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

v0.1.3 #138

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
59534e9
fix: Fix reduce_mean and nms.
RoyYang0714 Jul 9, 2024
91b2fca
fix: Fix lint.
RoyYang0714 Jul 10, 2024
96871a5
feat: Add VIS flag and update transformer related code.
RoyYang0714 Jul 26, 2024
c834f28
fix: Fix mypy for PyTorch 2.4.0
RoyYang0714 Jul 26, 2024
456e3da
feat: Add compute FLOPs flag.
RoyYang0714 Aug 7, 2024
70fbfd7
feat: Add fix sized resize, update vis functional and fix test error.
RoyYang0714 Aug 21, 2024
4f490d1
fix: Fix tests.
RoyYang0714 Aug 21, 2024
17c4e02
fix: Update ipynb for test.
RoyYang0714 Aug 21, 2024
d042e2f
feat: Update docs.
RoyYang0714 Aug 22, 2024
f90fdb4
fix: Separate to hdf5 script.
RoyYang0714 Aug 23, 2024
633a711
Merge branch '0.1.3' of github.com:SysCV/vis4d into 0.1.3
RoyYang0714 Aug 23, 2024
539b8a9
feat: Give user freedom to select dist tmp dir.
RoyYang0714 Aug 27, 2024
04ae3e9
Merge branch '0.1.3' of github.com:SysCV/vis4d into 0.1.3
RoyYang0714 Aug 27, 2024
8b0055f
fix: Fix pylint.
RoyYang0714 Aug 27, 2024
68c99ce
feat: Add pl trainer ddp timeout and separate evaluator callback meti…
RoyYang0714 Aug 30, 2024
4ca57f6
fix: Fix lint.
RoyYang0714 Aug 30, 2024
ae4523a
fix: Fix bbox3d visualizer for corner cases. Update Visualizer callba…
RoyYang0714 Sep 2, 2024
d95fb72
feat: Add grad checking and set wandb id.
RoyYang0714 Oct 13, 2024
53f2242
fix: Fix function args.
RoyYang0714 Oct 15, 2024
efd205c
feat: Update CBGS, bbox3D visualization.
RoyYang0714 Nov 28, 2024
d8751fe
feat: Add AspectRationBatchSampler.
RoyYang0714 Dec 2, 2024
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
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

project = "Vis4D"
copyright = "2022, ETH Zurich"
author = "Tobias Fischer"
author = "Vis4D Team"


# -- General configuration ---------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions docs/source/datasets.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
********
Datasets
********
12 changes: 7 additions & 5 deletions docs/source/dev_guide/cli.rst
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
###
CLI
###

We provide a command line interface for training and evaluating your models.
Assuming you have installed the package using pip, you can use the command `vis4d` to access the CLI.

Alternatively, you can run the CLI using `python -m vis4d.engine.cli` or `python -m vis4d.pl.cli` if you want to use the PyTorch Lightning version.
Alternatively, you can run the CLI using `python -m vis4d.engine.run` or `python -m vis4d.pl.run` if you want to use the PyTorch Lightning version.

The CLI relies on a configuration file to specify each experiment. We use `ml_collections <https://github.com/google/ml_collections>`_ as underlying framework to define the configuration files.
You can read up on our configuration files in the `Config System <configuration_files>`_ section.

=============
CLI Interface
=============

The provided examples assume that the experiment configuration file is located at `path_to_experiment_cfg.py`.
You can read up on our configuration files in the `Config System <configuration_files>`_ section.

