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

[Fix] Fix CI error due to np.int and legacy builder.py #389

Merged
merged 5 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .circleci/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ jobs:
name: Install mmyolo dependencies
command: |
pip install -U openmim
mim install 'mmengine >= 0.3.1'
mim install git+https://github.com/open-mmlab/mmengine.git@main
mim install 'mmcv >= 2.0.0rc1'
pip install git+https://github.com/open-mmlab/[email protected]
mim install git+https://github.com/open-mmlab/[email protected]
pip install -r requirements/albu.txt
pip install -r requirements/tests.txt
- run:
Expand Down
4 changes: 2 additions & 2 deletions docs/en/algorithm_descriptions/yolov5_description.md
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ At the same time, the batch shape of the current batch is calculated to prevent

n = len(image_shapes) # number of images
batch_index = np.floor(np.arange(n) / self.batch_size).astype(
np.int) # batch index
np.int64) # batch index
number_of_batches = batch_index[-1] + 1 # number of batches

aspect_ratio = image_shapes[:, 1] / image_shapes[:, 0] # aspect ratio
Expand All @@ -640,7 +640,7 @@ At the same time, the batch shape of the current batch is calculated to prevent

batch_shapes = np.ceil(
np.array(shapes) * self.img_size / self.size_divisor +
self.pad).astype(np.int) * self.size_divisor
self.pad).astype(np.int64) * self.size_divisor

for i, data_info in enumerate(data_list):
data_info['batch_shape'] = batch_shapes[batch_index[i]]
Expand Down
4 changes: 2 additions & 2 deletions docs/zh_cn/algorithm_descriptions/yolov5_description.md
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ YOLOv5 是非解耦输出头,而其他大部分算法都是解耦输出头,

n = len(image_shapes) # number of images
batch_index = np.floor(np.arange(n) / self.batch_size).astype(
np.int) # batch index
np.int64) # batch index
number_of_batches = batch_index[-1] + 1 # number of batches

aspect_ratio = image_shapes[:, 1] / image_shapes[:, 0] # aspect ratio
Expand All @@ -641,7 +641,7 @@ YOLOv5 是非解耦输出头,而其他大部分算法都是解耦输出头,

batch_shapes = np.ceil(
np.array(shapes) * self.img_size / self.size_divisor +
self.pad).astype(np.int) * self.size_divisor
self.pad).astype(np.int64) * self.size_divisor

for i, data_info in enumerate(data_list):
data_info['batch_shape'] = batch_shapes[batch_index[i]]
Expand Down
4 changes: 2 additions & 2 deletions mmyolo/datasets/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __call__(self, data_list: List[dict]) -> List[dict]:

n = len(image_shapes) # number of images
batch_index = np.floor(np.arange(n) / self.batch_size).astype(
np.int) # batch index
np.int64) # batch index
number_of_batches = batch_index[-1] + 1 # number of batches

aspect_ratio = image_shapes[:, 1] / image_shapes[:, 0] # aspect ratio
Expand All @@ -86,7 +86,7 @@ def __call__(self, data_list: List[dict]) -> List[dict]:

batch_shapes = np.ceil(
np.array(shapes) * self.img_size / self.size_divisor +
self.extra_pad_ratio).astype(np.int) * self.size_divisor
self.extra_pad_ratio).astype(np.int64) * self.size_divisor

for i, data_info in enumerate(data_list):
data_info['batch_shape'] = batch_shapes[batch_index[i]]
Expand Down
5 changes: 3 additions & 2 deletions mmyolo/utils/boxam_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
import torchvision
from mmcv.transforms import Compose
from mmdet.evaluation import get_classes
from mmdet.models import build_detector
from mmdet.utils import ConfigType
from mmengine.config import Config
from mmengine.runner import load_checkpoint
from mmengine.structures import InstanceData
from torch import Tensor

from mmyolo.registry import MODELS

try:
from pytorch_grad_cam import (AblationCAM, AblationLayer,
ActivationsAndGradients)
Expand Down Expand Up @@ -71,7 +72,7 @@ def init_detector(
# grad based method requires train_cfg
# config.model.train_cfg = None

model = build_detector(config.model)
model = MODELS.build(config.model)
if checkpoint is not None:
checkpoint = load_checkpoint(model, checkpoint, map_location='cpu')
# Weights converted from elsewhere may not have meta fields.
Expand Down
16 changes: 8 additions & 8 deletions tests/test_models/test_detectors/test_yolo_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def test_init(self, cfg_file):
model = get_detector_cfg(cfg_file)
model.backbone.init_cfg = None

from mmdet.models import build_detector
detector = build_detector(model)
from mmyolo.registry import MODELS
detector = MODELS.build(model)
self.assertTrue(detector.backbone)
self.assertTrue(detector.neck)
self.assertTrue(detector.bbox_head)
Expand All @@ -56,11 +56,11 @@ def test_forward_loss_mode(self, cfg_file, devices):
std=[255., 255., 255.],
bgr_to_rgb=True)

from mmdet.models import build_detector
from mmyolo.registry import MODELS
assert all([device in ['cpu', 'cuda'] for device in devices])

for device in devices:
detector = build_detector(model)
detector = MODELS.build(model)
detector.init_weights()

if device == 'cuda':
Expand All @@ -85,11 +85,11 @@ def test_forward_predict_mode(self, cfg_file, devices):
model = get_detector_cfg(cfg_file)
model.backbone.init_cfg = None

from mmdet.models import build_detector
from mmyolo.registry import MODELS
assert all([device in ['cpu', 'cuda'] for device in devices])

for device in devices:
detector = build_detector(model)
detector = MODELS.build(model)

if device == 'cuda':
if not torch.cuda.is_available():
Expand Down Expand Up @@ -117,11 +117,11 @@ def test_forward_tensor_mode(self, cfg_file, devices):
model = get_detector_cfg(cfg_file)
model.backbone.init_cfg = None

from mmdet.models import build_detector
from mmyolo.registry import MODELS
assert all([device in ['cpu', 'cuda'] for device in devices])

for device in devices:
detector = build_detector(model)
detector = MODELS.build(model)

if device == 'cuda':
if not torch.cuda.is_available():
Expand Down
4 changes: 2 additions & 2 deletions tools/analysis_tools/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import time

import torch
from mmdet.models import build_detector
from mmengine import Config, DictAction
from mmengine.dist import get_world_size, init_dist
from mmengine.logging import MMLogger, print_log
from mmengine.runner import Runner, load_checkpoint
from mmengine.utils import mkdir_or_exist
from mmengine.utils.dl_utils import set_multi_processing

from mmyolo.registry import MODELS
from mmyolo.utils import register_all_modules

register_all_modules()
Expand Down Expand Up @@ -82,7 +82,7 @@ def measure_inference_speed(cfg, checkpoint, max_iter, log_interval,
data_loader = Runner.build_dataloader(dataloader_cfg)

# build the model and load checkpoint
model = build_detector(cfg.model)
model = MODELS.build(cfg.model)
load_checkpoint(model, checkpoint, map_location='cpu')
model = model.cuda()
model.eval()
Expand Down