Skip to content

Commit

Permalink
Co3Dv2 point cloud fix
Browse files Browse the repository at this point in the history
Summary: Avoid certain hardcoded paths in co3dv2 data

Reviewed By: davnov134

Differential Revision: D40209309

fbshipit-source-id: 0e83a15baa47d5bd07d2d23c6048cb4522c1ccba
  • Loading branch information
bottler authored and facebook-github-bot committed Oct 9, 2022
1 parent 9df875b commit 95a2acf
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
17 changes: 14 additions & 3 deletions pytorch3d/implicitron/dataset/json_index_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,15 +414,26 @@ def __getitem__(self, index) -> FrameData:
)

if self.load_point_clouds and point_cloud is not None:
frame_data.sequence_point_cloud_path = pcl_path = os.path.join(
self.dataset_root, point_cloud.path
)
pcl_path = self._fix_point_cloud_path(point_cloud.path)
frame_data.sequence_point_cloud = _load_pointcloud(
self._local_path(pcl_path), max_points=self.max_points
)
frame_data.sequence_point_cloud_path = pcl_path

return frame_data

def _fix_point_cloud_path(self, path: str) -> str:
"""
Fix up a point cloud path from the dataset.
Some files in Co3Dv2 have an accidental absolute path stored.
"""
unwanted_prefix = (
"/large_experiments/p3/replay/datasets/co3d/co3d45k_220512/export_v23/"
)
if path.startswith(unwanted_prefix):
path = path[len(unwanted_prefix) :]
return os.path.join(self.dataset_root, path)

def _load_crop_fg_probability(
self, entry: types.FrameAnnotation
) -> Tuple[
Expand Down
9 changes: 6 additions & 3 deletions tests/implicitron/common_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@


CO3D_MANIFOLD_PATH: str = "manifold://co3d/tree/extracted"
CO3DV2_MANIFOLD_PATH: str = "manifold://co3d/tree/v2/extracted"

INSIDE_RE_WORKER: bool = os.environ.get("INSIDE_RE_WORKER", False)


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

if os.environ.get("INSIDE_RE_WORKER", False):
if INSIDE_RE_WORKER:
raise ValueError("Cannot get to manifold from RE")

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

elif avoid_manifold or os.environ.get("INSIDE_RE_WORKER", False):
elif avoid_manifold or INSIDE_RE_WORKER:
from libfb.py.parutil import get_file_path

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

os.environ["FVCORE_CACHE"] = "iopath_cache"
Expand Down
16 changes: 16 additions & 0 deletions tests/implicitron/test_json_index_dataset_provider_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
SequenceAnnotation,
)
from pytorch3d.implicitron.tools.config import expand_args_fields
from tests.common_testing import interactive_testing_requested

from .common_resources import CO3DV2_MANIFOLD_PATH


class TestJsonIndexDatasetProviderV2(unittest.TestCase):
Expand Down Expand Up @@ -175,3 +178,16 @@ def _make_random_json_dataset_map_provider_v2_data(

with open(os.path.join(root, "category_to_subset_name_list.json"), "w") as f:
json.dump(category_to_subset_list, f)


class TestCo3dv2(unittest.TestCase):
def test_simple(self):
if not interactive_testing_requested():
return
dataset_provider = JsonIndexDatasetMapProviderV2(
category="apple",
subset_name="manyview_dev_0",
dataset_root=CO3DV2_MANIFOLD_PATH,
dataset_JsonIndexDataset_args={"load_point_clouds": True},
)
dataset_provider.get_dataset_map().train[0]

0 comments on commit 95a2acf

Please sign in to comment.