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 2dbe2779..91280b25 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 +import fastjsonschema import numpy as np from perception_eval.common import ObjectType from perception_eval.common.object import DynamicObject @@ -305,27 +305,26 @@ def fill_xyzw_quat(q: Quaternion | None) -> dict: # utils for writing each perception frame result to a file class FrameDescriptionWriter: schema: dict = None + validate_func = None @classmethod def load_schema(cls) -> None: - if cls.schema is None: + if cls.schema is None or cls.validate_func is None: package_share_directory = get_package_share_directory("driving_log_replayer") schema_file_path = ( Path(package_share_directory) / "config" / "object_output_schema.json" ) with schema_file_path.open() as file: cls.schema = json.load(file) - # Compile the schema into a validator instance - validator_cls = jsonschema.validators.validator_for(cls.schema) - validator_cls.check_schema(cls.schema) - cls.validator = validator_cls(cls.schema) + # Compile the schema into a validation function + cls.validate_func = fastjsonschema.compile(cls.schema) @classmethod def is_object_structure_valid(cls, objdata: dict | None) -> bool: cls.load_schema() try: - cls.validator.validate(objdata) - except jsonschema.exceptions.ValidationError: + cls.validate_func(objdata) + except fastjsonschema.exceptions.JsonSchemaException: return False else: return True