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

TypeError: __init__() got an unexpected keyword argument 'img_prefix' #11958

Open
conmeobeoi opened this issue Sep 13, 2024 · 0 comments
Open
Assignees
Labels
reimplementation Issues in model reimplementation

Comments

@conmeobeoi
Copy link

conmeobeoi commented Sep 13, 2024

I train the model on my custom dataset
Here is my config file:

_base_ = [
    'Z:/300_Minh_Anh/train_rtmdet/mmdetection-3.x/configs/rtmdet/rtmdet_s_8xb32-300e_coco.py',
]

experiment_id = 'rtmdet_s_8xb32-300e_coco'

classes = ('NG',)  
num_classes = len(classes)
metainfo = {
    'classes': classes,
    'palette': [(190, 77, 37)]
}

model = dict(
    data_preprocessor=dict(
        type='DetDataPreprocessor',
        mean=[123.675, 102.466, 48.287],
        std=[31.949, 31.084, 20.839],
        bgr_to_rgb=False,
        batch_augments=None,
        pad_size_divisor=32), 
    bbox_head=dict(num_classes=num_classes)
)

image_scale = (512, 672)
batch_size = 4
n_workers = 2
n_gpu = 1
base_lr = 0.004
eta = base_lr * (batch_size * n_gpu / 16)**0.5
n_epochs = 300

albu_train_transforms = [
    dict(
        type='ShiftScaleRotate',
        shift_limit=(-0.0625, 0.0625),
        scale_limit=(0.0, 0.0),
        rotate_limit=(-3.0, 3.0),
        interpolation=1,  
        p=0.5),
    dict(
        type='OneOf',
        transforms=[
            dict(type='Blur', blur_limit=(3, 5), p=1.0),
            dict(type='MedianBlur', blur_limit=(3, 5), p=1.0)
        ],
        p=0.5),
    dict(
        type='RandomBrightnessContrast',
        brightness_limit=[0.0, 0.05],
        contrast_limit=[0.0, 0.05],
        p=0.5),
    dict(
        type='OneOf',
        transforms=[
        dict(
            type='HueSaturationValue',
            hue_shift_limit=2,
            sat_shift_limit=2,
            val_shift_limit=2,
            p=1.0),
        dict(
            type='RGBShift',
            r_shift_limit=(-2, 2),
            g_shift_limit=(-2, 2),
            b_shift_limit=(-2, 2),
            p=1.0),
        ],
        p=0.5),
    dict(type='JpegCompression', quality_lower=98, quality_upper=100, p=0.5),
]
packed_inputs_items = ('img_id', 'img_path', 'img_shape', 'scale_factor', 'ori_shape')
train_pipeline = [
    dict(type='LoadImageFromFile'),
    dict(type='LoadAnnotations', with_bbox=True, with_mask=False, with_seg=False),
    dict(type='Resize', scale=image_scale, keep_ratio=True),
    dict(
        type='Albu',
        transforms=albu_train_transforms,
        bbox_params=dict(
            type='BboxParams',
            format='pascal_voc',
            label_fields=['gt_bboxes_labels', 'gt_ignore_flags'],
            min_visibility=0.0,
            filter_lost_elements=True),
        keymap={
            'img': 'image',
            'gt_bboxes': 'bboxes'
        },
        skip_img_without_anno=True),
    dict(type='RandomFlip', prob=0.5, direction='horizontal'),
    dict(type='PackDetInputs', meta_keys=packed_inputs_items),
]
val_pipeline = [
    dict(type='LoadImageFromFile'),
    dict(type='LoadAnnotations', with_bbox=True, with_mask=False, with_seg=False),
    dict(type='Resize', scale=image_scale, keep_ratio=True),
    dict(type='PackDetInputs', meta_keys=packed_inputs_items),
]
test_pipeline = val_pipeline

dataset_type = 'CocoDataset'
data_root = r'Z://300_Minh_Anh/train_rtmdet/dataset/'  # Ensure this path is correct
backend_args = None

base_dataset_config = {
    "type": dataset_type,
    "metainfo": metainfo,
    "data_root": data_root,
    "ann_file": 'annotations/train_label.json', 
    "backend_args": backend_args
}

train_dataset = dict(
    **base_dataset_config,
    data_prefix=dict(img='train/', ann='annotations/'),
    filter_cfg=dict(filter_empty_gt=True, min_size=32),
    pipeline=train_pipeline
)

val_dataset = dict(
    **base_dataset_config,
    data_prefix=dict(img='dev/', ann='annotations/'), 
    test_mode=True,
    pipeline=val_pipeline
)

