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

Support YOLOv8 Ins Segmentation Inference #895

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
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
59 changes: 59 additions & 0 deletions configs/yolov8/ins_seg/yolov8_ins_s_syncbn_fast_8xb16-500e_coco.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
_base_ = '../yolov8_s_mask-refine_syncbn_fast_8xb16-500e_coco.py'

# Batch size of a single GPU during validation
val_batch_size_per_gpu = 16
# Worker to pre-fetch data for each single GPU during validation
val_num_workers = 8

batch_shapes_cfg = dict(
_delete_=True,
type='BatchShapePolicy',
batch_size=val_batch_size_per_gpu,
img_size=_base_.img_scale[0],
# The image scale of padding should be divided by pad_size_divisor
size_divisor=32,
# Additional paddings for pixel scale
extra_pad_ratio=0.5)

# Testing take a long time due to model_test_cfg.
# If you want to speed it up, you can increase score_thr
# or decraese nms_pre and max_per_img
model_test_cfg = dict(
multi_label=True,
nms_pre=30000,
min_bbox_size=0,
score_thr=0.001,
nms=dict(type='nms', iou_threshold=0.7),
max_per_img=300,
mask_thr_binary=0.5,
# fast_test: Whether to use fast test methods. When set
# to False, the implementation here is the same as the
# official, with higher mAP. If set to True, mask will first
# be upsampled to origin image shape through Pytorch, and
# then use mask_thr_binary to determine which pixels belong
# to the object. If set to False, will first use
# mask_thr_binary to determine which pixels belong to the
# object , and then use opencv to upsample mask to origin
# image shape. Default to False.
fast_test=False)

# ===============================Unmodified in most cases====================
model = dict(
bbox_head=dict(
type='YOLOv8InsHead',
head_module=dict(
type='YOLOv8InsHeadModule', masks_channels=32,
protos_channels=256)),
test_cfg=model_test_cfg)

val_dataloader = dict(
batch_size=val_batch_size_per_gpu,
num_workers=val_num_workers,
dataset=dict(batch_shapes_cfg=batch_shapes_cfg))
test_dataloader = val_dataloader

val_evaluator = dict(metric=['bbox', 'segm'])
test_evaluator = val_evaluator

val_cfg = dict(type='ValLoop')
test_cfg = dict(type='TestLoop')
2 changes: 1 addition & 1 deletion mmyolo/datasets/transforms/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def _resize_img(self, results: dict):
results['pad_param_origin'] = results['pad_param'] * \
np.repeat(ratio, 2)

if self.half_pad_param:
if self.half_pad_param or 'gt_masks' in results:
results['pad_param'] = np.array(
[padding_h / 2, padding_h / 2, padding_w / 2, padding_w / 2],
dtype=np.float32)
Expand Down
4 changes: 3 additions & 1 deletion mmyolo/models/dense_heads/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .yolov6_head import YOLOv6Head, YOLOv6HeadModule
from .yolov7_head import YOLOv7Head, YOLOv7HeadModule, YOLOv7p6HeadModule
from .yolov8_head import YOLOv8Head, YOLOv8HeadModule
from .yolov8_ins_head import YOLOv8InsHead, YOLOv8InsHeadModule
from .yolox_head import YOLOXHead, YOLOXHeadModule
from .yolox_pose_head import YOLOXPoseHead, YOLOXPoseHeadModule

Expand All @@ -19,5 +20,6 @@
'YOLOv7HeadModule', 'YOLOv7p6HeadModule', 'YOLOv8Head', 'YOLOv8HeadModule',
'RTMDetRotatedHead', 'RTMDetRotatedSepBNHeadModule', 'RTMDetInsSepBNHead',
'RTMDetInsSepBNHeadModule', 'YOLOv5InsHead', 'YOLOv5InsHeadModule',
'YOLOXPoseHead', 'YOLOXPoseHeadModule'
'YOLOv8InsHead', 'YOLOv8InsHeadModule', 'YOLOXPoseHead',
'YOLOXPoseHeadModule'
]
Loading