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

fix scale for loss hyps #374

Merged
merged 1 commit into from
Oct 22, 2024
Merged
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
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
8 changes: 6 additions & 2 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 @@ -189,8 +190,11 @@ def train(args):
eval_dataset, eval_dataloader = None, None

# Scale loss hyps
args.loss.cls *= args.data.nc / 80
args.loss.obj *= (args.img_size / 640) ** 2
nl = network.model.model[-1].nl
WongGawa marked this conversation as resolved.
Show resolved Hide resolved
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(
Expand Down
Loading