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

Refactor config for the Release. #136

Merged
merged 12 commits into from
May 15, 2024
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,4 @@ srun --cpus-per-task=4 --gres=gpumem:20G python -m vis4d.pl.run test \

## Contribute

[Check out our contribution guidelines for this project](docs/source/contribute.rst)
[Check out our contribution guidelines for this project](docs/source/dev_guide/contribute.rst)
36 changes: 19 additions & 17 deletions docs/source/user_guide/faster_rcnn_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,40 @@
"""Faster RCNN COCO training example."""
from __future__ import annotations

import tempfile

import lightning.pytorch as pl
import numpy as np
import tempfile
from torch.optim import SGD
from torch.optim.lr_scheduler import LinearLR, MultiStepLR

from vis4d.config import class_config
from vis4d.config.common.datasets.coco import (
CONN_COCO_BBOX_EVAL,
get_coco_detection_cfg,
)
from vis4d.config.common.models import get_faster_rcnn_cfg
from vis4d.config.default import (
get_default_callbacks_cfg,
get_default_cfg,
get_default_pl_trainer_cfg,
)
from vis4d.config.default.data_connectors import (
CONN_BBOX_2D_TEST,
CONN_BBOX_2D_TRAIN,
)
from vis4d.config.typing import (
ExperimentConfig,
ExperimentParameters,
ParameterSweepConfig,
)
from vis4d.config.util import get_lr_scheduler_cfg, get_optimizer_cfg
from vis4d.config.util.sweep import grid_search
from vis4d.config.sweep import grid_search
from vis4d.engine.callbacks import EvaluatorCallback
from vis4d.engine.connectors import CallbackConnector, DataConnector
from vis4d.eval.coco import COCODetectEvaluator
from vis4d.op.base import ResNet
from vis4d.zoo.base import (
get_default_callbacks_cfg,
get_default_cfg,
get_default_pl_trainer_cfg,
get_lr_scheduler_cfg,
get_optimizer_cfg,
)
from vis4d.zoo.base.data_connectors import (
CONN_BBOX_2D_TEST,
CONN_BBOX_2D_TRAIN,
)
from vis4d.zoo.base.datasets.coco import (
CONN_COCO_BBOX_EVAL,
get_coco_detection_cfg,
)
from vis4d.zoo.base.models.faster_rcnn import get_faster_rcnn_cfg


def get_config() -> ExperimentConfig:
Expand Down
2 changes: 1 addition & 1 deletion docs/source/user_guide/getting_started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@
"from vis4d.vis.functional.image import imshow_bboxes\n",
"\n",
"from vis4d.config import instantiate_classes\n",
"from vis4d.config.common.datasets.coco import get_coco_detection_cfg"
"from vis4d.zoo.base.datasets.coco import get_coco_detection_cfg"
]
},
{
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ plugins = ["numpy.typing.mypy_plugin"]
"terminaltables.*",
"timm.*",
"vis4d_cuda_ops.*",
"fvcore.*",
]
ignore_missing_imports = true

Expand Down
1 change: 0 additions & 1 deletion tests/config/common/__init__.py

This file was deleted.

4 changes: 2 additions & 2 deletions tests/config/registry_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pytest

from tests.util import get_test_data
from vis4d.config.util.registry import get_config_by_name, register_config
from vis4d.config.registry import get_config_by_name, register_config


class TestRegistry(unittest.TestCase):
Expand All @@ -16,7 +16,7 @@ class TestRegistry(unittest.TestCase):
def test_yaml(self) -> None:
"""Test reading a yaml config file."""
file = get_test_data(
"config_test/bdd100k/faster_rcnn/faster_rcnn_r50_1x_bdd100k.yaml"
"zoo_test/bdd100k/faster_rcnn/faster_rcnn_r50_1x_bdd100k.yaml"
)

# Config can be resolved
Expand Down
11 changes: 3 additions & 8 deletions tests/config/show_connection_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

import unittest

from tests.zoo.util import content_equal, get_config_for_name
from tests.util import content_equal, get_test_file
from tests.zoo.util import get_config_for_name
from vis4d.config import instantiate_classes
from vis4d.config.show_connection import prints_datagraph_for_config


class TestShowConfig(unittest.TestCase):
"""Tests the content of the provided configs for Show."""

gt_config_path = "tests/vis4d-test-data/config_test"

