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

Adding class BlobLoader to separate loading from JsonIndexDataset logic #1463

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
aa34aa0
created class BlobLoader and moved all related function to sep file
Feb 28, 2023
f745dfc
added type hints and deleted chore pyre-ignore
Feb 28, 2023
c3c5110
linter
Feb 28, 2023
9b431bd
linter
Feb 28, 2023
c74261d
Merge branch 'main' into main
salaxieb Feb 28, 2023
627e60f
deleted chore pyre-ignore
Feb 28, 2023
d0a2d4d
Merge branch 'main' of github.com:salaxieb/pytorch3d
Feb 28, 2023
0aa27a6
renamed load_blob to blob_loader
Mar 1, 2023
53823cf
sending to BlobLoader whore seq_annotation
Mar 1, 2023
d6f13eb
made blob_loader dataclass to avoid boilerplate
Mar 1, 2023
86e64f7
documented, that FrameData modification done inplace
Mar 1, 2023
2f17049
spliited JsonIndexDataset args to 2 gorups: Matadata-related and Blo…
Mar 1, 2023
527ec09
code refactoring to delete chore pyre-ignore
Mar 1, 2023
24b731b
deleted chore function
Mar 6, 2023
f484a12
BloabLoader tests boilerplate
Mar 6, 2023
b8674ea
tests WIP (not tested)
Mar 7, 2023
faeffcf
tests typos and errors WIP
Mar 9, 2023
bc24e29
tests typos and errors WIP
Mar 9, 2023
e9c5969
solved error and typos for test_bbox
Mar 9, 2023
44cfcfb
updating test_blob_loader WIP
Mar 9, 2023
11def0a
blob loader tests ready for review
Mar 9, 2023
bc52382
typo
Mar 9, 2023
0149377
typo
Mar 9, 2023
3bcbd01
linter
Mar 9, 2023
269cffa
all entry tests run thru all frames
Mar 9, 2023
f930d71
assert .. == .. to self.assertEqual(.., ..)
Mar 10, 2023
dc7a702
testing only on 1 frame
Mar 10, 2023
fcd8d8b
instead of loading whole dataset, loading only single frame annots
Mar 10, 2023
c3bd722
added default values to BlobLoader to ease initialisation
Mar 10, 2023
cb34c01
mackink tests on single loaded frame
Mar 10, 2023
04b7d15
made _resize_image separate function (will ease use in pixar replay)
Mar 10, 2023
76f45aa
type in function arguments
Mar 10, 2023
e5d3a2b
moved tests for _resize_image to test_bbox
Mar 10, 2023
1ba1a3a
np array instead of tensor to resize_image
Mar 10, 2023
cd9aa5c
setting up default scale value to correct one
Mar 13, 2023
ce9fd40
renamed funciton to load_ to make more obvious inplace modification
Mar 14, 2023
46d39ed
Update pytorch3d/implicitron/dataset/blob_loader.py
salaxieb Mar 14, 2023
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
68 changes: 39 additions & 29 deletions tests/implicitron/test_blob_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,38 @@ def setUp(self):
load_point_clouds=True,
path_manager=self.path_manager,
)
index = 7000
self.entry = self.dataset.frame_annots[index]["frame_annotation"]

def test_BlobLoader_args(self):
# test that BlobLoader works with get_default_args
get_default_args(BlobLoader)

def test_load_pipeline(self):
def test_fix_point_cloud_path(self):
"""Some files in Co3Dv2 have an accidental absolute path stored."""
original_path = "some_file_path"
modified_path = self.dataset.blob_loader._fix_point_cloud_path(original_path)
assert original_path in modified_path
assert self.dataset.blob_loader.dataset_root in modified_path

def test_entry_loading_functions(self):
for index in range(len(self.dataset.frame_annots)):
entry = self.dataset.frame_annots[index]["frame_annotation"]
self.load_test(entry)
self._resize_image_test(entry)
self._load_image_test(entry)
self._load_mask_test(entry)
self._load_depth_test(entry)
self._load_16big_png_depth_test(entry)
self._load_1bit_png_mask_test(entry)
self._load_depth_mask_test(entry)

