open-mmlab / mmdeploy

OpenMMLab Model Deployment Framework
https://mmdeploy.readthedocs.io/en/latest/
Apache License 2.0
2.77k stars 636 forks source link

[Bug] KeyError: 'LoadImageFromNDArray is not in the transform registry #2197

Closed smrlehdgus closed 1 year ago

smrlehdgus commented 1 year ago

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

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/test/frame_001.jpeg \
--work-dir /home/model/YOLOX/deploy \
--device cuda:0

Test Inference with code below

import mmengine
import torch

from mmdeploy.utils import get_input_shape, load_config
from mmdeploy.apis.utils import build_task_processor
import mmcv

deploy_cfg = "/home/project/ObjectDetection/configs/deploy/detection_tensorrt_static-640x640.py"
model_cfg = "/home/project/ObjectDetection/configs/yolox/yolox_m_fast_8xb32-300e-rtmdet-hyp.py"
backend_files = ["/home/model/YOLOX/deploy/end2end.engine"]
device = "cuda:0"
img = "/home/data/ObjectDetection/test/frame_001.jpeg"
backend = None

img = mmcv.imread(img, channel_order="rgb")

deploy_cfg, model_cfg = load_config(deploy_cfg, model_cfg)

task_processor = build_task_processor(model_cfg, deploy_cfg, device)

model = task_processor.build_backend_model(
    backend_files, task_processor.update_data_preprocessor
)

input_shape = get_input_shape(deploy_cfg)
model_inputs, _ = task_processor.create_input(img, input_shape)

with torch.no_grad():
    result = model.test_step(model_inputs)

Environment

06/19 17:37:37 - mmengine - INFO - 

06/19 17:37:37 - mmengine - INFO - **********Environmental information**********
06/19 17:37:38 - mmengine - INFO - sys.platform: linux
06/19 17:37:38 - mmengine - INFO - Python: 3.8.10 (default, Jun 22 2022, 20:18:18) [GCC 9.4.0]
06/19 17:37:38 - mmengine - INFO - CUDA available: True
06/19 17:37:38 - mmengine - INFO - numpy_random_seed: 2147483648
06/19 17:37:38 - mmengine - INFO - GPU 0: NVIDIA GeForce RTX 4080
06/19 17:37:38 - mmengine - INFO - CUDA_HOME: /usr/local/cuda
06/19 17:37:38 - mmengine - INFO - NVCC: Cuda compilation tools, release 11.8, V11.8.89
06/19 17:37:38 - mmengine - INFO - GCC: x86_64-linux-gnu-gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
06/19 17:37:38 - mmengine - INFO - PyTorch: 1.13.0a0+936e930
06/19 17:37:38 - mmengine - INFO - PyTorch compiling details: PyTorch built with:
  - GCC 9.4
  - C++ Version: 201402
  - Intel(R) oneAPI Math Kernel Library Version 2021.1-Product Build 20201104 for Intel(R) 64 architecture applications
  - Intel(R) MKL-DNN v2.6.0 (Git Hash N/A)
  - OpenMP 201511 (a.k.a. OpenMP 4.5)
  - LAPACK is enabled (usually provided by MKL)
  - NNPACK is enabled
  - CPU capability usage: AVX2
  - CUDA Runtime 11.8
  - NVCC architecture flags: -gencode;arch=compute_52,code=sm_52;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_61,code=sm_61;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_80,code=sm_80;-gencode;arch=compute_86,code=sm_86;-gencode;arch=compute_90,code=sm_90;-gencode;arch=compute_90,code=compute_90
  - CuDNN 8.7
  - Magma 2.6.2
  - Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=11.8, CUDNN_VERSION=8.7.0, CXX_COMPILER=/usr/bin/c++, CXX_FLAGS=-fno-gnu-unique -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -fopenmp -DNDEBUG -DUSE_KINETO -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -DEDGE_PROFILER_USE_KINETO -O2 -fPIC -Wno-narrowing -Wall -Wextra -Werror=return-type -Werror=non-virtual-dtor -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wunused-local-typedefs -Wno-unused-parameter -Wno-unused-function -Wno-unused-result -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-psabi -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -Werror=cast-function-type -Wno-stringop-overflow, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_VERSION=1.13.0, USE_CUDA=ON, USE_CUDNN=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=ON, USE_NCCL=ON, USE_NNPACK=ON, USE_OPENMP=ON, USE_ROCM=OFF, 

06/19 17:37:38 - mmengine - INFO - TorchVision: 0.15.0a0
06/19 17:37:38 - mmengine - INFO - OpenCV: 4.7.0
06/19 17:37:38 - mmengine - INFO - MMEngine: 0.7.4
06/19 17:37:38 - mmengine - INFO - MMCV: 2.0.0
06/19 17:37:38 - mmengine - INFO - MMCV Compiler: GCC 9.4
06/19 17:37:38 - mmengine - INFO - MMCV CUDA Compiler: 11.8
06/19 17:37:38 - mmengine - INFO - MMDeploy: 1.1.0+90f17f2
06/19 17:37:38 - mmengine - INFO - 

06/19 17:37:38 - mmengine - INFO - **********Backend information**********
06/19 17:37:38 - mmengine - INFO - tensorrt:    8.5.1.7
06/19 17:37:38 - mmengine - INFO - tensorrt custom ops: Available
06/19 17:37:38 - mmengine - INFO - ONNXRuntime: 1.8.1
06/19 17:37:38 - mmengine - INFO - ONNXRuntime-gpu:     1.8.1
06/19 17:37:38 - mmengine - INFO - ONNXRuntime custom ops:      Available
06/19 17:37:38 - mmengine - INFO - pplnn:       None
06/19 17:37:38 - mmengine - INFO - ncnn:        None
06/19 17:37:38 - mmengine - INFO - snpe:        None
06/19 17:37:38 - mmengine - INFO - openvino:    None
06/19 17:37:38 - mmengine - INFO - torchscript: 1.13.0a0+936e930
06/19 17:37:38 - mmengine - INFO - torchscript custom ops:      NotAvailable
06/19 17:37:38 - mmengine - INFO - rknn-toolkit:        None
06/19 17:37:38 - mmengine - INFO - rknn-toolkit2:       None
06/19 17:37:38 - mmengine - INFO - ascend:      None
06/19 17:37:38 - mmengine - INFO - coreml:      None
06/19 17:37:38 - mmengine - INFO - tvm: None
06/19 17:37:38 - mmengine - INFO - vacc:        None
06/19 17:37:38 - mmengine - INFO - 

06/19 17:37:38 - mmengine - INFO - **********Codebase information**********
06/19 17:37:38 - mmengine - INFO - mmdet:       3.0.0rc6
06/19 17:37:38 - mmengine - INFO - mmseg:       None
06/19 17:37:38 - mmengine - INFO - mmpretrain:  None
06/19 17:37:38 - mmengine - INFO - mmocr:       1.0.0
06/19 17:37:38 - mmengine - INFO - mmagic:      None
06/19 17:37:38 - mmengine - INFO - mmdet3d:     None
06/19 17:37:38 - mmengine - INFO - mmpose:      None
06/19 17:37:38 - mmengine - INFO - mmrotate:    None
06/19 17:37:38 - mmengine - INFO - mmaction:    None
06/19 17:37:38 - mmengine - INFO - mmrazor:     None

Error traceback

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'
RunningLeon commented 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)
smrlehdgus commented 1 year ago

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)])
RunningLeon commented 1 year ago

you are using model config from mmyolo style.

  1. you have to add scope for classes from mmdet in the model config, eg. mmdet.SyncNormHook.
  2. you could refer to this doc to deploy models from mmyolo
smrlehdgus commented 1 year ago

dict(type='LoadImageFromFile', file_client_args=dict(backend='disk')),

  1. How can I add scope for classes from mmdet?
  2. I created tensorrt engine file using command below like the doc
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
RunningLeon commented 1 year ago
  1. for instance you want to use visualizer 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')
  2. pls. use deploy config from mmyolo
  3. should you use LoadImageFromFile instead of LoadImageFromNDArray?
smrlehdgus commented 1 year ago
  1. I used mmyolo's easydeploy to deploy the model, but returned the result that the onnx/tensorRT model was not accurate. Bug report to mmdeploy.
  2. LoadImageFromFile works well. but for Webcam or RTSP inference I need to use LoadImageFromNDArray.
github-actions[bot] commented 1 year ago

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.

github-actions[bot] commented 1 year ago

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.