def test_show_frcnn(self) -> None:
"""Test the config for faster_rcnn_coco.py.

Expand All @@ -36,11 +35,7 @@ def test_show_frcnn(self) -> None:
model, train_data_connector, test_data_connector, loss, callbacks
)

with open(
f"{self.gt_config_path}/connection.txt",
"r",
encoding="UTF-8",
) as f:
with open(get_test_file("connection.txt"), "r", encoding="UTF-8") as f:
gt_dg = f.read()

self.assertTrue(content_equal(dg, gt_dg))
1 change: 0 additions & 1 deletion tests/config/sweep/__init__.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from ml_collections import ConfigDict

from vis4d.config.replicator import replicate_config
from vis4d.config.sweep import grid_search
from vis4d.config.typing import ExperimentConfig
from vis4d.config.util.sweep import grid_search


class TestSweep(unittest.TestCase):
Expand Down
62 changes: 62 additions & 0 deletions tests/config/testcases/connection.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
===================================
= Training Loop =
===================================
--------------
 <d>-boxes2d | | *boxes2d 
<d>-boxes2d_classes | | *boxes2d_classes
 <d>-images | Train Data | *images 
 <d>-input_hw | | *input_hw 
--------------
--------------
 boxes2d* | | <p>-proposals 
 boxes2d_classes* | | <p>-roi 
 images* | | *<p>-rpn 
 input_hw* | FasterRCNN | <p>-sampled_proposals 
 original_hw | | <p>-sampled_target_indices
  | | <p>-sampled_targets 
--------------
-----------
 <p>-rpn.cls* | | cls_outs 
 <d>-input_hw | | images_hw 
 <p>-rpn.box* | RPNLoss | reg_outs 
 <d>-boxes2d | | target_boxes
-----------
------------
<p>-sampled_proposals.boxes | | boxes 
 <p>-sampled_targets.labels | | boxes_mask 
 <p>-roi.cls_score | | class_outs 
 <p>-roi.bbox_pred | RCNNLoss | regression_outs
 <p>-sampled_targets.boxes | | target_boxes 
<p>-sampled_targets.classes | | target_classes 
------------
===================================
= Testing Loop =
===================================
-------------
 <d>-images | | *images 
 <d>-input_hw | Test Data | *input_hw 
<d>-original_hw | | *original_hw
-------------
--------------
 boxes2d | | <p>-boxes 
boxes2d_classes | | <p>-class_ids
 images* | FasterRCNN | <p>-scores 
 input_hw* | |  
 original_hw* | |  
--------------
===================================
= Callbacks =
===================================
-------------------------
 <p>-boxes | | *boxes 
 <p>-class_ids | | *class_ids 
 <d>-sample_names | BoundingBoxVisualizer | *image_names
<d>-original_images | | *images 
 <p>-scores | | *scores 
-------------------------
-----------------------
<d>-sample_names | | coco_image_id
 <p>-boxes | | pred_boxes 
 <p>-class_ids | COCODetectEvaluator | pred_classes 
 <p>-scores | | pred_scores 
-----------------------
2 changes: 1 addition & 1 deletion tests/engine/callbacks/evaluator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import torch

from tests.util import MockModel, get_test_data
from vis4d.config.common.datasets.coco import CONN_COCO_MASK_EVAL
from vis4d.data.const import CommonKeys as K
from vis4d.engine.callbacks import EvaluatorCallback, TrainerState
from vis4d.engine.connectors import CallbackConnector
from vis4d.eval.coco import COCODetectEvaluator
from vis4d.zoo.base.datasets.coco import CONN_COCO_MASK_EVAL


class TestEvaluatorCallback(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/engine/callbacks/visualizer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import torch

from tests.util import MOCKLOSS, MockModel
from vis4d.config.default.data_connectors import CONN_BBOX_2D_VIS
from vis4d.data.const import CommonKeys as K
from vis4d.engine.callbacks import TrainerState, VisualizerCallback
from vis4d.engine.connectors import CallbackConnector
from vis4d.vis.image import BoundingBoxVisualizer
from vis4d.zoo.base.data_connectors import CONN_BBOX_2D_VIS


class TestVisualizerCallback(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/engine/optim/optimizer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from tests.util import MockModel
from vis4d.config import class_config
from vis4d.config.typing import LrSchedulerConfig, ParamGroupCfg
from vis4d.config.util import get_lr_scheduler_cfg, get_optimizer_cfg
from vis4d.engine.optim import LRSchedulerWrapper, PolyLR, set_up_optimizers
from vis4d.zoo.base import get_lr_scheduler_cfg, get_optimizer_cfg


def get_optimizer(
Expand Down
2 changes: 1 addition & 1 deletion tests/eval/common/depth_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,6 @@ def test_precomputed(self) -> None:
metrics[DepthEvaluator.KEY_ABS_REL], 1.208, places=3
)
self.assertAlmostEqual(
metrics[DepthEvaluator.KEY_SQ_REL], 4.007, places=3
metrics[DepthEvaluator.KEY_SQ_REL], 5.635, places=3
)
assert isinstance(log_str, str)
2 changes: 1 addition & 1 deletion tests/eval/kitti/depth_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,6 @@ def test_precomputed(self) -> None:
metrics[KITTIDepthEvaluator.KEY_ABS_REL], 1.208, places=3
)
self.assertAlmostEqual(
metrics[KITTIDepthEvaluator.KEY_SQ_REL], 4.007, places=3
metrics[KITTIDepthEvaluator.KEY_SQ_REL], 5.635, places=3
)
assert isinstance(log_str, str)
10 changes: 5 additions & 5 deletions tests/model/detect/mask_rcnn_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@

from tests.util import get_test_data, get_test_file
from vis4d.common.ckpt import load_model_checkpoint
from vis4d.config.common.models.mask_rcnn import (
CONN_MASK_HEAD_LOSS_2D,
CONN_ROI_LOSS_2D,
CONN_RPN_LOSS_2D,
)
from vis4d.data.const import CommonKeys as K
from vis4d.data.datasets import COCO
from vis4d.engine.connectors import LossConnector
Expand All @@ -29,6 +24,11 @@
)
from vis4d.op.detect.rcnn import RCNNLoss, get_default_rcnn_box_codec
from vis4d.op.detect.rpn import RPNLoss, get_default_rpn_box_codec
from vis4d.zoo.base.models.mask_rcnn import (
CONN_MASK_HEAD_LOSS_2D,
CONN_ROI_LOSS_2D,
CONN_RPN_LOSS_2D,
)

from .faster_rcnn_test import get_test_dataloader, get_train_dataloader

Expand Down
4 changes: 2 additions & 2 deletions tests/op/base/resnet_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ def test_resnet():

# test norm freezed
model.trainable_layers = 5
model.norm_freezed = True
model.norm_frozen = True
model.train()
for m in model.modules():
if isinstance(m, _BatchNorm):
assert not m.training
model.norm_freezed = False
model.norm_frozen = False
model.train()
for m in model.modules():
if isinstance(m, _BatchNorm):
Expand Down
2 changes: 1 addition & 1 deletion tests/pl/data_module_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from torch.utils.data.dataloader import DataLoader

from tests.util import get_test_data
from vis4d.config.common.datasets.coco import get_coco_detection_cfg
from vis4d.pl.data_module import DataModule
from vis4d.zoo.base.datasets.coco import get_coco_detection_cfg


class DataModuleTest(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/pl/trainer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

from tests.util import get_test_data
from vis4d.config import class_config
from vis4d.config.util import get_optimizer_cfg
from vis4d.data.const import CommonKeys as K
from vis4d.data.datasets import COCO
from vis4d.data.loader import DataPipe, build_train_dataloader
Expand All @@ -38,6 +37,7 @@
from vis4d.pl.callbacks import CallbackWrapper, LRSchedulerCallback
from vis4d.pl.trainer import PLTrainer
from vis4d.pl.training_module import TrainingModule
from vis4d.zoo.base import get_optimizer_cfg


def seg_pipeline(data: list[DictData]) -> DictData:
Expand Down
40 changes: 40 additions & 0 deletions tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,43 @@ def forward( # type: ignore
).sum()
}
return {}


def content_equal(
content1: str, content2: str, ignored_props: list[str] | None = None
) -> bool:
"""Compare two strings line by line.

