glenn-jocher commited on
Commit
55ca5c7
·
1 Parent(s): 7c2832c

multi-scale fix #16

Browse files
Files changed (2) hide show
  1. .github/workflows/stale.yml +1 -1
  2. train.py +6 -4
.github/workflows/stale.yml CHANGED
@@ -14,4 +14,4 @@ jobs:
14
  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.'
15
  days-before-stale: 30
16
  days-before-close: 5
17
- exempt-issue-label: 'tutorial'
 
14
  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.'
15
  days-before-stale: 30
16
  days-before-close: 5
17
+ exempt-issue-label: ['documentation', 'tutorial']
train.py CHANGED
@@ -241,9 +241,9 @@ def train(hyp):
241
  x['momentum'] = np.interp(ni, xi, [0.9, hyp['momentum']])
242
 
243
  # Multi-scale
244
- if True:
245
- imgsz = random.randrange(640, 640 + gs) // gs * gs
246
- sf = imgsz / max(imgs.shape[2:]) # scale factor
247
  if sf != 1:
248
  ns = [math.ceil(x * sf / gs) * gs for x in imgs.shape[2:]] # new shape (stretched to gs-multiple)
249
  imgs = F.interpolate(imgs, size=ns, mode='bilinear', align_corners=False)
@@ -273,7 +273,8 @@ def train(hyp):
273
  # Print
274
  mloss = (mloss * i + loss_items) / (i + 1) # update mean losses
275
  mem = '%.3gG' % (torch.cuda.memory_cached() / 1E9 if torch.cuda.is_available() else 0) # (GB)
276
- s = ('%10s' * 2 + '%10.4g' * 6) % ('%g/%g' % (epoch, epochs - 1), mem, *mloss, targets.shape[0], imgsz)
 
277
  pbar.set_description(s)
278
 
279
  # Plot
@@ -377,6 +378,7 @@ if __name__ == '__main__':
377
  parser.add_argument('--name', default='', help='renames results.txt to results_name.txt if supplied')
378
  parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
379
  parser.add_argument('--adam', action='store_true', help='use adam optimizer')
 
380
  parser.add_argument('--single-cls', action='store_true', help='train as single-class dataset')
381
  opt = parser.parse_args()
382
  opt.weights = last if opt.resume else opt.weights
 
241
  x['momentum'] = np.interp(ni, xi, [0.9, hyp['momentum']])
242
 
243
  # Multi-scale
244
+ if opt.multi_scale:
245
+ sz = random.randrange(imgsz * 0.5, imgsz * 1.5 + gs) // gs * gs # size
246
+ sf = sz / max(imgs.shape[2:]) # scale factor
247
  if sf != 1:
248
  ns = [math.ceil(x * sf / gs) * gs for x in imgs.shape[2:]] # new shape (stretched to gs-multiple)
249
  imgs = F.interpolate(imgs, size=ns, mode='bilinear', align_corners=False)
 
273
  # Print
274
  mloss = (mloss * i + loss_items) / (i + 1) # update mean losses
275
  mem = '%.3gG' % (torch.cuda.memory_cached() / 1E9 if torch.cuda.is_available() else 0) # (GB)
276
+ s = ('%10s' * 2 + '%10.4g' * 6) % (
277
+ '%g/%g' % (epoch, epochs - 1), mem, *mloss, targets.shape[0], imgs.shape[-1])
278
  pbar.set_description(s)
279
 
280
  # Plot
 
378
  parser.add_argument('--name', default='', help='renames results.txt to results_name.txt if supplied')
379
  parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
380
  parser.add_argument('--adam', action='store_true', help='use adam optimizer')
381
+ parser.add_argument('--multi-scale', action='store_true', help='vary img-size +/- 50%')
382
  parser.add_argument('--single-cls', action='store_true', help='train as single-class dataset')
383
  opt = parser.parse_args()
384
  opt.weights = last if opt.resume else opt.weights