Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

Commit

Permalink
perf: 2x processing speedup (#581)
Browse files Browse the repository at this point in the history
Signed-off-by: Hayato Mizushima <[email protected]>
Co-authored-by: Hayato Mizushima <[email protected]>
  • Loading branch information
ralwing and hayato-m126 authored Nov 1, 2024
1 parent da819a5 commit 0794126
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .driving_log_replayer.cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"youtalk",
"UMiho",
"nuscenes",
"devkit"
"devkit",
"fastjsonschema"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

from ament_index_python.packages import get_package_share_directory
from builtin_interfaces.msg import Time
import fastjsonschema
from geometry_msgs.msg import Point
from geometry_msgs.msg import Polygon as RosPolygon
from geometry_msgs.msg import Pose
from geometry_msgs.msg import Quaternion as RosQuaternion
from geometry_msgs.msg import Vector3
import jsonschema
import numpy as np
from perception_eval.common import ObjectType
from perception_eval.common.object import DynamicObject
Expand Down Expand Up @@ -305,25 +305,28 @@ 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)
cls.validate_func = fastjsonschema.compile(cls.schema)

@classmethod
def is_object_structure_valid(cls, objdata: dict | None) -> bool:
cls.load_schema()
try:
jsonschema.validate(objdata, cls.schema)
except jsonschema.exceptions.ValidationError:
cls.validate_func(objdata)
except fastjsonschema.exceptions.JsonSchemaException:
return False
return True
else:
return True

@staticmethod
def object_to_description(obj: ObjectType | None) -> dict:
Expand Down
2 changes: 1 addition & 1 deletion driving_log_replayer/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<exec_depend>driving_log_replayer_analyzer</exec_depend>
<exec_depend>lanelet2_extension_python</exec_depend>
<exec_depend>perception_eval</exec_depend>
<exec_depend>python3-jsonschema</exec_depend>
<exec_depend>python3-fastjsonschema</exec_depend>
<exec_depend>python3-pandas</exec_depend>
<exec_depend>python3-simplejson</exec_depend>
<exec_depend>python3-termcolor</exec_depend>
Expand Down

0 comments on commit 0794126

Please sign in to comment.