def load_test(self, entry):
(
fg_probability,
mask_path,
bbox_xywh,
clamp_bbox_xyxy,
crop_bbox_xywh,
) = self.dataset.blob_loader._load_crop_fg_probability(self.entry)
) = self.dataset.blob_loader._load_crop_fg_probability(entry)

assert mask_path
assert torch.is_tensor(fg_probability)
Expand All @@ -86,7 +103,7 @@ def test_load_pipeline(self):
mask_crop,
scale,
) = self.dataset.blob_loader._load_crop_images(
self.entry,
entry,
fg_probability,
clamp_bbox_xyxy,
)
Expand All @@ -103,7 +120,7 @@ def test_load_pipeline(self):
depth_path,
depth_mask,
) = self.dataset.blob_loader._load_mask_depth(
self.entry,
entry,
clamp_bbox_xyxy,
fg_probability,
)
Expand All @@ -115,21 +132,14 @@ def test_load_pipeline(self):
assert depth_mask.shape == torch.Size([1, self.image_height, self.image_width])

camera = self.dataset.blob_loader._get_pytorch3d_camera(
self.entry,
entry,
scale,
clamp_bbox_xyxy,
)
assert type(camera) == PerspectiveCameras

def test_fix_point_cloud_path(self):
"""Some files in Co3Dv2 have an accidental absolute path stored."""
original_path = "some_file_path"
modified_path = self.dataset.blob_loader._fix_point_cloud_path(original_path)
assert original_path in modified_path
assert self.dataset.blob_loader.dataset_root in modified_path

def test_resize_image(self):
path = os.path.join(self.dataset_root, self.entry.image.path)
def _resize_image_test(self, entry):
path = os.path.join(self.dataset_root, entry.image.path)
local_path = self.path_manager.get_local_path(path)
image = _load_image(local_path)
image_rgb, scale, mask_crop = self.dataset.blob_loader._resize_image(image)
Expand All @@ -147,41 +157,41 @@ def test_resize_image(self):
assert image_rgb.shape[-2:] == expected_shape
assert mask_crop.shape[-2:] == expected_shape

def test_load_image(self):
path = os.path.join(self.dataset_root, self.entry.image.path)
def _load_image_test(self, entry):
path = os.path.join(self.dataset_root, entry.image.path)
local_path = self.path_manager.get_local_path(path)
image = _load_image(local_path)
assert image.dtype == np.float32
assert np.max(image) <= 1.0
assert np.min(image) >= 0.0

def test_load_mask(self):
path = os.path.join(self.dataset_root, self.entry.mask.path)
def _load_mask_test(self, entry):
path = os.path.join(self.dataset_root, entry.mask.path)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use methods like self.assertEqual as they give better diagnostics.

mask = _load_mask(path)
assert mask.dtype == np.float32
assert np.max(mask) <= 1.0
assert np.min(mask) >= 0.0

def test_load_depth(self):
path = os.path.join(self.dataset_root, self.entry.depth.path)
depth_map = _load_depth(path, self.entry.depth.scale_adjustment)
def _load_depth_test(self, entry):
path = os.path.join(self.dataset_root, entry.depth.path)
depth_map = _load_depth(path, entry.depth.scale_adjustment)
assert depth_map.dtype == np.float32
assert depth_map.shape

def test_load_16big_png_depth(self):
path = os.path.join(self.dataset_root, self.entry.depth.path)
def _load_16big_png_depth_test(self, entry):
path = os.path.join(self.dataset_root, entry.depth.path)
depth_map = _load_16big_png_depth(path)
assert depth_map.dtype == np.float32
assert len(depth_map.shape) == 2

def test_load_1bit_png_mask(self):
mask_path = os.path.join(self.dataset_root, self.entry.depth.mask_path)
def _load_1bit_png_mask_test(self, entry):
mask_path = os.path.join(self.dataset_root, entry.depth.mask_path)
mask = _load_1bit_png_mask(mask_path)
assert mask.dtype == np.float32
assert len(mask.shape) == 2

def test_load_depth_mask(self):
mask_path = os.path.join(self.dataset_root, self.entry.depth.mask_path)
def _load_depth_mask_test(self, entry):
mask_path = os.path.join(self.dataset_root, entry.depth.mask_path)
mask = _load_depth_mask(mask_path)
assert mask.dtype == np.float32
assert len(mask.shape) == 3