From f7276fc32c721e4820746813df8e257233840055 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20G=C5=82owacki?= Date: Wed, 30 Oct 2024 07:29:12 +0000 Subject: [PATCH] 2x processing speedup --- .../perception_eval_conversions.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/driving_log_replayer/driving_log_replayer/perception_eval_conversions.py b/driving_log_replayer/driving_log_replayer/perception_eval_conversions.py index 48f1f2fb..e45453f5 100644 --- a/driving_log_replayer/driving_log_replayer/perception_eval_conversions.py +++ b/driving_log_replayer/driving_log_replayer/perception_eval_conversions.py @@ -22,7 +22,7 @@ from geometry_msgs.msg import Pose from geometry_msgs.msg import Quaternion as RosQuaternion from geometry_msgs.msg import Vector3 -import jsonschema +from jsonschema.validators import validator_for import numpy as np from perception_eval.common import ObjectType from perception_eval.common.object import DynamicObject @@ -315,15 +315,19 @@ def load_schema(cls) -> None: ) with schema_file_path.open() as file: cls.schema = json.load(file) + # Compile the schema into a validator instance + validator_cls = validator_for(cls.schema) + validator_cls.check_schema(cls.schema) + cls.validator = validator_cls(cls.schema) @classmethod def is_object_structure_valid(cls, objdata: dict | None) -> bool: cls.load_schema() try: - jsonschema.validate(objdata, cls.schema) + cls.validator.validate(objdata) + return True except jsonschema.exceptions.ValidationError: return False - return True @staticmethod def object_to_description(obj: ObjectType | None) -> dict: