Hồ Chí Minh, 16-08-2023
Trần Nguyễn Chí Huy, Võ Duy Nguyên, UIT-Together Research Group
RTMDet
Mục Lục
Step 1. Cài đặt môi trường
Step 1.1. Tạo môi trường anaconda
Đặt tên theo cú pháp: Ten_viet tat cua ho va chu lot
VD: Tran Nguyen Chi Huy -> Huytnc
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Step 1.2. Kích hoạt môi trường vừa tạo
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Step 2. Cài đặt MMEngine và MMCV sử dụng MIM
Hình ảnh cài đặt thành công openmim
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Hình ảnh cài đặt thành công MMEngine
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Hình ảnh cài đặt thành công MMCV
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Step 3. Thao tác với MMDetection
Truy cập vào thư mục luutru
VD: /home/u2301/luutru/
Tạo thư mục tương ứng với tên môi trường bên trên
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Step 3.1. Cài đặt MMDetection
Tại thư mục này thực hiện clone và cài đặt mmdetection
Hình ảnh clone thành công
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Step 3.2. Tạo thư mục checkpoints và tải file config
Tạo thư mục checkpoints
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Tải checkpoints của file config rtmdet_tiny_8xb32-300e_coco
Hình ảnh tải thành công file config và checkpoints
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Verify the installation
Chọn GPU
Chọn GPU bằng lệnh:
Verify the inference demo
Kết quả được lưu trong thư mục outputs/vis
Vd: /home/u2301/luutru/Huytnc/mmdetection/outputs/vis/
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Tạo thư mục data trong thư mục mmdetection để chứa shortcut dẫn tới thư mục MS-COCO
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Sử dụng chung thư mục MS-COCO nên chúng ta sẽ tạo 1 shortcut dẫn tới thư mục MS-COCO dùng chung bằng lệnh:
ln -s /duong dan toi thu muc goc /duong dan toi thu muc luu shortcut
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Test với dữ liệu MS-COCO
Nhấn tổ hợp Ctrl+C để dừng visualized. Màn hình hiện như bên dưới thì dừng thành công:
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Train with customized dataset
Chuẩn bị dataset
Ở đây mình dùng dataset visDrone đã được cài đặt sẵn, nên chỉ cần tạo 1 shortcut dẫn tới thư mục visDrone dùng chung bằng lệnh:
Vì visDrone đã có COCO format nên không cần convert.
Prepare a config
Tạo 1 file tên Prepare_Config.py

với nội dung như bên dưới:
config_drone = """
# Inherit and overwrite part of the config based on this config
_base_ = './rtmdet_tiny_8xb32-300e_coco.py'
data_root = '/home/cvpr2023/LuuTru/dataset/VisDrone/cocoVisdrone/' # dataset root
train_batch_size_per_gpu = 4
train_num_workers = 2
max_epochs = 1 # so luong epoch can train
stage2_num_epochs = 1
base_lr = 0.00008
metainfo = {
'classes': ( 'pedestrian','people','bicycle','car','van','truck','tricycle','awning-tricycle','bus','motor'), # so classes cua dataset
'palette': [
(220, 20, 60),
(220, 0, 60),
(220, 20, 0),
(220, 20, 60),
(220, 20, 60),
(220, 20, 60),
(220, 0, 60),
(220, 20, 0),
(220, 20, 60),
(220, 20, 60),
]
}
train_dataloader = dict(
batch_size=train_batch_size_per_gpu,
num_workers=train_num_workers,
dataset=dict(
data_root=data_root,
metainfo=metainfo,
data_prefix=dict(img='train/'),
ann_file='annotations/train.json'))
val_dataloader = dict(
dataset=dict(
data_root=data_root,
metainfo=metainfo,
data_prefix=dict(img='val/'),
ann_file='annotations/val.json'))
test_dataloader = dict(
dataset=dict(
data_root=data_root,
metainfo=metainfo,
data_prefix=dict(img='test/'),
ann_file='annotations/test.json'))
val_evaluator = dict(ann_file=data_root + 'annotations/val.json')
test_evaluator = dict(ann_file=data_root + 'annotations/test.json')
model = dict(bbox_head=dict(num_classes=10)) # thay doi so classes phu hop
# learning rate
param_scheduler = [
dict(
type='LinearLR',
start_factor=1.0e-5,
by_epoch=False,
begin=0,
end=10),
dict(
# use cosine lr from 10 to 20 epoch
type='CosineAnnealingLR',
eta_min=base_lr * 0.05,
begin=max_epochs // 2,
end=max_epochs,
T_max=max_epochs // 2,
by_epoch=True,
convert_to_iter_based=True),
]
train_pipeline_stage2 = [
dict(type='LoadImageFromFile', backend_args=None),
dict(type='LoadAnnotations', with_bbox=True),
dict(
type='RandomResize',
scale=(640, 640),
ratio_range=(0.1, 2.0),
keep_ratio=True),
dict(type='RandomCrop', crop_size=(640, 640)),
dict(type='YOLOXHSVRandomAug'),
dict(type='RandomFlip', prob=0.5),
dict(type='Pad', size=(640, 640), pad_val=dict(img=(114, 114, 114))),
dict(type='PackDetInputs')
]
# optimizer
optim_wrapper = dict(
_delete_=True,
type='OptimWrapper',
optimizer=dict(type='AdamW', lr=base_lr, weight_decay=0.05),
paramwise_cfg=dict(
norm_decay_mult=0, bias_decay_mult=0, bypass_duplicate=True))
default_hooks = dict(
checkpoint=dict(
interval=5,
max_keep_ckpts=2, # only keep latest 2 checkpoints
save_best='auto'
),
logger=dict(type='LoggerHook', interval=5))
custom_hooks = [
dict(
type='PipelineSwitchHook',
switch_epoch=max_epochs - stage2_num_epochs,
switch_pipeline=train_pipeline_stage2)
]
# load COCO pre-trained weight
load_from = './checkpoints/rtmdet_tiny_8xb32-300e_coco_20220902_112414-78e30dcc.pth'
train_cfg = dict(type='EpochBasedTrainLoop', max_epochs=max_epochs, val_interval=1)
"""
with open('./configs/rtmdet/rtmdet_tiny_1xb4-1e_drone.py', 'w') as f:
f.write(config_drone)
Sau đó chạy lệnh:
Bắt đầu train với lệnh:
Sau khi train xong, chúng ta có thể tính toán điểm mAP từng class bằng cách chạy câu lệnh:
Bên dưới là điểm mAP từng class.

Tiếp theo sẽ đến với phần visualize kết quả.
Visualize kết quả sau khi train
Visualize nhiều ảnh:
Chạy câu lệnh:
Sau khi chạy, thư mục các ảnh kết quả sẽ nằm trong thư mục work_dirs.
Visualize 1 ảnh:
Tạo file Demo_Detec.py

với nội dung:
Chạy lệnh dưới để visualize:
Kết quả sau khi chạy sẽ được lưu trong thư mục outputs.

Tài liệu hướng dẫn dùng cho nhóm UIT-Together Research Group