Skip to content

Commit

Permalink
Ensure cameras follow same order when (de)serializing
Browse files Browse the repository at this point in the history
  • Loading branch information
roomrys committed Oct 4, 2024
1 parent 69e00b1 commit f97e19d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion sleap/io/cameras.py
Original file line number Diff line number Diff line change
Expand Up @@ -1581,10 +1581,13 @@ def to_session_dict(
# Unstructure `CameraCluster` and `metadata`
calibration_dict = self.camera_cluster.to_calibration_dict()

# Sort `Camcorder`s following same schema as when deserializing
self.camera_cluster.cameras.sort(key=lambda x: x.name)

# Store camcorder-to-video indices map where key is camcorder index
# and value is video index from `Labels.videos`
camcorder_to_video_idx_map = {}
for cam_idx, camcorder in enumerate(self.camera_cluster):
for cam_idx, camcorder in enumerate(self.camera_cluster.cameras):
# Skip if Camcorder is not linked to any Video
if camcorder not in self._video_by_camcorder:
continue
Expand Down Expand Up @@ -1644,6 +1647,9 @@ def from_session_dict(
calibration_dict
)

# Ensure `Camcorder`s are in the same order as they were serialized
session.camera_cluster.cameras.sort(key=lambda x: x.name)

# Retrieve all `Camcorder` and `Video` objects, then add to `RecordingSession`
camcorder_to_video_idx_map = session_dict["camcorder_to_video_idx_map"]
for cam_idx, video_idx in camcorder_to_video_idx_map.items():
Expand Down

0 comments on commit f97e19d

Please sign in to comment.