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

Fix bug of multiple pre-processing when segmentation (PyTorch) #645

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
7 changes: 3 additions & 4 deletions ml3d/torch/dataloaders/torch_dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def __init__(self,
sampler=None,
use_cache=True,
steps_per_epoch=None,
cache_convert=None,
**kwargs):
"""Initialize.

Expand All @@ -38,6 +39,7 @@ def __init__(self,
self.dataset = dataset
self.preprocess = preprocess
self.steps_per_epoch = steps_per_epoch
self.cache_convert = cache_convert

if preprocess is not None and use_cache:
cache_dir = getattr(dataset.cfg, 'cache_dir')
Expand All @@ -59,10 +61,7 @@ def __init__(self,
continue
data = dataset.get_data(idx)
# cache the data
self.cache_convert(name, data, attr)

else:
self.cache_convert = None
self.cache_convert(name, data, attr)

self.transform = transform

Expand Down
8 changes: 7 additions & 1 deletion ml3d/torch/pipelines/semantic_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ def run_inference(self, data):
model.device = device
model.eval()

preprocess_func = model.preprocess
processed_data = preprocess_func(data, {'split': 'test'})
def get_cache(attr):
return processed_data

batcher = self.get_batcher(device)
infer_dataset = InferenceDummySplit(data)
self.dataset_split = infer_dataset
Expand All @@ -144,7 +149,8 @@ def run_inference(self, data):
preprocess=model.preprocess,
transform=model.transform,
sampler=infer_sampler,
use_cache=False)
use_cache=False,
cache_convert=get_cache)
infer_loader = DataLoader(infer_split,
batch_size=cfg.batch_size,
sampler=get_sampler(infer_sampler),
Expand Down