Skip to content

Commit

Permalink
[Fix] Fix some bugs to be compatible with the latest mmcv and mmengine (
Browse files Browse the repository at this point in the history
#687)

* fix some import errors about mmcv and unit test

* update the version of torchvision

* skip cpu ut for prdimp

* fix UT about mask2former

* fix prdimp ut

* reduce reid channel in strongsort

Co-authored-by: Pengxiang Li <[email protected]>
  • Loading branch information
JingweiZhang12 and Pengxiang Li authored Aug 24, 2022
1 parent 9208168 commit 067cc16
Show file tree
Hide file tree
Showing 34 changed files with 106 additions and 98 deletions.
6 changes: 3 additions & 3 deletions .circleci/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ workflows:
- dev-1.x
- build_cpu:
name: minimum_version_cpu
torch: 1.6.0
torchvision: 0.7.0
torch: 1.7.0
torchvision: 0.8.1
python: 3.6.9 # The lowest python 3.6.x version available on CircleCI images
mmcv: https://download.openmmlab.com/mmcv/dev-2.x/cpu/torch1.6.0/mmcv_full-2.0.0rc0-cp36-cp36m-manylinux1_x86_64.whl
requires:
Expand Down Expand Up @@ -187,7 +187,7 @@ workflows:
jobs:
- build_cuda:
name: minimum_version_gpu
torch: 1.6.0
torch: 1.7.0
# Use double quotation mark to explicitly specify its type
# as string instead of number
mmcv: https://download.openmmlab.com/mmcv/dev-2.x/cu101/torch1.6.0/mmcv_full-2.0.0rc0-cp37-cp37m-manylinux1_x86_64.whl
Expand Down
4 changes: 2 additions & 2 deletions .dev_scripts/benchmark/gather_train_benchmark_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import json
import os.path as osp

import mmcv
import mmengine

try:
import xlrd
Expand Down Expand Up @@ -67,7 +67,7 @@ def parse_args():
if osp.exists(result_path):

# 1 read config and excel
cfg = mmcv.Config.fromfile(config)
cfg = mmengine.Config.fromfile(config)
total_epochs = cfg.train_cfg.max_epochs if cfg.train_cfg else 0

# the first metric will be used to find the best ckpt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
transformer=dict(
type='StarkTransformer',
encoder=dict(
type='DetrTransformerEncoder',
type='mmdet.DetrTransformerEncoder',
num_layers=6,
transformerlayers=dict(
type='BaseTransformerLayer',
Expand All @@ -53,7 +53,7 @@
ffn_drop=0.1),
operation_order=('self_attn', 'norm', 'ffn', 'norm'))),
decoder=dict(
type='DetrTransformerDecoder',
type='mmdet.DetrTransformerDecoder',
return_intermediate=False,
num_layers=6,
transformerlayers=dict(
Expand All @@ -72,7 +72,8 @@
'ffn', 'norm'))),
),
positional_encoding=dict(
type='SinePositionalEncoding', num_feats=128, normalize=True),
type='mmdet.SinePositionalEncoding', num_feats=128,
normalize=True),
bbox_head=dict(
type='CornerPredictorHead',
inplanes=256,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
num_frames=num_frames,
num_transformer_feat_level=3,
pixel_decoder=dict(
type='MSDeformAttnPixelDecoder',
type='mmdet.MSDeformAttnPixelDecoder',
num_outs=3,
norm_cfg=dict(type='GN', num_groups=32),
act_cfg=dict(type='ReLU'),
encoder=dict(
type='DetrTransformerEncoder',
type='mmdet.DetrTransformerEncoder',
num_layers=6,
transformerlayers=dict(
type='BaseTransformerLayer',
Expand All @@ -65,17 +65,19 @@
operation_order=('self_attn', 'norm', 'ffn', 'norm')),
init_cfg=None),
positional_encoding=dict(
type='SinePositionalEncoding', num_feats=128, normalize=True),
type='mmdet.SinePositionalEncoding',
num_feats=128,
normalize=True),
init_cfg=None),
enforce_decoder_input_project=False,
positional_encoding=dict(
type='SinePositionalEncoding3D', num_feats=128, normalize=True),
transformer_decoder=dict(
type='DetrTransformerDecoder',
type='mmdet.DetrTransformerDecoder',
return_intermediate=True,
num_layers=9,
transformerlayers=dict(
type='DetrTransformerDecoderLayer',
type='mmdet.DetrTransformerDecoderLayer',
attn_cfgs=dict(
type='MultiheadAttention',
embed_dims=256,
Expand Down
2 changes: 1 addition & 1 deletion mmtrack/apis/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def init_model(config: Union[str, mmengine.Config],
"""Initialize a model from config file.
Args:
config (str or :obj:`mmcv.Config`): Config file path or the config
config (str or :obj:`mmengine.Config`): Config file path or the config
object.
checkpoint (Optional[str], optional): Checkpoint path. Defaults to
None.
Expand Down
2 changes: 1 addition & 1 deletion mmtrack/datasets/transforms/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import numpy as np
from mmcv.transforms import BaseTransform
from mmcv.utils import print_log
from mmengine.logging import print_log

from mmtrack.registry import TRANSFORMS

Expand Down
2 changes: 1 addition & 1 deletion mmtrack/datasets/transforms/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy as np
from mmcv.transforms import BaseTransform
from mmcv.transforms.utils import cache_randomness
from mmcv.utils import print_log
from mmengine.logging import print_log

from mmtrack.registry import TRANSFORMS
from mmtrack.utils import crop_image
Expand Down
3 changes: 2 additions & 1 deletion mmtrack/engine/hooks/visualization_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from mmengine.fileio import FileClient
from mmengine.hooks import Hook
from mmengine.runner import Runner
from mmengine.utils import mkdir_or_exist
from mmengine.visualization import Visualizer

from mmtrack.registry import HOOKS
Expand Down Expand Up @@ -122,7 +123,7 @@ def after_test_iter(self, runner: Runner, batch_idx: int,
if self.test_out_dir is not None:
self.test_out_dir = osp.join(runner.work_dir, runner.timestamp,
self.test_out_dir)
mmcv.mkdir_or_exist(self.test_out_dir)
mkdir_or_exist(self.test_out_dir)

assert len(data_batch) == len(outputs) == 1, \
'only batch_size=1 is supported while testing.'
Expand Down
2 changes: 1 addition & 1 deletion mmtrack/evaluation/metrics/base_video_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from typing import Optional

import torch
from mmengine import mkdir_or_exist
from mmengine.dist import (barrier, broadcast, broadcast_object_list,
get_dist_info, is_main_process)
from mmengine.evaluator import BaseMetric
from mmengine.utils import mkdir_or_exist


class BaseVideoMetric(BaseMetric):
Expand Down
12 changes: 5 additions & 7 deletions mmtrack/models/track_heads/mask2former_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import Conv2d, build_plugin_layer, caffe2_xavier_init
from mmcv.cnn.bricks.transformer import build_transformer_layer_sequence
from mmcv.cnn import Conv2d
from mmcv.ops import point_sample
from mmcv.runner import ModuleList
from mmdet.models.dense_heads import AnchorFreeHead
from mmdet.models.dense_heads import MaskFormerHead as MMDET_MaskFormerHead
from mmdet.models.utils import get_uncertain_point_coords_with_randomness
from mmdet.structures.mask import mask2bbox
from mmdet.utils import ConfigType, OptConfigType, OptMultiConfig, reduce_mean
from mmengine.data import InstanceData
from mmengine.model import ModuleList
from mmengine.model.utils import caffe2_xavier_init
from torch import Tensor

from mmtrack.registry import MODELS, TASK_UTILS
Expand Down Expand Up @@ -115,10 +115,8 @@ def __init__(self,
in_channels=in_channels,
feat_channels=feat_channels,
out_channels=out_channels)
# TODO: change to `MODELS.build`
self.pixel_decoder = build_plugin_layer(pixel_decoder_)[1]
self.transformer_decoder = build_transformer_layer_sequence(
transformer_decoder)
self.pixel_decoder = MODELS.build(pixel_decoder_)
self.transformer_decoder = MODELS.build(transformer_decoder)
self.decoder_embed_dims = self.transformer_decoder.embed_dims

self.decoder_input_projs = ModuleList()
Expand Down
26 changes: 13 additions & 13 deletions mmtrack/models/track_heads/stark_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ class StarkTransformer(Transformer):
<https://arxiv.org/pdf/2005.12872>`_ for details.
Args:
encoder (`mmcv.ConfigDict` | Dict): Config of
encoder (`mmengine.ConfigDict` | Dict): Config of
TransformerEncoder. Defaults to None.
decoder ((`mmcv.ConfigDict` | Dict)): Config of
decoder ((`mmengine.ConfigDict` | Dict)): Config of
TransformerDecoder. Defaults to None
init_cfg (obj:`mmcv.ConfigDict`): The Config for initialization.
init_cfg (obj:`mmengine.ConfigDict`): The Config for initialization.
Defaults to None.
"""

Expand Down Expand Up @@ -274,23 +274,23 @@ class StarkHead(BaseModule):
Args:
num_query (int): Number of query in transformer.
transformer (obj:`mmcv.ConfigDict`|dict): Config for transformer.
transformer (obj:`mmengine.ConfigDict`|dict): Config for transformer.
Default: None.
positional_encoding (obj:`mmcv.ConfigDict`|dict):
positional_encoding (obj:`mmengine.ConfigDict`|dict):
Config for position encoding.
bbox_head (obj:`mmcv.ConfigDict`|dict, optional): Config for bbox head.
Defaults to None.
cls_head (obj:`mmcv.ConfigDict`|dict, optional): Config for
bbox_head (obj:`mmengine.ConfigDict`|dict, optional): Config for bbox
head. Defaults to None.
cls_head (obj:`mmengine.ConfigDict`|dict, optional): Config for
classification head. Defaults to None.
loss_cls (obj:`mmcv.ConfigDict`|dict): Config of the
loss_cls (obj:`mmengine.ConfigDict`|dict): Config of the
classification loss. Default `CrossEntropyLoss`.
loss_bbox (obj:`mmcv.ConfigDict`|dict): Config of the bbox
loss_bbox (obj:`mmengine.ConfigDict`|dict): Config of the bbox
regression loss. Default `L1Loss`.
loss_iou (obj:`mmcv.ConfigDict`|dict): Config of the bbox
loss_iou (obj:`mmengine.ConfigDict`|dict): Config of the bbox
regression iou loss. Default `GIoULoss`.
tran_cfg (obj:`mmcv.ConfigDict`|dict): Training config of
tran_cfg (obj:`mmengine.ConfigDict`|dict): Training config of
transformer head.
test_cfg (obj:`mmcv.ConfigDict`|dict): Testing config of
test_cfg (obj:`mmengine.ConfigDict`|dict): Testing config of
transformer head.
init_cfg (dict or list[dict], optional): Initialization config dict.
Default: None
Expand Down
4 changes: 2 additions & 2 deletions mmtrack/structures/reid_data_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from numbers import Number
from typing import Sequence, Union

import mmcv
import mmengine
import numpy as np
import torch
from mmengine.data import BaseDataElement, LabelData
Expand Down Expand Up @@ -30,7 +30,7 @@ def format_label(value: Union[torch.Tensor, np.ndarray, Sequence, int],

if isinstance(value, np.ndarray):
value = torch.from_numpy(value)
elif isinstance(value, Sequence) and not mmcv.is_str(value):
elif isinstance(value, Sequence) and not mmengine.utils.is_str(value):
value = torch.tensor(value)
elif isinstance(value, int):
value = torch.LongTensor([value])
Expand Down
2 changes: 1 addition & 1 deletion mmtrack/testing/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def _get_config_directory():

def _get_config_module(fname):
"""Load a configuration as a python module."""
from mmcv import Config
from mmengine import Config
config_dpath = _get_config_directory()
config_fpath = join(config_dpath, fname)
config_mod = Config.fromfile(config_fpath)
Expand Down
2 changes: 1 addition & 1 deletion mmtrack/utils/collect_env.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (c) OpenMMLab. All rights reserved.
from mmcv.utils import collect_env as collect_base_env
from mmcv.utils import get_git_hash
from mmengine.utils import get_git_hash

import mmtrack

Expand Down
2 changes: 1 addition & 1 deletion mmtrack/utils/mot_error_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import numpy as np
import seaborn as sns
from matplotlib.patches import Rectangle
from mmcv.utils import mkdir_or_exist
from mmengine.utils import mkdir_or_exist


def imshow_mot_errors(*args, backend: str = 'cv2', **kwargs):
Expand Down
3 changes: 2 additions & 1 deletion tests/data/demo_cocovid_data/create_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from collections import defaultdict

import mmcv
from mmdet.core.bbox.demodata import random_boxes

from mmtrack.testing import random_boxes


def create_dummy_data():
Expand Down
5 changes: 2 additions & 3 deletions tests/test_models/test_filter/test_filter_head.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch

from mmtrack.models import FilterInitializer


@pytest.mark.skipif(
not torch.cuda.is_available, reason='test case under gpu environment')
def test_filter_classifier_initializer():
if not torch.cuda.is_available():
return
classifier_initializer = FilterInitializer(
filter_size=4, feature_dim=8, feature_stride=16).to('cuda:0')
feats = torch.randn(4, 8, 22, 22, device='cuda:0')
Expand Down
4 changes: 4 additions & 0 deletions tests/test_models/test_mot/test_strong_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ def setUpClass(cls):
])
def test_init(self, cfg_file):
model = get_model_cfg(cfg_file)
model.reid.backbone.depth = 18
model.reid.head.fc_channels = 1
model.reid.head.out_channels = 1
model.reid.head.num_classes = 2
model = MODELS.build(model)
assert model.detector
assert model.reid
Expand Down
2 changes: 1 addition & 1 deletion tests/test_models/test_reid/test_base_reid.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def setUpClass(cls) -> None:
register_all_modules()

@parameterized.expand([
'reid/reid_resnet50_8x32bs-6e_mot17train80_test-mot17val20.py',
'reid/reid_r50_8xb32-6e_mot17train80_test-mot17val20.py',
])
def test_forward(self, cfg_file):
model_cfg = get_model_cfg(cfg_file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def setUpClass(cls):
target_means=[0., 0., 0., 0.],
target_stds=[0.2, 0.2, 0.2, 0.2]),
reg_class_agnostic=False,
reg_predictor_cfg=dict(type='mmdet.Linear'),
cls_predictor_cfg=dict(type='mmdet.Linear'),
loss_cls=dict(
type='mmdet.CrossEntropyLoss',
use_sigmoid=False,
Expand Down
10 changes: 5 additions & 5 deletions tests/test_models/test_sot/test_prdimp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright (c) OpenMMLab. All rights reserved.
from unittest import TestCase

import pytest
import torch
from parameterized import parameterized

Expand All @@ -17,7 +16,7 @@ class TestPrDiMP(TestCase):
def setUpClass(cls):
register_all_modules(init_default_scope=True)

@parameterized.expand(['sot/prdimp/prdimp_resnet50_8x10bs-50e_got10k.py'])
@parameterized.expand(['sot/prdimp/prdimp_r50_8xb10-50e_got10k.py'])
def test_init(self, cfg_file):
model = get_model_cfg(cfg_file)

Expand All @@ -26,10 +25,11 @@ def test_init(self, cfg_file):
assert model.classifier
assert model.bbox_regressor

@pytest.mark.skipif(
not torch.cuda.is_available, reason='test case under gpu environment')
@parameterized.expand(['sot/prdimp/prdimp_resnet50_8x10bs-50e_got10k.py'])
@parameterized.expand(['sot/prdimp/prdimp_r50_8xb10-50e_got10k.py'])
def test_stark_forward_predict_mode(self, cfg_file):
if not torch.cuda.is_available():
return

_model = get_model_cfg(cfg_file)
model = MODELS.build(_model)
model = model.cuda()
Expand Down
6 changes: 3 additions & 3 deletions tests/test_models/test_sot/test_siamrpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def setUpClass(cls):
register_all_modules(init_default_scope=True)

@parameterized.expand([
'sot/siamese_rpn/siamese-rpn_resnet50_8xb28-20e_imagenetvid-imagenetdet-coco_test-lasot.py', # noqa: E501
'sot/siamese_rpn/siamese-rpn_r50_8xb28-20e_imagenetvid-imagenetdet-coco_test-lasot.py', # noqa: E501
])
def test_init(self, cfg_file):
model = get_model_cfg(cfg_file)
Expand All @@ -30,7 +30,7 @@ def test_init(self, cfg_file):

@parameterized.expand([
(
'sot/siamese_rpn/siamese-rpn_resnet50_8xb28-20e_imagenetvid-imagenetdet-coco_test-lasot.py', # noqa: E501
'sot/siamese_rpn/siamese-rpn_r50_8xb28-20e_imagenetvid-imagenetdet-coco_test-lasot.py', # noqa: E501
('cpu', 'cuda')),
])
def test_siamese_rpn_forward_loss_mode(self, cfg_file, devices):
Expand Down Expand Up @@ -61,7 +61,7 @@ def test_siamese_rpn_forward_loss_mode(self, cfg_file, devices):

@parameterized.expand([
(
'sot/siamese_rpn/siamese-rpn_resnet50_8xb28-20e_imagenetvid-imagenetdet-coco_test-lasot.py', # noqa: E501
'sot/siamese_rpn/siamese-rpn_r50_8xb28-20e_imagenetvid-imagenetdet-coco_test-lasot.py', # noqa: E501
('cpu', 'cuda')),
])
def test_siamese_rpn_forward_predict_mode(self, cfg_file, devices):
Expand Down
Loading

0 comments on commit 067cc16

Please sign in to comment.