Skip to content

Commit

Permalink
multi-scale fix #16
Browse files Browse the repository at this point in the history
  • Loading branch information
glenn-jocher committed Jun 5, 2020
1 parent 7c2832c commit 55ca5c7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ jobs:
stale-pr-message: 'This pull request is stale because it has been open 30 days with no activity. Remove Stale label or comment or this will be closed in 5 days.'
days-before-stale: 30
days-before-close: 5
exempt-issue-label: 'tutorial'
exempt-issue-label: ['documentation', 'tutorial']
10 changes: 6 additions & 4 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ def train(hyp):
x['momentum'] = np.interp(ni, xi, [0.9, hyp['momentum']])

# Multi-scale
if True:
imgsz = random.randrange(640, 640 + gs) // gs * gs
sf = imgsz / max(imgs.shape[2:]) # scale factor
if opt.multi_scale:
sz = random.randrange(imgsz * 0.5, imgsz * 1.5 + gs) // gs * gs # size
sf = sz / max(imgs.shape[2:]) # scale factor
if sf != 1:
ns = [math.ceil(x * sf / gs) * gs for x in imgs.shape[2:]] # new shape (stretched to gs-multiple)
imgs = F.interpolate(imgs, size=ns, mode='bilinear', align_corners=False)
Expand Down Expand Up @@ -273,7 +273,8 @@ def train(hyp):
# Print
mloss = (mloss * i + loss_items) / (i + 1) # update mean losses
mem = '%.3gG' % (torch.cuda.memory_cached() / 1E9 if torch.cuda.is_available() else 0) # (GB)
s = ('%10s' * 2 + '%10.4g' * 6) % ('%g/%g' % (epoch, epochs - 1), mem, *mloss, targets.shape[0], imgsz)
s = ('%10s' * 2 + '%10.4g' * 6) % (
'%g/%g' % (epoch, epochs - 1), mem, *mloss, targets.shape[0], imgs.shape[-1])
pbar.set_description(s)

# Plot
Expand Down Expand Up @@ -377,6 +378,7 @@ def train(hyp):
parser.add_argument('--name', default='', help='renames results.txt to results_name.txt if supplied')
parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
parser.add_argument('--adam', action='store_true', help='use adam optimizer')
parser.add_argument('--multi-scale', action='store_true', help='vary img-size +/- 50%')
parser.add_argument('--single-cls', action='store_true', help='train as single-class dataset')
opt = parser.parse_args()
opt.weights = last if opt.resume else opt.weights
Expand Down

0 comments on commit 55ca5c7

Please sign in to comment.