Args:
content1 (str): First file content
content2 (str): Second file content
ignored_props (list[str], optional): List of properties to ignore.
All lines matching any of these properties (followed by a ':')
will be ignored. Defaults to [].
"""
if ignored_props is None:
ignored_props = []

lines1 = content1.splitlines()
lines2 = content2.splitlines()
if len(lines1) != len(lines2):
print("File length mismatch:", len(lines1), "!=", len(lines2))
return False

for line_id, line1 in enumerate(lines1):
skip = False
for prop in ignored_props:
# Append `:` to avoid matching a property that is a substring of
# another property
prop = prop + ":"
if prop in line1 and prop in lines2[line_id]:
skip = True
continue # ignore these lines

if not skip and line1 != lines2[line_id]:
print(
"Line mismatch #", line_id, ":", line1, "!=", lines2[line_id]
)
return False

return True
2 changes: 1 addition & 1 deletion tests/vis4d-test-data
Submodule vis4d-test-data updated 41 files
+0 −62 config_test/connection.txt
+7 −6 zoo_test/bdd100k/faster_rcnn/faster_rcnn_r50_1x_bdd100k.yaml
+7 −6 zoo_test/bdd100k/faster_rcnn/faster_rcnn_r50_3x_bdd100k.yaml
+7 −6 zoo_test/bdd100k/mask_rcnn/mask_rcnn_r50_1x_bdd100k.yaml
+7 −6 zoo_test/bdd100k/mask_rcnn/mask_rcnn_r50_3x_bdd100k.yaml
+7 −6 zoo_test/bdd100k/mask_rcnn/mask_rcnn_r50_5x_bdd100k.yaml
+11 −9 zoo_test/bdd100k/qdtrack/qdtrack_frcnn_r50_fpn_1x_bdd100k.yaml
+7 −6 zoo_test/bdd100k/semantic_fpn/semantic_fpn_r101_80k_bdd100k.yaml
+7 −6 zoo_test/bdd100k/semantic_fpn/semantic_fpn_r50_40k_bdd100k.yaml
+7 −6 zoo_test/bdd100k/semantic_fpn/semantic_fpn_r50_80k_bdd100k.yaml
+7 −6 zoo_test/bevformer/bevformer_base.yaml
+9 −8 zoo_test/bevformer/bevformer_tiny.yaml
+7 −6 zoo_test/bevformer/bevformer_vis.yaml
+8 −7 zoo_test/cc_3dt/cc_3dt_bevformer_base_velo_lstm_nusc.yaml
+8 −7 zoo_test/cc_3dt/cc_3dt_frcnn_r101_fpn_kf3d_24e_nusc.yaml
+7 −6 zoo_test/cc_3dt/cc_3dt_frcnn_r101_fpn_pure_det_nusc.yaml
+8 −7 zoo_test/cc_3dt/cc_3dt_frcnn_r101_fpn_velo_lstm_24e_nusc.yaml
+8 −7 zoo_test/cc_3dt/cc_3dt_frcnn_r50_fpn_kf3d_12e_nusc.yaml
+8 −7 zoo_test/cc_3dt/cc_3dt_nusc_vis.yaml
+6 −5 zoo_test/cc_3dt/velo_lstm_bevformer_base_100e_nusc.yaml
+6 −5 zoo_test/cc_3dt/velo_lstm_frcnn_r101_fpn_100e_nusc.yaml
+7 −6 zoo_test/faster_rcnn/faster_rcnn_coco.yaml
+6 −5 zoo_test/fcn_resnet/fcn_resnet_coco.yaml
+7 −6 zoo_test/mask_rcnn/mask_rcnn_coco.yaml
+8 −7 zoo_test/qdtrack/qdtrack_frcnn_r50_fpn_augs_1x_bdd100k.yaml
+20 −18 zoo_test/qdtrack/qdtrack_yolox_x_25e_bdd100k.yaml
+7 −6 zoo_test/retinanet/retinanet_coco.yaml
+7 −6 zoo_test/shift/faster_rcnn/faster_rcnn_r50_12e_shift.yaml
+7 −6 zoo_test/shift/faster_rcnn/faster_rcnn_r50_36e_shift.yaml
+7 −6 zoo_test/shift/faster_rcnn/faster_rcnn_r50_6e_shift_all_domains.yaml
+7 −6 zoo_test/shift/mask_rcnn/mask_rcnn_r50_12e_shift.yaml
+7 −6 zoo_test/shift/mask_rcnn/mask_rcnn_r50_36e_shift.yaml
+7 −6 zoo_test/shift/mask_rcnn/mask_rcnn_r50_6e_shift_all_domains.yaml
+7 −6 zoo_test/shift/semantic_fpn/semantic_fpn_r50_160k_shift.yaml
+7 −6 zoo_test/shift/semantic_fpn/semantic_fpn_r50_160k_shift_all_domains.yaml
+7 −6 zoo_test/shift/semantic_fpn/semantic_fpn_r50_40k_shift.yaml
+7 −6 zoo_test/shift/semantic_fpn/semantic_fpn_r50_40k_shift_all_domains.yaml
+6 −5 zoo_test/vit/vit_small_imagenet.yaml
+6 −5 zoo_test/vit/vit_tiny_imagenet.yaml
+8 −7 zoo_test/yolox/yolox_s_300e_coco.yaml
+8 −7 zoo_test/yolox/yolox_tiny_300e_coco.yaml
1 change: 1 addition & 0 deletions tests/zoo/base/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Model zoo base test."""
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

from tests.util import get_test_data
from vis4d.config import instantiate_classes
from vis4d.config.common.datasets.bdd100k.detect import (
from vis4d.data.const import CommonKeys as K
from vis4d.zoo.base.datasets.bdd100k.detect import (
get_test_dataloader,
get_train_dataloader,
)
from vis4d.data.const import CommonKeys as K


class TestDetPreprocessing(unittest.TestCase):
Expand Down
Loading
Loading