Skip to content

Commit

Permalink
Merge pull request #380 from yuedongli1/v0.4.0
Browse files Browse the repository at this point in the history
fix yolov8x-segment bug and fix scale for loss hyps
  • Loading branch information
CaitinZhao authored Nov 4, 2024
2 parents aa8340c + 66df282 commit f88bbd2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions configs/yolov8/seg/yolov8-seg-base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ img_size: 640
conf_thres: 0.001
iou_thres: 0.7
conf_free: True
anchor_base: False
sync_bn: True
clip_grad: True
clip_grad_value: 10.0
Expand Down
1 change: 1 addition & 0 deletions configs/yolov8/yolov8-base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ img_size: 640
iou_thres: 0.7
conf_free: True
sync_bn: True
anchor_base: False
opencv_threads_num: 0 # opencv: disable threading optimizations

network:
Expand Down
2 changes: 1 addition & 1 deletion mindyolo/data/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ def random_perspective(
sample['cls'] = cls
sample['bboxes'] = targets
if use_segments:
sample['segments'] = segments[i]
sample['segments'] = new_segments[i]

sample['img'] = img

Expand Down
8 changes: 8 additions & 0 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def get_parser_train(parents=None):
parser.add_argument("--ms_amp_level", type=str, default="O0", help="amp level, O0/O1/O2/O3")
parser.add_argument("--keep_loss_fp32", type=ast.literal_eval, default=True,
help="Whether to maintain loss using fp32/O0-level calculation")
parser.add_argument("--anchor_base", type=ast.literal_eval, default=True, help="Anchor-base")
parser.add_argument("--ms_loss_scaler", type=str, default="static", help="train loss scaler, static/dynamic/none")
parser.add_argument("--ms_loss_scaler_value", type=float, default=1024.0, help="static loss scale value")
parser.add_argument("--ms_jit", type=ast.literal_eval, default=True, help="use jit or not")
Expand Down Expand Up @@ -188,6 +189,13 @@ def train(args):
else:
eval_dataset, eval_dataloader = None, None

# Scale loss hyps
nl = network.model.model[-1].nl
args.loss.box *= 3 / nl # scale to layers
args.loss.cls *= args.data.nc / 80 * 3 / nl # scale to classes and layers
if args.anchor_base:
args.loss.obj *= (args.img_size / 640) ** 2 * 3 / nl # scale to image size and layers

# Create Loss
loss_fn = create_loss(
**args.loss, anchors=args.network.get("anchors", 1), stride=args.network.stride, nc=args.data.nc
Expand Down

0 comments on commit f88bbd2

Please sign in to comment.