Expand All @@ -20,6 +22,7 @@ We support both, our own training engine as well as `PyTorch Lightning <https://
------------
CLI Commands
------------

.. code-block:: bash

vis4d [fit | test] --config path_to_experiment_cfg.py
Expand Down Expand Up @@ -54,16 +57,14 @@ Quick Start

.. code-block:: bash

vis4d fit --config path_to_experiment_cfg.py
vis4d test --config path_to_experiment_cfg.py

**Overwrite Config Parameters**

.. code-block:: bash

vis4d fit --config path_to_experiment_cfg.py --config.my_field=2 --config.my.nested.field="test"



**Perform Parameter Sweeps**

.. code-block:: bash
Expand All @@ -87,6 +88,7 @@ Note that misstyping a config parameter
vis4d fit --config path_to_experiment_cfg.py --config.params.lrs=0.01

will result in the following error:

.. code-block:: bash

AttributeError: Did you mean "lr" instead of "lrw"?'
AttributeError: Did you mean "lr" instead of "lrs"?'
4 changes: 0 additions & 4 deletions docs/source/faq/trouble.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
Troubleshooting
***************

================
Training crashes
================

-----------
File limits
-----------
Expand Down
2 changes: 1 addition & 1 deletion docs/source/user_guide/3D_visualization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"os.environ[\"WEBRTC_IP\"] = \"127.0.0.1\"\n",
"\n",
"import pickle\n",
"from vis4d.vis.functional import show_points\n",
"from vis4d.vis.pointcloud.functional import show_points\n",
"import numpy as np"
]
},
Expand Down
2 changes: 1 addition & 1 deletion docs/source/user_guide/faster_rcnn_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

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

from vis4d.config import class_config
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 @@ -251,7 +251,7 @@
"from vis4d.model.detect.faster_rcnn import FasterRCNN\n",
"\n",
"from vis4d.data.const import CommonKeys as K\n",
"from vis4d.vis.functional.image import imshow_bboxes\n",
"from vis4d.vis.image.functional import imshow_bboxes\n",
"\n",
"from vis4d.config import instantiate_classes\n",
"from vis4d.zoo.base.datasets.coco import get_coco_detection_cfg"
Expand Down
16 changes: 3 additions & 13 deletions docs/source/user_guide/visualization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,12 @@
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Jupyter environment detected. Enabling Open3D WebVisualizer.\n",
"[Open3D INFO] WebRTC GUI backend enabled.\n",
"[Open3D INFO] WebRTCWindowSystem: HTTP handshake server disabled.\n"
]
}
],
"outputs": [],
"source": [
"from __future__ import annotations\n",
"\n",
"from vis4d.common.typing import NDArrayF64, NDArrayI64\n",
"from vis4d.vis.functional import imshow_bboxes, imshow_masks, imshow_topk_bboxes, imshow, draw_bboxes, draw_masks, imshow_track_matches\n",
"from vis4d.vis.image.functional import imshow_bboxes, imshow_masks, imshow_topk_bboxes, imshow, draw_bboxes, draw_masks, imshow_track_matches\n",
"\n",
"import pickle\n",
"import numpy as np"
Expand Down Expand Up @@ -453,7 +443,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
"version": "3.11.9"
},
"vscode": {
"interpreter": {
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ line_length = 79

[tool.pyright]
include = ["vis4d"]
typeCheckingMode = "off"

[tool.coverage]
[tool.coverage.report]
Expand Down
2 changes: 1 addition & 1 deletion requirements/install.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ h5py
jsonargparse[signatures]
lightning
ml_collections==0.1.1 # Config interface. Need exact version since we overwrite internal functions
numpy>=1.21.0
numpy>=1.21.0,<2.0.0
opencv-python
pandas
pillow
Expand Down
1 change: 1 addition & 0 deletions requirements/viewer.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
open3d
matplotlib>3.9
2 changes: 1 addition & 1 deletion tests/data/io/to_hdf5_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import unittest

from tests.util import get_test_data
from vis4d.data.io.hdf5 import convert_dataset
from vis4d.data.io.to_hdf5 import convert_dataset


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

from torch.optim import SGD
from torch.optim.sgd import SGD

from tests.util import MOCKLOSS, MockModel
from vis4d.config import class_config
Expand Down
4 changes: 2 additions & 2 deletions tests/engine/optim/scheduler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import torch
import torch.nn.functional as F
from torch import optim
from torch.optim.lr_scheduler import LRScheduler
from torch.optim.sgd import SGD
from torch.testing import assert_close

from vis4d.engine.optim.scheduler import ConstantLR, PolyLR, QuadraticLRWarmup
Expand Down Expand Up @@ -68,7 +68,7 @@ def setUp(self) -> None:
model = ToyModel()
self.lr = 0.05
self.l2_mult = 10
self.optimizer = optim.SGD(
self.optimizer = SGD(
[
{"params": model.conv1.parameters()},
{
Expand Down
4 changes: 2 additions & 2 deletions tests/model/detect/mask_rcnn_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import unittest

import torch
from torch import optim
from torch.optim.sgd import SGD

from tests.util import get_test_data, get_test_file
from vis4d.common.ckpt import load_model_checkpoint
Expand Down Expand Up @@ -120,7 +120,7 @@ def test_train(self):
]
)

optimizer = optim.SGD(mask_rcnn.parameters(), lr=0.001, momentum=0.9)
optimizer = SGD(mask_rcnn.parameters(), lr=0.001, momentum=0.9)

dataset = COCO(get_test_data("coco_test"), split="train")
train_loader = get_train_dataloader(dataset, 2, (256, 256))
Expand Down
4 changes: 2 additions & 2 deletions tests/model/detect/retinanet_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import unittest

import torch
from torch import optim
from torch.optim.sgd import SGD

from tests.util import get_test_data, get_test_file
from vis4d.common.ckpt import load_model_checkpoint
Expand Down Expand Up @@ -75,7 +75,7 @@ def test_train(self) -> None:
retina_net.retinanet_head.box_sampler,
)

optimizer = optim.SGD(retina_net.parameters(), lr=0.001, momentum=0.9)
optimizer = SGD(retina_net.parameters(), lr=0.001, momentum=0.9)

dataset = COCO(get_test_data("coco_test"), split="train")
train_loader = get_train_dataloader(dataset, 2, (256, 256))
Expand Down
4 changes: 2 additions & 2 deletions tests/model/seg/fcn_resnet_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import unittest

import torch
from torch import optim
from torch.optim.sgd import SGD

from tests.util import get_test_data, get_test_file
from vis4d.common.ckpt import load_model_checkpoint
Expand Down Expand Up @@ -46,7 +46,7 @@ def test_train(self) -> None:
"""Test FCNResNet training."""
model = FCNResNet(base_model="resnet50", resize=(64, 64))
loss_fn = MultiLevelSegLoss(feature_idx=(4, 5), weights=[0.5, 1])
optimizer = optim.SGD(model.parameters(), lr=0.01, momentum=0.9)
optimizer = SGD(model.parameters(), lr=0.01, momentum=0.9)
dataset = COCO(
get_test_data("coco_test"), split="train", use_pascal_voc_cats=True
)
Expand Down
4 changes: 2 additions & 2 deletions tests/model/seg/semantic_fpn_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import unittest

import torch
from torch import optim
from torch.optim.sgd import SGD

from tests.util import get_test_data, get_test_file
from vis4d.data.const import CommonKeys as K
Expand Down Expand Up @@ -59,7 +59,7 @@ def test_train(self) -> None:
"""Test SemanticFPN training."""
model = SemanticFPN(num_classes=21)
loss_fn = SegCrossEntropyLoss()
optimizer = optim.SGD(model.parameters(), lr=0.01, momentum=0.9)
optimizer = SGD(model.parameters(), lr=0.01, momentum=0.9)
train_loader = get_train_dataloader(self.dataset, 2)
model.train()

Expand Down
4 changes: 2 additions & 2 deletions tests/pl/trainer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import unittest

from ml_collections import ConfigDict
from torch import optim
from torch.optim.sgd import SGD
from torch.utils.data import DataLoader, Dataset

from tests.util import get_test_data
Expand Down Expand Up @@ -85,7 +85,7 @@ def get_training_module(model_cfg: ConfigDict):
}
)

optimizer_cfg = get_optimizer_cfg(class_config(optim.SGD, lr=0.01))
optimizer_cfg = get_optimizer_cfg(class_config(SGD, lr=0.01))
return TrainingModule(
model_cfg=model_cfg,
optimizers_cfg=[optimizer_cfg],
Expand Down
4 changes: 3 additions & 1 deletion tests/vis/image/bounding_box_visualizer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ def setUp(self) -> None:
self.scores: list[NDArrayF64] = testcase_gt["scores"]
self.tracks = [np.arange(len(b)) for b in self.boxes]

cat_mapping = {v: k for k, v in COCO_COLOR_MAPPING.items()}

self.vis = BoundingBoxVisualizer(
n_colors=20, class_id_mapping=COCO_COLOR_MAPPING, vis_freq=1
n_colors=20, cat_mapping=cat_mapping, vis_freq=1
)

def tearDown(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion tests/vis4d-test-data
Submodule vis4d-test-data updated 41 files
+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
+6 −5 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
+7 −6 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
+1,134 −0 zoo_test/cc_3dt/cc_3dt_nusc_test.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
+8 −7 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
12 changes: 12 additions & 0 deletions tests/zoo/cc_3dt_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ def test_nusc_vis(self) -> None:
)
)

def test_nusc_test(self) -> None:
"""Test the config."""
cfg_gt = f"{self.gt_config_path}/cc_3dt_nusc_test.yaml"

self.assertTrue(
compare_configs(
f"{self.config_prefix}.cc_3dt_nusc_test",
cfg_gt,
self.varying_keys,
)
)

def test_bevformer_base_velo_lstm_nusc(self) -> None:
"""Test the config."""
cfg_gt = (
Expand Down
4 changes: 3 additions & 1 deletion vis4d/common/ckpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ def load_from_local(
filename = osp.expanduser(filename)
if not osp.isfile(filename):
raise FileNotFoundError(f"{filename} can not be found.")
checkpoint = torch.load(filename, map_location=map_location)
checkpoint = torch.load(
filename, weights_only=True, map_location=map_location
)
return checkpoint


Expand Down
14 changes: 8 additions & 6 deletions vis4d/common/distributed.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def all_gather_object_gpu( # type: ignore


def create_tmpdir(
rank: int, tmpdir: None | str = None
rank: int, tmpdir: None | str = None, use_system_tmp: bool = True
) -> str: # pragma: no cover
"""Create and distribute a temporary directory across all processes."""
if tmpdir is not None:
Expand All @@ -273,10 +273,10 @@ def create_tmpdir(
if rank == 0:
# create a temporary directory
default_tmpdir = tempfile.gettempdir()
if default_tmpdir is not None:
if default_tmpdir is not None and use_system_tmp:
dist_tmpdir = os.path.join(default_tmpdir, ".dist_tmp")
else:
dist_tmpdir = ".dist_tmp"
dist_tmpdir = os.path.join("vis4d-workspace", ".dist_tmp")
os.makedirs(dist_tmpdir, exist_ok=True)
tmpdir = tempfile.mkdtemp(dir=dist_tmpdir)
else:
Expand All @@ -288,13 +288,15 @@ def all_gather_object_cpu( # type: ignore
data: Any,
tmpdir: None | str = None,
rank_zero_return_only: bool = True,
use_system_tmp: bool = True,
) -> list[Any] | None: # pragma: no cover
"""Share arbitrary picklable data via file system caching.

Args:
data: any picklable object.
tmpdir: Save path for temporary files. If None, safely create tmpdir.
rank_zero_return_only: if results should only be returned on rank 0
rank_zero_return_only: if results should only be returned on rank 0.
use_system_tmp: if use system tmpdir or not.

Returns:
list[Any]: list of data gathered from each process.
Expand All @@ -304,7 +306,7 @@ def all_gather_object_cpu( # type: ignore
return [data]

# make tmp dir
tmpdir = create_tmpdir(rank, tmpdir)
tmpdir = create_tmpdir(rank, tmpdir, use_system_tmp)

# encode & save
with open(os.path.join(tmpdir, f"part_{rank}.pkl"), "wb") as f:
Expand Down Expand Up @@ -335,7 +337,7 @@ def reduce_mean(tensor: torch.Tensor) -> torch.Tensor:
if not (dist.is_available() and dist.is_initialized()):
return tensor
tensor = tensor.clone()
dist.all_reduce(tensor.div_(dist.get_world_size()), op=dist.ReduceOp.SUM)
dist.all_reduce(tensor.div_(get_world_size()), op=dist.ReduceOp.SUM)
return tensor


Expand Down
2 changes: 1 addition & 1 deletion vis4d/common/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def set_tf32(use_tf32: bool, precision: str) -> None: # pragma: no cover

def init_random_seed() -> int:
"""Initialize random seed for the experiment."""
return np.random.randint(2**31)
return int(np.random.randint(2**31))


def set_random_seed(seed: int, deterministic: bool = False) -> None:
Expand Down
Loading
Loading