Skip to content

Commit 1163eaa

Browse files
davnov134facebook-github-bot
authored andcommitted
CO3Dv2 trainer configs
Summary: Adds yaml configs to train selected methods on CO3Dv2. Few more updates: 1) moved some fields to base classes so that we can check is_multisequence in experiment.py 2) skip loading all train cameras for multisequence datasets, without this, co3d-fewview is untrainable 3) fix bug in json index dataset provider v2 Reviewed By: kjchalup Differential Revision: D38952755 fbshipit-source-id: 3edac6fc8e20775aa70400bd73a0e6d52b091e0c
1 parent 03562d8 commit 1163eaa

17 files changed

+120
-21
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
data_source_ImplicitronDataSource_args:
2+
dataset_map_provider_class_type: JsonIndexDatasetMapProviderV2
3+
dataset_map_provider_JsonIndexDatasetMapProviderV2_args:
4+
category: teddybear
5+
subset_name: fewview_dev
6+
training_loop_ImplicitronTrainingLoop_args:
7+
evaluator_ImplicitronEvaluator_args:
8+
is_multisequence: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
defaults:
2+
- repro_multiseq_nerf_wce.yaml
3+
- repro_multiseq_co3dv2_base.yaml
4+
- _self_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
defaults:
2+
- repro_multiseq_nerformer.yaml
3+
- repro_multiseq_co3dv2_base.yaml
4+
- _self_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
defaults:
2+
- repro_multiseq_srn_ad_hypernet.yaml
3+
- repro_multiseq_co3dv2_base.yaml
4+
- _self_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
defaults:
2+
- repro_multiseq_srn_wce.yaml
3+
- repro_multiseq_co3dv2_base.yaml
4+
- _self_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
data_source_ImplicitronDataSource_args:
2+
dataset_map_provider_class_type: JsonIndexDatasetMapProviderV2
3+
dataset_map_provider_JsonIndexDatasetMapProviderV2_args:
4+
category: teddybear
5+
subset_name: manyview_dev_0
6+
training_loop_ImplicitronTrainingLoop_args:
7+
evaluator_ImplicitronEvaluator_args:
8+
is_multisequence: false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
defaults:
2+
- repro_singleseq_idr.yaml
3+
- repro_singleseq_co3dv2_base.yaml
4+
- _self_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
defaults:
2+
- repro_singleseq_nerf.yaml
3+
- repro_singleseq_co3dv2_base.yaml
4+
- _self_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
defaults:
2+
- repro_singleseq_nerformer.yaml
3+
- repro_singleseq_co3dv2_base.yaml
4+
- _self_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
defaults:
2+
- repro_singleseq_srn_noharm.yaml
3+
- repro_singleseq_co3dv2_base.yaml
4+
- _self_

Diff for: projects/implicitron_trainer/experiment.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,10 @@ def run(self) -> None:
207207
val_loader,
208208
) = accelerator.prepare(model, optimizer, train_loader, val_loader)
209209

210-
all_train_cameras = self.data_source.all_train_cameras
210+
if not self.training_loop.evaluator.is_multisequence:
211+
all_train_cameras = self.data_source.all_train_cameras
212+
else:
213+
all_train_cameras = None
211214

