Closed smrlehdgus closed 1 year ago
@smrlehdgus hi, are you using the model config from mmdet or mmyolo? Could you post your model config here by running
import mmengine
model_cfg = mmengine.Config.fromfile("/home/project/ObjectDetection/configs/yolox/yolox_m_fast_8xb32-300e-rtmdet-hyp.py")
print(model_cfg.pretty_text)
import mmengine model_cfg = mmengine.Config.fromfile("/home/project/ObjectDetection/configs/yolox/yolox_m_fast_8xb32-300e-rtmdet-hyp.py") print(model_cfg.pretty_text)
paths could be different I hid and fix personal info from paths
default_scope = 'mmyolo'
default_hooks = dict(
timer=dict(type='IterTimerHook'),
logger=dict(type='LoggerHook', interval=5),
param_scheduler=dict(type='ParamSchedulerHook'),
checkpoint=dict(
type='CheckpointHook', interval=10, max_keep_ckpts=2,
save_best='auto'),
sampler_seed=dict(type='DistSamplerSeedHook'),
visualization=dict(type='mmdet.DetVisualizationHook'))
env_cfg = dict(
cudnn_benchmark=False,
mp_cfg=dict(mp_start_method='fork', opencv_num_threads=0),
dist_cfg=dict(backend='nccl'))
vis_backends = [dict(type='LocalVisBackend')]
visualizer = dict(
type='mmdet.DetLocalVisualizer',
vis_backends=[dict(type='LocalVisBackend')],
name='visualizer')
log_processor = dict(type='LogProcessor', window_size=50, by_epoch=True)
log_level = 'INFO'
load_from = 'https://download.openmmlab.com/mmyolo/v0/yolox/yolox_s_fast_8xb32-300e-rtmdet-hyp_coco/yolox_s_fast_8xb32-300e-rtmdet-hyp_coco_20230210_134645-3a8dfbd7.pth'
resume = False
file_client_args = dict(backend='disk')
_file_client_args = dict(backend='disk')
tta_model = dict(
type='mmdet.DetTTAModel',
tta_cfg=dict(nms=dict(type='nms', iou_threshold=0.65), max_per_img=300))
img_scales = [(640, 640), (320, 320), (960, 960)]
tta_pipeline = [
dict(type='LoadImageFromFile', file_client_args=dict(backend='disk')),
dict(
type='TestTimeAug',
transforms=[[{
'type': 'mmdet.Resize',
'scale': (640, 640),
'keep_ratio': True
}, {
'type': 'mmdet.Resize',
'scale': (320, 320),
'keep_ratio': True
}, {
'type': 'mmdet.Resize',
'scale': (960, 960),
'keep_ratio': True
}],
[{
'type': 'mmdet.RandomFlip',
'prob': 1.0
}, {
'type': 'mmdet.RandomFlip',
'prob': 0.0
}],
[{
'type': 'mmdet.Pad',
'pad_to_square': True,
'pad_val': {
'img': (114.0, 114.0, 114.0)
}
}],
[{
'type':
'mmdet.PackDetInputs',
'meta_keys':
('img_id', 'img_path', 'ori_shape', 'img_shape',
'scale_factor', 'flip', 'flip_direction')
}]])
]
data_root = '/home/data/ObjectDetection/****/20221017/'
train_ann_file = 'train.json'
train_data_prefix = 'images/train/'
val_ann_file = 'val.json'
val_data_prefix = 'images/train/'
num_classes = 4
train_batch_size_per_gpu = 8
train_num_workers = 4
persistent_workers = True
base_lr = 0.004
max_epochs = 100
model_test_cfg = dict(
yolox_style=True,
multi_label=True,
score_thr=0.001,
max_per_img=300,
nms=dict(type='nms', iou_threshold=0.65))
img_scale = (640, 640)
dataset_type = 'YOLOv5CocoDataset'
val_batch_size_per_gpu = 16
val_num_workers = 4
deepen_factor = 0.67
widen_factor = 0.75
norm_cfg = dict(type='BN', momentum=0.03, eps=0.001)
batch_augments_interval = 1
weight_decay = 0.0005
loss_cls_weight = 1.0
loss_bbox_weight = 5.0
loss_obj_weight = 1.0
loss_bbox_aux_weight = 1.0
center_radius = 2.5
num_last_epochs = 5
random_affine_scaling_ratio_range = (0.1, 2)
mixup_ratio_range = (0.8, 1.6)
save_epoch_intervals = 10
max_keep_ckpts = 3
ema_momentum = 0.0002
model = dict(
type='YOLODetector',
init_cfg=dict(
type='Kaiming',
layer='Conv2d',
a=2.23606797749979,
distribution='uniform',
mode='fan_in',
nonlinearity='leaky_relu'),
use_syncbn=False,
data_preprocessor=dict(
type='YOLOv5DetDataPreprocessor',
pad_size_divisor=32,
batch_augments=[
dict(
type='YOLOXBatchSyncRandomResize',
random_size_range=(480, 800),
size_divisor=32,
interval=1)
]),
backbone=dict(
type='YOLOXCSPDarknet',
deepen_factor=0.67,
widen_factor=0.75,
out_indices=(2, 3, 4),
spp_kernal_sizes=(5, 9, 13),
norm_cfg=dict(type='BN', momentum=0.03, eps=0.001),
act_cfg=dict(type='SiLU', inplace=True)),
neck=dict(
type='YOLOXPAFPN',
deepen_factor=0.67,
widen_factor=0.75,
in_channels=[256, 512, 1024],
out_channels=256,
norm_cfg=dict(type='BN', momentum=0.03, eps=0.001),
act_cfg=dict(type='SiLU', inplace=True)),
bbox_head=dict(
type='YOLOXHead',
head_module=dict(
type='YOLOXHeadModule',
num_classes=4,
in_channels=256,
feat_channels=256,
widen_factor=0.75,
stacked_convs=2,
featmap_strides=(8, 16, 32),
use_depthwise=False,
norm_cfg=dict(type='BN', momentum=0.03, eps=0.001),
act_cfg=dict(type='SiLU', inplace=True)),
loss_cls=dict(
type='mmdet.CrossEntropyLoss',
use_sigmoid=True,
reduction='sum',
loss_weight=1.0),
loss_bbox=dict(
type='mmdet.IoULoss',
mode='square',
eps=1e-16,
reduction='sum',
loss_weight=5.0),
loss_obj=dict(
type='mmdet.CrossEntropyLoss',
use_sigmoid=True,
reduction='sum',
loss_weight=1.0),
loss_bbox_aux=dict(
type='mmdet.L1Loss', reduction='sum', loss_weight=1.0)),
train_cfg=dict(
assigner=dict(
type='mmdet.SimOTAAssigner',
center_radius=2.5,
iou_calculator=dict(type='mmdet.BboxOverlaps2D'))),
test_cfg=dict(
yolox_style=True,
multi_label=True,
score_thr=0.001,
max_per_img=300,
nms=dict(type='nms', iou_threshold=0.65)))
pre_transform = [
dict(type='LoadImageFromFile', file_client_args=dict(backend='disk')),
dict(type='LoadAnnotations', with_bbox=True)
]
train_pipeline_stage1 = [
dict(type='LoadImageFromFile', file_client_args=dict(backend='disk')),
dict(type='LoadAnnotations', with_bbox=True),
dict(
type='Mosaic',
img_scale=(640, 640),
pad_val=114.0,
pre_transform=[
dict(
type='LoadImageFromFile',
file_client_args=dict(backend='disk')),
dict(type='LoadAnnotations', with_bbox=True)
]),
dict(
type='mmdet.RandomAffine',
scaling_ratio_range=(0.1, 2),
border=(-320, -320)),
dict(
type='YOLOXMixUp',
img_scale=(640, 640),
ratio_range=(0.8, 1.6),
pad_val=114.0,
pre_transform=[
dict(
type='LoadImageFromFile',
file_client_args=dict(backend='disk')),
dict(type='LoadAnnotations', with_bbox=True)
]),
dict(type='mmdet.YOLOXHSVRandomAug'),
dict(type='mmdet.RandomFlip', prob=0.5),
dict(
type='mmdet.FilterAnnotations',
min_gt_bbox_wh=(1, 1),
keep_empty=False),
dict(
type='mmdet.PackDetInputs',
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape', 'flip',
'flip_direction'))
]
train_pipeline_stage2 = [
dict(type='LoadImageFromFile', file_client_args=dict(backend='disk')),
dict(type='LoadAnnotations', with_bbox=True),
dict(type='mmdet.Resize', scale=(640, 640), keep_ratio=True),
dict(
type='mmdet.Pad',
pad_to_square=True,
pad_val=dict(img=(114.0, 114.0, 114.0))),
dict(type='mmdet.YOLOXHSVRandomAug'),
dict(type='mmdet.RandomFlip', prob=0.5),
dict(
type='mmdet.FilterAnnotations',
min_gt_bbox_wh=(1, 1),
keep_empty=False),
dict(type='mmdet.PackDetInputs')
]
train_dataloader = dict(
batch_size=8,
num_workers=4,
persistent_workers=True,
pin_memory=True,
collate_fn=dict(type='yolov5_collate'),
sampler=dict(type='DefaultSampler', shuffle=True),
dataset=dict(
type='YOLOv5CocoDataset',
data_root='/home/data/ObjectDetection/****/20221017/',
ann_file='train.json',
data_prefix=dict(img='images/train/'),
filter_cfg=dict(filter_empty_gt=False, min_size=32),
pipeline=[
dict(
type='LoadImageFromFile',
file_client_args=dict(backend='disk')),
dict(type='LoadAnnotations', with_bbox=True),
dict(
type='Mosaic',
img_scale=(640, 640),
pad_val=114.0,
pre_transform=[
dict(
type='LoadImageFromFile',
file_client_args=dict(backend='disk')),
dict(type='LoadAnnotations', with_bbox=True)
]),
dict(
type='mmdet.RandomAffine',
scaling_ratio_range=(0.1, 2),
border=(-320, -320)),
dict(
type='YOLOXMixUp',
img_scale=(640, 640),
ratio_range=(0.8, 1.6),
pad_val=114.0,
pre_transform=[
dict(
type='LoadImageFromFile',
file_client_args=dict(backend='disk')),
dict(type='LoadAnnotations', with_bbox=True)
]),
dict(type='mmdet.YOLOXHSVRandomAug'),
dict(type='mmdet.RandomFlip', prob=0.5),
dict(
type='mmdet.FilterAnnotations',
min_gt_bbox_wh=(1, 1),
keep_empty=False),
dict(
type='mmdet.PackDetInputs',
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
'flip', 'flip_direction'))
],
metainfo=dict(
classes=('stain', 'scratch', 'dent', 'deformation'),
palette=[(8, 187, 145), (35, 13, 245), (213, 65, 95),
(220, 222, 250)])))
test_pipeline = [
dict(type='LoadImageFromFile', file_client_args=dict(backend='disk')),
dict(type='mmdet.Resize', scale=(640, 640), keep_ratio=True),
dict(
type='mmdet.Pad',
pad_to_square=True,
pad_val=dict(img=(114.0, 114.0, 114.0))),
dict(type='LoadAnnotations', with_bbox=True, _scope_='mmdet'),
dict(
type='mmdet.PackDetInputs',
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
'scale_factor'))
]
val_dataloader = dict(
batch_size=16,
num_workers=4,
persistent_workers=True,
pin_memory=True,
drop_last=False,
sampler=dict(type='DefaultSampler', shuffle=False),
dataset=dict(
type='YOLOv5CocoDataset',
data_root='/home/data/ObjectDetection/****/20221017/',
ann_file='val.json',
data_prefix=dict(img='images/train/'),
test_mode=True,
pipeline=[
dict(
type='LoadImageFromFile',
file_client_args=dict(backend='disk')),
dict(type='mmdet.Resize', scale=(640, 640), keep_ratio=True),
dict(
type='mmdet.Pad',
pad_to_square=True,
pad_val=dict(img=(114.0, 114.0, 114.0))),
dict(type='LoadAnnotations', with_bbox=True, _scope_='mmdet'),
dict(
type='mmdet.PackDetInputs',
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
'scale_factor'))
],
metainfo=dict(
classes=('stain', 'scratch', 'dent', 'deformation'),
palette=[(8, 187, 145), (35, 13, 245), (213, 65, 95),
(220, 222, 250)])))
test_dataloader = dict(
batch_size=16,
num_workers=4,
persistent_workers=True,
pin_memory=True,
drop_last=False,
sampler=dict(type='DefaultSampler', shuffle=False),
dataset=dict(
type='YOLOv5CocoDataset',
data_root='/home/data/ObjectDetection/****/20221017/',
ann_file='test.json',
data_prefix=dict(img='images/train/'),
test_mode=True,
pipeline=[
dict(
type='LoadImageFromFile',
file_client_args=dict(backend='disk')),
dict(type='mmdet.Resize', scale=(640, 640), keep_ratio=True),
dict(
type='mmdet.Pad',
pad_to_square=True,
pad_val=dict(img=(114.0, 114.0, 114.0))),
dict(type='LoadAnnotations', with_bbox=True, _scope_='mmdet'),
dict(
type='mmdet.PackDetInputs',
meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
'scale_factor'))
],
metainfo=dict(
classes=('stain', 'scratch', 'dent', 'deformation'),
palette=[(8, 187, 145), (35, 13, 245), (213, 65, 95),
(220, 222, 250)])))
val_evaluator = dict(
type='mmdet.CocoMetric',
proposal_nums=(100, 1, 10),
ann_file='/home/data/ObjectDetection/****/20221017/val.json',
metric='bbox')
test_evaluator = dict(
type='mmdet.CocoMetric',
proposal_nums=(100, 1, 10),
ann_file='/home/data/ObjectDetection/****/20221017/test.json',
metric='bbox')
optim_wrapper = dict(
type='OptimWrapper',
optimizer=dict(type='AdamW', lr=0.004, weight_decay=0.05),
paramwise_cfg=dict(
norm_decay_mult=0, bias_decay_mult=0, bypass_duplicate=True))
param_scheduler = [
dict(
type='mmdet.QuadraticWarmupLR',
by_epoch=True,
begin=0,
end=3,
convert_to_iter_based=True),
dict(
type='CosineAnnealingLR',
eta_min=0.0002,
begin=5,
T_max=95,
end=95,
by_epoch=True,
convert_to_iter_based=True),
dict(type='ConstantLR', by_epoch=True, factor=1, begin=95, end=100)
]
custom_hooks = [
dict(
type='YOLOXModeSwitchHook',
num_last_epochs=5,
new_train_pipeline=[
dict(
type='LoadImageFromFile',
file_client_args=dict(backend='disk')),
dict(type='LoadAnnotations', with_bbox=True),
dict(type='mmdet.Resize', scale=(640, 640), keep_ratio=True),
dict(
type='mmdet.Pad',
pad_to_square=True,
pad_val=dict(img=(114.0, 114.0, 114.0))),
dict(type='mmdet.YOLOXHSVRandomAug'),
dict(type='mmdet.RandomFlip', prob=0.5),
dict(
type='mmdet.FilterAnnotations',
min_gt_bbox_wh=(1, 1),
keep_empty=False),
dict(type='mmdet.PackDetInputs')
],
priority=48),
dict(type='mmdet.SyncNormHook', priority=48),
dict(
type='EMAHook',
ema_type='ExpMomentumEMA',
momentum=0.0002,
update_buffers=True,
strict_load=False,
priority=49)
]
train_cfg = dict(
type='EpochBasedTrainLoop',
max_epochs=100,
val_interval=10,
dynamic_intervals=[(280, 1)])
auto_scale_lr = dict(base_batch_size=256)
val_cfg = dict(type='ValLoop')
test_cfg = dict(type='TestLoop')
test_ann_file = 'test.json'
test_data_prefix = 'images/train/'
class_name = ('stain', 'scratch', 'dent', 'deformation')
palette = [(8, 187, 145), (35, 13, 245), (213, 65, 95), (220, 222, 250)]
metainfo = dict(
classes=('stain', 'scratch', 'dent', 'deformation'),
palette=[(8, 187, 145), (35, 13, 245), (213, 65, 95), (220, 222, 250)])
you are using model config from mmyolo style.
mmdet.SyncNormHook
. dict(type='LoadImageFromFile', file_client_args=dict(backend='disk')),
python ./tools/deploy.py \
/home/project/ObjectDetection/configs/deploy/detection_tensorrt_static-640x640.py \
/home/project/ObjectDetection/configs/yolox/yolox_m_fast_8xb32-300e-rtmdet-hyp_****.py \
/home/model/YOLOX/best_coco_bbox_mAP_epoch_50.pth \
/home/data/ObjectDetection/****/20221017/images/train/frame_0019_8.jpeg \
--work-dir /home/model/YOLOX/deploy \
--device cuda:0
my config file is almost same as "cat" example config file. just fixed classes and paths
_base_ = './yolox_s_fast_8xb32-300e-rtmdet-hyp_coco.py'
data_root = './data/cat/'
class_name = ('cat', )
num_classes = len(class_name)
metainfo = dict(classes=class_name, palette=[(20, 220, 60)])
num_last_epochs = 5
max_epochs = 40
train_batch_size_per_gpu = 12
train_num_workers = 4
load_from = 'https://download.openmmlab.com/mmyolo/v0/yolox/yolox_s_fast_8xb32-300e-rtmdet-hyp_coco/yolox_s_fast_8xb32-300e-rtmdet-hyp_coco_20230210_134645-3a8dfbd7.pth' # noqa
model = dict(
backbone=dict(frozen_stages=4),
bbox_head=dict(head_module=dict(num_classes=num_classes)))
train_dataloader = dict(
batch_size=train_batch_size_per_gpu,
num_workers=train_num_workers,
dataset=dict(
data_root=data_root,
metainfo=metainfo,
ann_file='annotations/trainval.json',
data_prefix=dict(img='images/')))
val_dataloader = dict(
dataset=dict(
metainfo=metainfo,
data_root=data_root,
ann_file='annotations/test.json',
data_prefix=dict(img='images/')))
test_dataloader = val_dataloader
param_scheduler = [
dict(
# use quadratic formula to warm up 3 epochs
# and lr is updated by iteration
# TODO: fix default scope in get function
type='mmdet.QuadraticWarmupLR',
by_epoch=True,
begin=0,
end=3,
convert_to_iter_based=True),
dict(
# use cosine lr from 5 to 35 epoch
type='CosineAnnealingLR',
eta_min=_base_.base_lr * 0.05,
begin=5,
T_max=max_epochs - num_last_epochs,
end=max_epochs - num_last_epochs,
by_epoch=True,
convert_to_iter_based=True),
dict(
# use fixed lr during last num_last_epochs epochs
type='ConstantLR',
by_epoch=True,
factor=1,
begin=max_epochs - num_last_epochs,
end=max_epochs,
)
]
_base_.custom_hooks[0].num_last_epochs = num_last_epochs
val_evaluator = dict(ann_file=data_root + 'annotations/test.json')
test_evaluator = val_evaluator
default_hooks = dict(
checkpoint=dict(interval=10, max_keep_ckpts=2, save_best='auto'),
logger=dict(type='LoggerHook', interval=5))
train_cfg = dict(max_epochs=max_epochs, val_interval=10)
# visualizer = dict(vis_backends = [dict(type='LocalVisBackend'), dict(type='WandbVisBackend')]) # noqa
DetLocalVisualizer
from mmdet, you could add prefix mmdet.
in the config as mmdet.DetLocalVisualizer
.
visualizer = dict(
type='mmdet.DetLocalVisualizer',
vis_backends=vis_backends,
name='visualizer')
LoadImageFromFile
instead of LoadImageFromNDArray
?LoadImageFromFile
works well. but for Webcam or RTSP inference I need to use LoadImageFromNDArray
.This issue is marked as stale because it has been marked as invalid or awaiting response for 7 days without any further response. It will be closed in 5 days if the stale label is not removed or if there is no further response.
This issue is closed because it has been stale for 5 days. Please open a new issue if you have similar issues or you have any new updates now.
Checklist
Describe the bug
KeyError: 'LoadImageFromNDArray is not in the transform registry. Please check whether the value of
LoadImageFromNDArray
is correct or it was registered as expected. More details can be found at https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#import-the-custom-module'Reproduction
Created TRT engine with command below
Test Inference with code below
Environment
Error traceback