Skip to content

Commit 95a2acf

Browse files
bottlerfacebook-github-bot
authored andcommitted
Co3Dv2 point cloud fix
Summary: Avoid certain hardcoded paths in co3dv2 data Reviewed By: davnov134 Differential Revision: D40209309 fbshipit-source-id: 0e83a15baa47d5bd07d2d23c6048cb4522c1ccba
1 parent 9df875b commit 95a2acf

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

Diff for: pytorch3d/implicitron/dataset/json_index_dataset.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -414,15 +414,26 @@ def __getitem__(self, index) -> FrameData:
414414
)
415415

416416
if self.load_point_clouds and point_cloud is not None:
417-
frame_data.sequence_point_cloud_path = pcl_path = os.path.join(
418-
self.dataset_root, point_cloud.path
419-
)
417+
pcl_path = self._fix_point_cloud_path(point_cloud.path)
420418
frame_data.sequence_point_cloud = _load_pointcloud(
421419
self._local_path(pcl_path), max_points=self.max_points
422420
)
421+
frame_data.sequence_point_cloud_path = pcl_path
423422

424423
return frame_data
425424

425+
def _fix_point_cloud_path(self, path: str) -> str:
426+
"""
427+
Fix up a point cloud path from the dataset.
428+
Some files in Co3Dv2 have an accidental absolute path stored.
429+
"""
430+
unwanted_prefix = (
431+
"/large_experiments/p3/replay/datasets/co3d/co3d45k_220512/export_v23/"
432+
)
433+
if path.startswith(unwanted_prefix):
434+
path = path[len(unwanted_prefix) :]
435+
return os.path.join(self.dataset_root, path)
436+
426437
def _load_crop_fg_probability(
427438
self, entry: types.FrameAnnotation
428439
) -> Tuple[

Diff for: tests/implicitron/common_resources.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818

1919
CO3D_MANIFOLD_PATH: str = "manifold://co3d/tree/extracted"
20+
CO3DV2_MANIFOLD_PATH: str = "manifold://co3d/tree/v2/extracted"
21+
22+
INSIDE_RE_WORKER: bool = os.environ.get("INSIDE_RE_WORKER", False)
2023

2124

2225
def get_path_manager(silence_logs: bool = False) -> PathManager:
@@ -30,7 +33,7 @@ def get_path_manager(silence_logs: bool = False) -> PathManager:
3033
logging.getLogger("iopath.fb.manifold").setLevel(logging.CRITICAL)
3134
logging.getLogger("iopath.common.file_io").setLevel(logging.CRITICAL)
3235

33-
if os.environ.get("INSIDE_RE_WORKER", False):
36+
if INSIDE_RE_WORKER:
3437
raise ValueError("Cannot get to manifold from RE")
3538

3639
path_manager = PathManager()
@@ -70,7 +73,7 @@ def get_skateboard_data(
7073
raise unittest.SkipTest("Unknown environment. Data not available.")
7174
yield "/datasets01/co3d/081922", PathManager()
7275

73-
elif avoid_manifold or os.environ.get("INSIDE_RE_WORKER", False):
76+
elif avoid_manifold or INSIDE_RE_WORKER:
7477
from libfb.py.parutil import get_file_path
7578

7679
par_path = "skateboard_first_5"
@@ -120,7 +123,7 @@ def _provide_torchvision_weights(par_path: str, filename: str) -> None:
120123
# (It can't copy straight to a nested location, see
121124
# https://fb.workplace.com/groups/askbuck/posts/2644615728920359/)
122125
# Here we symlink it to the new cache location.
123-
if os.environ.get("INSIDE_RE_WORKER") is not None:
126+
if INSIDE_RE_WORKER:
124127
from libfb.py.parutil import get_file_path
125128

126129
os.environ["FVCORE_CACHE"] = "iopath_cache"

Diff for: tests/implicitron/test_json_index_dataset_provider_v2.py

+16
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
SequenceAnnotation,
3030
)
3131
from pytorch3d.implicitron.tools.config import expand_args_fields
32+
from tests.common_testing import interactive_testing_requested
33+
34+
from .common_resources import CO3DV2_MANIFOLD_PATH
3235

3336

3437
class TestJsonIndexDatasetProviderV2(unittest.TestCase):
@@ -175,3 +178,16 @@ def _make_random_json_dataset_map_provider_v2_data(
175178

176179
with open(os.path.join(root, "category_to_subset_name_list.json"), "w") as f:
177180
json.dump(category_to_subset_list, f)
181+
182+
183+
class TestCo3dv2(unittest.TestCase):
184+
def test_simple(self):
185+
if not interactive_testing_requested():
186+
return
187+
dataset_provider = JsonIndexDatasetMapProviderV2(
188+
category="apple",
189+
subset_name="manyview_dev_0",
190+
dataset_root=CO3DV2_MANIFOLD_PATH,
191+
dataset_JsonIndexDataset_args={"load_point_clouds": True},
192+
)
193+
dataset_provider.get_dataset_map().train[0]

0 commit comments

Comments
 (0)