212215
# Enter the main training loop.
213216
self.training_loop.run(

Diff for: projects/implicitron_trainer/impl/training_loop.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@
3030

3131

3232
class TrainingLoopBase(ReplaceableBase):
33+
"""
34+
Members:
35+
evaluator: An EvaluatorBase instance, used to evaluate training results.
36+
"""
37+
38+
evaluator: Optional[EvaluatorBase]
39+
evaluator_class_type: Optional[str] = "ImplicitronEvaluator"
40+
3341
def run(
3442
self,
3543
train_loader: DataLoader,
@@ -58,7 +66,6 @@ class ImplicitronTrainingLoop(TrainingLoopBase): # pyre-ignore [13]
5866
"""
5967
Members:
6068
eval_only: If True, only run evaluation using the test dataloader.
61-
evaluator: An EvaluatorBase instance, used to evaluate training results.
6269
max_epochs: Train for this many epochs. Note that if the model was
6370
loaded from a checkpoint, we will restart training at the appropriate
6471
epoch and run for (max_epochs - checkpoint_epoch) epochs.
@@ -82,8 +89,6 @@ class ImplicitronTrainingLoop(TrainingLoopBase): # pyre-ignore [13]
8289

8390
# Parameters of the outer training loop.
8491
eval_only: bool = False
85-
evaluator: EvaluatorBase
86-
evaluator_class_type: str = "ImplicitronEvaluator"
8792
max_epochs: int = 1000
8893
store_checkpoints: bool = True
8994
store_checkpoints_purge: int = 1

Diff for: projects/implicitron_trainer/tests/experiment.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,13 @@ optimizer_factory_ImplicitronOptimizerFactory_args:
406406
linear_exponential_lr_milestone: 200
407407
linear_exponential_start_gamma: 0.1
408408
training_loop_ImplicitronTrainingLoop_args:
409-
eval_only: false
410409
evaluator_class_type: ImplicitronEvaluator
410+
evaluator_ImplicitronEvaluator_args:
411+
is_multisequence: false
412+
camera_difficulty_bin_breaks:
413+
- 0.97
414+
- 0.98
415+
eval_only: false
411416
max_epochs: 1000
412417
store_checkpoints: true
413418
store_checkpoints_purge: 1
@@ -420,8 +425,3 @@ training_loop_ImplicitronTrainingLoop_args:
420425
visdom_env: ''
421426
visdom_port: 8097
422427
visdom_server: http://127.0.0.1
423-
evaluator_ImplicitronEvaluator_args:
424-
camera_difficulty_bin_breaks:
425-
- 0.97
426-
- 0.98
427-
is_multisequence: false

Diff for: projects/implicitron_trainer/tests/test_experiment.py

+28
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,34 @@ def test_nerf_llff(self):
190190
experiment.dump_cfg(cfg)
191191
experiment_runner.run()
192192

193+
@unittest.skip("This test runs nerf training on co3d v2 - manyview.")
194+
def test_nerf_co3dv2_manyview(self):
195+
# Train NERF
196+
if not interactive_testing_requested():
197+
return
198+
with initialize_config_dir(config_dir=str(IMPLICITRON_CONFIGS_DIR)):
199+
cfg = compose(
200+
config_name="repro_singleseq_v2_nerf",
201+
overrides=[],
202+
)
203+
experiment_runner = experiment.Experiment(**cfg)
204+
experiment.dump_cfg(cfg)
205+
experiment_runner.run()
206+
207+
@unittest.skip("This test runs nerformer training on co3d v2 - fewview.")
208+
def test_nerformer_co3dv2_fewview(self):
209+
# Train NeRFormer
210+
if not interactive_testing_requested():
211+
return
212+
with initialize_config_dir(config_dir=str(IMPLICITRON_CONFIGS_DIR)):
213+
cfg = compose(
214+
config_name="repro_multiseq_v2_nerformer",
215+
overrides=[],
216+
)
217+
experiment_runner = experiment.Experiment(**cfg)
218+
experiment.dump_cfg(cfg)
219+
experiment_runner.run()
220+
193221
@unittest.skip("This test checks resuming of the NeRF training.")
194222
def test_nerf_blender_resume(self):
195223
# Train one train batch of NeRF, then resume for one more batch.

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from pytorch3d.renderer.camera_utils import join_cameras_as_batch
3737
from pytorch3d.renderer.cameras import CamerasBase, PerspectiveCameras
3838
from pytorch3d.structures.pointclouds import Pointclouds
39+
from tqdm import tqdm
3940

4041
from . import types
4142
from .dataset_base import DatasetBase, FrameData
@@ -338,9 +339,10 @@ def get_all_train_cameras(self) -> CamerasBase:
338339
"""
339340
Returns the cameras corresponding to all the known frames.
340341
"""
342+
logger.info("Loading all train cameras.")
341343
cameras = []
342344
# pyre-ignore[16]
343-
for frame_idx, frame_annot in enumerate(self.frame_annots):
345+
for frame_idx, frame_annot in enumerate(tqdm(self.frame_annots)):
344346
frame_type = self._get_frame_type(frame_annot)
345347
if frame_type is None:
346348
raise ValueError("subsets not loaded")

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

+21-9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from typing import Dict, List, Optional, Tuple, Type, Union
1515

1616
import numpy as np
17+
from iopath.common.file_io import PathManager
1718

1819
from omegaconf import DictConfig
1920
from pytorch3d.implicitron.dataset.dataset_map_provider import (
@@ -383,12 +384,11 @@ def _load_annotation_json(self, json_filename: str):
383384
return data
384385

385386
def _get_available_subset_names(self):
386-
path_manager = self.path_manager_factory.get()
387-
if path_manager is not None:
388-
dataset_root = path_manager.get_local_path(self.dataset_root)
389-
else:
390-
dataset_root = self.dataset_root
391-
return get_available_subset_names(dataset_root, self.category)
387+
return get_available_subset_names(
388+
self.dataset_root,
389+
self.category,
390+
path_manager=self.path_manager_factory.get(),
391+
)
392392

393393
def _extend_test_data_with_known_views(
394394
self,
@@ -425,18 +425,30 @@ def _extend_test_data_with_known_views(
425425
return eval_batch_index_out, list(test_subset_mapping_set)
426426

427427

428-
def get_available_subset_names(dataset_root: str, category: str) -> List[str]:
428+
def get_available_subset_names(
429+
dataset_root: str,
430+
category: str,
431+
path_manager: Optional[PathManager] = None,
432+
) -> List[str]:
429433
"""
430434
Get the available subset names for a given category folder inside a root dataset
431435
folder `dataset_root`.
432436
"""
433437
category_dir = os.path.join(dataset_root, category)
434-
if not os.path.isdir(category_dir):
438+
category_dir_exists = (
439+
(path_manager is not None) and path_manager.isdir(category_dir)
440+
) or os.path.isdir(category_dir)
441+
if not category_dir_exists:
435442
raise ValueError(
436443
f"Looking for dataset files in {category_dir}. "
437444
+ "Please specify a correct dataset_root folder."
438445
)
439-
set_list_jsons = os.listdir(os.path.join(category_dir, "set_lists"))
446+
447+
set_list_dir = os.path.join(category_dir, "set_lists")
448+
set_list_jsons = (os.listdir if path_manager is None else path_manager.ls)(
449+
set_list_dir
450+
)
451+
440452
return [
441453
json_file.replace("set_lists_", "").replace(".json", "")
442454
for json_file in set_list_jsons

Diff for: pytorch3d/implicitron/evaluation/evaluator.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class EvaluatorBase(ReplaceableBase):
3636
names and their values.
3737
"""
3838

39+
is_multisequence: bool = False
40+
3941
def run(
4042
self, model: ImplicitronModelBase, dataloader: DataLoader, **kwargs
4143
) -> Dict[str, Any]:
@@ -56,7 +58,6 @@ class ImplicitronEvaluator(EvaluatorBase):
5658
"""
5759

5860
camera_difficulty_bin_breaks: Tuple[float, ...] = 0.97, 0.98
59-
is_multisequence: bool = False
6061

6162
def __post_init__(self):
6263
run_auto_creation(self)

0 commit comments

Comments
 (0)