-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Support inference and visualization of VPD (#3331)
Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily get feedback. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers. ## Motivation Support inference and visualization of VPD ## Modification 1. add a new VPD model that does not generate black border in predictions 2. update `SegLocalVisualizer` to support depth visualization 3. update `MMSegInferencer` to support save predictions of depth estimation in method `postprocess` ## BC-breaking (Optional) Does the modification introduce changes that break the backward-compatibility of the downstream repos? If so, please describe how it breaks the compatibility and how the downstream projects should modify their code to keep compatibility with this PR. ## Use cases (Optional) Run inference with VPD using the this command ```sh python demo/image_demo_with_inferencer.py demo/classroom__rgb_00283.jpg vpd_depth --out-dir vis_results ``` The following image will be saved under `vis_results/vis`  ## Checklist 1. Pre-commit or other linting tools are used to fix the potential lint issues. 4. The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness. 5. If the modification has potential influence on downstream projects, this PR should be tested with downstream projects, like MMDet or MMDet3D. 6. The documentation has been modified accordingly, like docstring or example tutorials.
- Loading branch information
Showing
15 changed files
with
366 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
version: 2 | ||
|
||
build: | ||
os: ubuntu-22.04 | ||
tools: | ||
python: "3.7" | ||
|
||
formats: | ||
- epub | ||
|
||
python: | ||
version: 3.7 | ||
install: | ||
- requirements: requirements/docs.txt | ||
- requirements: requirements/readthedocs.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# dataset settings | ||
dataset_type = 'NYUDataset' | ||
data_root = 'data/nyu' | ||
|
||
train_pipeline = [ | ||
dict(type='LoadImageFromFile'), | ||
dict(type='LoadDepthAnnotation', depth_rescale_factor=1e-3), | ||
dict(type='RandomDepthMix', prob=0.25), | ||
dict(type='RandomFlip', prob=0.5), | ||
dict( | ||
type='RandomResize', | ||
scale=(768, 512), | ||
ratio_range=(0.8, 1.5), | ||
keep_ratio=True), | ||
dict(type='RandomCrop', crop_size=(512, 512)), | ||
dict( | ||
type='Albu', | ||
transforms=[ | ||
dict(type='RandomBrightnessContrast'), | ||
dict(type='RandomGamma'), | ||
dict(type='HueSaturationValue'), | ||
]), | ||
dict( | ||
type='PackSegInputs', | ||
meta_keys=('img_path', 'depth_map_path', 'ori_shape', 'img_shape', | ||
'pad_shape', 'scale_factor', 'flip', 'flip_direction', | ||
'category_id')), | ||
] | ||
|
||
test_pipeline = [ | ||
dict(type='LoadImageFromFile'), | ||
dict(type='Resize', scale=(2048, 512), keep_ratio=True), | ||
dict(dict(type='LoadDepthAnnotation', depth_rescale_factor=1e-3)), | ||
dict( | ||
type='PackSegInputs', | ||
meta_keys=('img_path', 'depth_map_path', 'ori_shape', 'img_shape', | ||
'pad_shape', 'scale_factor', 'flip', 'flip_direction', | ||
'category_id')) | ||
] | ||
|
||
train_dataloader = dict( | ||
batch_size=8, | ||
num_workers=8, | ||
persistent_workers=True, | ||
sampler=dict(type='InfiniteSampler', shuffle=True), | ||
dataset=dict( | ||
type=dataset_type, | ||
data_root=data_root, | ||
data_prefix=dict( | ||
img_path='images/train', depth_map_path='annotations/train'), | ||
pipeline=train_pipeline)) | ||
|
||
val_dataloader = dict( | ||
batch_size=1, | ||
num_workers=4, | ||
persistent_workers=True, | ||
sampler=dict(type='DefaultSampler', shuffle=False), | ||
dataset=dict( | ||
type=dataset_type, | ||
data_root=data_root, | ||
test_mode=True, | ||
data_prefix=dict( | ||
img_path='images/test', depth_map_path='annotations/test'), | ||
pipeline=test_pipeline)) | ||
test_dataloader = val_dataloader | ||
|
||
val_evaluator = dict( | ||
type='DepthMetric', | ||
min_depth_eval=0.001, | ||
max_depth_eval=10.0, | ||
crop_type='nyu_crop') | ||
test_evaluator = val_evaluator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
_base_ = [ | ||
'../_base_/models/vpd_sd.py', '../_base_/datasets/nyu_512x512.py', | ||
'../_base_/default_runtime.py', '../_base_/schedules/schedule_25k.py' | ||
] | ||
|
||
crop_size = (512, 512) | ||
|
||
model = dict( | ||
type='DepthEstimator', | ||
data_preprocessor=dict(size=crop_size), | ||
backbone=dict( | ||
class_embed_path='https://download.openmmlab.com/mmsegmentation/' | ||
'v0.5/vpd/nyu_class_embeddings.pth', | ||
class_embed_select=True, | ||
pad_shape=512, | ||
unet_cfg=dict(use_attn=False), | ||
), | ||
decode_head=dict( | ||
type='VPDDepthHead', | ||
in_channels=[320, 640, 1280, 1280], | ||
max_depth=10, | ||
), | ||
test_cfg=dict(mode='slide_flip', crop_size=crop_size, stride=(128, 128))) | ||
|
||
default_hooks = dict( | ||
checkpoint=dict(save_best='rmse', rule='less', max_keep_ckpts=1)) | ||
|
||
# custom optimizer | ||
optim_wrapper = dict( | ||
constructor='ForceDefaultOptimWrapperConstructor', | ||
paramwise_cfg=dict( | ||
bias_decay_mult=0, | ||
force_default_settings=True, | ||
custom_keys={ | ||
'backbone.encoder_vq': dict(lr_mult=0), | ||
'backbone.unet': dict(lr_mult=0.01), | ||
})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.