test_dataset = dict(
    **base_dataset_config,
    data_prefix=dict(img='test/', ann='annotations/'),  #

    test_mode=True,
    pipeline=test_pipeline
)


train_dataloader = dict(
    batch_size=batch_size,
    num_workers=2,
    persistent_workers=True,
    sampler=dict(type='DefaultSampler', shuffle=True),
    dataset=train_dataset
)

val_dataloader = dict(
    batch_size=1,
    num_workers=2,
    persistent_workers=True,
    drop_last=False,
    sampler=dict(type='DefaultSampler', shuffle=False),
    dataset=val_dataset
)

test_dataloader = dict(
    batch_size=1,
    num_workers=2,
    persistent_workers=True,
    drop_last=False,
    sampler=dict(type='DefaultSampler', shuffle=False),
    dataset=test_dataset
)

val_evaluator = dict(type='CocoMetric', metric=['bbox'], eval_mode='bbox')
test_evaluator = val_evaluator

optimizer = dict(type='AdamW', lr=eta, weight_decay=0.0001)
optim_wrapper = dict(type='OptimWrapper', optimizer=optimizer)

param_scheduler = [
    dict(
        type='LinearLR', start_factor=0.001, by_epoch=False, begin=0, end=1000),
    dict(
        type='MultiStepLR',
        begin=0,
        end=n_epochs,
        by_epoch=True,
        milestones=[270],
        gamma=0.1)
]

train_cfg = dict(
    type='EpochBasedTrainLoop', max_epochs=n_epochs, val_interval=1)
val_cfg = dict(type='ValLoop')
test_cfg = dict(type='TestLoop')

auto_scale_lr = dict(enable=False, base_batch_size=16)

default_hooks = dict(
    checkpoint=dict(type='CheckpointHook', interval=1, max_keep_ckpts=3),
    logger=dict(type='LoggerHook', interval=50))

vis_backends = [dict(type='LocalVisBackend'), 
                dict(type='TensorboardVisBackend')]
visualizer = dict(
    type='DetLocalVisualizer', vis_backends=vis_backends, name='visualizer')

log_processor = dict(type='LogProcessor', window_size=50, by_epoch=True)

work_dir = 'logs/' + experiment_id 

Here is my error:

Traceback (most recent call last):
  File "mmdetection-3.x/tools/train.py", line 133, in <module>
    main()
  File "mmdetection-3.x/tools/train.py", line 129, in main
    runner.train()
  File "C:\Users\dmvns00007\.conda\envs\openmmlab\lib\site-packages\mmengine\runner\runner.py", line 1728, in train
    self._train_loop = self.build_train_loop(
  File "C:\Users\dmvns00007\.conda\envs\openmmlab\lib\site-packages\mmengine\runner\runner.py", line 1520, in build_train_loop
    loop = LOOPS.build(
  File "C:\Users\dmvns00007\.conda\envs\openmmlab\lib\site-packages\mmengine\registry\registry.py", line 570, in build
    return self.build_func(cfg, *args, **kwargs, registry=self)
  File "C:\Users\dmvns00007\.conda\envs\openmmlab\lib\site-packages\mmengine\registry\build_functions.py", line 121, in build_from_cfg 
    obj = obj_cls(**args)  # type: ignore
  File "C:\Users\dmvns00007\.conda\envs\openmmlab\lib\site-packages\mmengine\runner\loops.py", line 44, in __init__
    super().__init__(runner, dataloader)
  File "C:\Users\dmvns00007\.conda\envs\openmmlab\lib\site-packages\mmengine\runner\base_loop.py", line 26, in __init__
    self.dataloader = runner.build_dataloader(
  File "C:\Users\dmvns00007\.conda\envs\openmmlab\lib\site-packages\mmengine\runner\runner.py", line 1370, in build_dataloader
    dataset = DATASETS.build(dataset_cfg)
  File "C:\Users\dmvns00007\.conda\envs\openmmlab\lib\site-packages\mmengine\registry\registry.py", line 570, in build
    return self.build_func(cfg, *args, **kwargs, registry=self)
  File "C:\Users\dmvns00007\.conda\envs\openmmlab\lib\site-packages\mmengine\registry\build_functions.py", line 121, in build_from_cfg 
    obj = obj_cls(**args)  # type: ignore
  File "c:\users\dmvns00007\mmdetection\mmdet\datasets\base_det_dataset.py", line 51, in __init__
    super().__init__(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'img_prefix'

Please help me to solve the problem. I am just a beginner. Thank you all

@conmeobeoi conmeobeoi added the reimplementation Issues in model reimplementation label Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
reimplementation Issues in model reimplementation
Projects
None yet
Development

No branches or pull requests

2 participants