Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GSoC2024] Fix missing related images 3d dataset exports #7699

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Added|Changed|Deprecated|Removed|Fixed|Security <!-- pick one -->
bargav25 marked this conversation as resolved.
Show resolved Hide resolved

- Fixed missing related images in Datumaro 3D exports
(<https://github.com/cvat-ai/cvat/pull/7699>)
12 changes: 10 additions & 2 deletions cvat/apps/dataset_manager/bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1534,9 +1534,13 @@ def __init__(
attributes["labels"].append({"label_id": idx, "name": label["name"], "color": label["color"], "type": label["type"]})
attributes["track_id"] = -1

extra_images_paths = dm_image[1]
extra_images_objects = [dm.Image(path=image_path) for image_path in extra_images_paths]

dm_item = dm.DatasetItem(
id=osp.splitext(osp.split(frame_data.name)[-1])[0],
annotations=dm_anno, media=PointCloud(dm_image[0]), related_images=dm_image[1],
annotations=dm_anno,
media=PointCloud(dm_image[0], extra_images=extra_images_objects),
attributes=attributes
)

Expand Down Expand Up @@ -1624,9 +1628,13 @@ def __init__(
attributes["labels"].append({"label_id": idx, "name": label["name"], "color": label["color"], "type": label["type"]})
attributes["track_id"] = -1

extra_images_paths = dm_image[1]
extra_images_objects = [dm.Image(path=image_path) for image_path in extra_images_paths]

dm_item = dm.DatasetItem(
id=osp.splitext(osp.split(frame_data.name)[-1])[0],
annotations=dm_anno, media=PointCloud(dm_image[0]), related_images=dm_image[1],
annotations=dm_anno,
media=PointCloud(dm_image[0], extra_images=extra_images_objects),
attributes=attributes, subset=frame_data.subset
)
dm_items.append(dm_item)
Expand Down
33 changes: 27 additions & 6 deletions cvat/apps/engine/tests/test_rest_api_3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,21 +255,42 @@ def etree_to_dict(t):
osp.join(tmp_dir, "ds0", "ann", "000001.pcd.json"),
osp.join(tmp_dir, "ds0", "ann", "000002.pcd.json"),
osp.join(tmp_dir, "ds0", "ann","000003.pcd.json")]
if related_files:
checking_files.extend([osp.join(tmp_dir, "ds0", "related_images", "000001.pcd_pcd", "000001.png.json"),
osp.join(tmp_dir, "ds0", "related_images", "000002.pcd_pcd", "000002.png.json"),
osp.join(tmp_dir, "ds0", "related_images", "000003.pcd_pcd", "000003.png.json")])
# if related_files:
# checking_files.extend([osp.join(tmp_dir, "ds0", "related_images", "000001.pcd_pcd", "000001.png.json"),
# osp.join(tmp_dir, "ds0", "related_images", "000002.pcd_pcd", "000002.png.json"),
# osp.join(tmp_dir, "ds0", "related_images", "000003.pcd_pcd", "000003.png.json")])
zipfile.ZipFile(content).extractall(tmp_dir)
jsons = glob(osp.join(tmp_dir, '**', '*.json'), recursive=True)
self.assertTrue(jsons)
self.assertTrue(set(checking_files).issubset(set(jsons)))
elif format_name == "Datumaro 3D 1.0":
with tempfile.TemporaryDirectory() as tmp_dir:
zipfile.ZipFile(content).extractall(tmp_dir)
extracted_files = set(
os.path.relpath(os.path.join(root, file), tmp_dir)
for root, dirs, files in os.walk(tmp_dir)
for file in files
)
expected_files = {'annotations/default.json'}
point_cloud_files = {'point_clouds/default/000001.pcd', 'point_clouds/default/000002.pcd', 'point_clouds/default/000003.pcd'}
# Check for point cloud files
if not point_cloud_files.isdisjoint(extracted_files):
expected_files.update(point_cloud_files)
if related_files:
expected_files.update([
'related_images/default/000001/image_0.png',
'related_images/default/000002/image_0.png',
'related_images/default/000003/image_0.png'
])
self.assertEqual(extracted_files, expected_files)



class Task3DTest(_DbTestBase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.format_names = ["Sly Point Cloud Format 1.0", "Kitti Raw Format 1.0"]
cls.format_names = ["Sly Point Cloud Format 1.0", "Kitti Raw Format 1.0", "Datumaro 3D 1.0"]
cls._image_sizes = {}
cls.pointcloud_pcd_filename = "test_canvas3d.zip"
cls.pointcloud_pcd_path = osp.join(os.path.dirname(__file__), 'assets', cls.pointcloud_pcd_filename)
Expand Down Expand Up @@ -761,5 +782,5 @@ def test_api_v2_export_dataset(self):
with open(file_name, "wb") as f:
f.write(content.getvalue())
self.assertEqual(osp.exists(file_name), edata['file_exists'])
self._check_dump_content(content, task_ann_prev.data, format_name,related_files=False)
self._check_dump_content(content, task_ann_prev.data, format_name, related_files=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self._check_dump_content(content, task_ann_prev.data, format_name, related_files=True)
if edata['file_exists']:
self._check_dump_content(content, task_ann_prev.data, format_name, related_files=True)

It seems there is an error in the test.