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

Passing input channels to Model constructor instead of hardcoding the value #12382

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions models/yolov5l.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# YOLOv5 πŸš€ by Ultralytics, AGPL-3.0 license

# Parameters
input_channels: 3 # number of input channels, RGB is 3
nc: 80 # number of classes
depth_multiple: 1.0 # model depth multiple
width_multiple: 1.0 # layer channel multiple
Expand Down
1 change: 1 addition & 0 deletions models/yolov5m.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# YOLOv5 πŸš€ by Ultralytics, AGPL-3.0 license

# Parameters
input_channels: 3 # number of input channels, RGB is 3
nc: 80 # number of classes
depth_multiple: 0.67 # model depth multiple
width_multiple: 0.75 # layer channel multiple
Expand Down
1 change: 1 addition & 0 deletions models/yolov5n.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# YOLOv5 πŸš€ by Ultralytics, AGPL-3.0 license

# Parameters
input_channels: 3 # number of input channels, RGB is 3
nc: 80 # number of classes
depth_multiple: 0.33 # model depth multiple
width_multiple: 0.25 # layer channel multiple
Expand Down
1 change: 1 addition & 0 deletions models/yolov5s.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# YOLOv5 πŸš€ by Ultralytics, AGPL-3.0 license

# Parameters
input_channels: 3 # number of input channels, RGB is 3
nc: 80 # number of classes
depth_multiple: 0.33 # model depth multiple
width_multiple: 0.50 # layer channel multiple
Expand Down
5 changes: 3 additions & 2 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,15 @@ def train(hyp, opt, device, callbacks): # hyp is path/to/hyp.yaml or hyp dictio
with torch_distributed_zero_first(LOCAL_RANK):
weights = attempt_download(weights) # download if not found locally
ckpt = torch.load(weights, map_location='cpu') # load checkpoint to CPU to avoid CUDA memory leak
model = Model(cfg or ckpt['model'].yaml, ch=3, nc=nc, anchors=hyp.get('anchors')).to(device) # create
model = Model(cfg or ckpt['model'].yaml, ch=hyp.get('input_channels', 3), nc=nc,
anchors=hyp.get('anchors')).to(device) # create
exclude = ['anchor'] if (cfg or hyp.get('anchors')) and not resume else [] # exclude keys
csd = ckpt['model'].float().state_dict() # checkpoint state_dict as FP32
csd = intersect_dicts(csd, model.state_dict(), exclude=exclude) # intersect
model.load_state_dict(csd, strict=False) # load
LOGGER.info(f'Transferred {len(csd)}/{len(model.state_dict())} items from {weights}') # report
else:
model = Model(cfg, ch=3, nc=nc, anchors=hyp.get('anchors')).to(device) # create
model = Model(cfg, ch=hyp.get('input_channels', 3), nc=nc, anchors=hyp.get('anchors')).to(device) # create
amp = check_amp(model) # check AMP

# Freeze
Expand Down