glenn-jocher commited on
Commit
099e6f5
1 Parent(s): 4ba47b1

--img-size stride-multiple verification

Browse files
Files changed (4) hide show
  1. detect.py +1 -0
  2. test.py +1 -0
  3. train.py +1 -3
  4. utils/utils.py +8 -1
detect.py CHANGED
@@ -156,6 +156,7 @@ if __name__ == '__main__':
156
  parser.add_argument('--agnostic-nms', action='store_true', help='class-agnostic NMS')
157
  parser.add_argument('--augment', action='store_true', help='augmented inference')
158
  opt = parser.parse_args()
 
159
  print(opt)
160
 
161
  with torch.no_grad():
 
156
  parser.add_argument('--agnostic-nms', action='store_true', help='class-agnostic NMS')
157
  parser.add_argument('--augment', action='store_true', help='augmented inference')
158
  opt = parser.parse_args()
159
+ opt.img_size = check_img_size(opt.img_size)
160
  print(opt)
161
 
162
  with torch.no_grad():
test.py CHANGED
@@ -245,6 +245,7 @@ if __name__ == '__main__':
245
  parser.add_argument('--augment', action='store_true', help='augmented inference')
246
  parser.add_argument('--verbose', action='store_true', help='report mAP by class')
247
  opt = parser.parse_args()
 
248
  opt.save_json = opt.save_json or opt.data.endswith('coco.yaml')
249
  opt.data = glob.glob('./**/' + opt.data, recursive=True)[0] # find file
250
  print(opt)
 
245
  parser.add_argument('--augment', action='store_true', help='augmented inference')
246
  parser.add_argument('--verbose', action='store_true', help='report mAP by class')
247
  opt = parser.parse_args()
248
+ opt.img_size = check_img_size(opt.img_size)
249
  opt.save_json = opt.save_json or opt.data.endswith('coco.yaml')
250
  opt.data = glob.glob('./**/' + opt.data, recursive=True)[0] # find file
251
  print(opt)
train.py CHANGED
@@ -80,9 +80,7 @@ def train(hyp):
80
 
81
  # Image sizes
82
  gs = int(max(model.stride)) # grid size (max stride)
83
- if any(x % gs != 0 for x in opt.img_size):
84
- print('WARNING: --img-size %g,%g must be multiple of %s max stride %g' % (*opt.img_size, opt.cfg, gs))
85
- imgsz, imgsz_test = [make_divisible(x, gs) for x in opt.img_size] # image sizes (train, test)
86
 
87
  # Optimizer
88
  nbs = 64 # nominal batch size
 
80
 
81
  # Image sizes
82
  gs = int(max(model.stride)) # grid size (max stride)
83
+ imgsz, imgsz_test = [check_img_size(x, gs) for x in opt.img_size] # verify imgsz are gs-multiples
 
 
84
 
85
  # Optimizer
86
  nbs = 64 # nominal batch size
utils/utils.py CHANGED
@@ -37,13 +37,20 @@ def init_seeds(seed=0):
37
 
38
 
39
  def check_git_status():
 
40
  if platform in ['linux', 'darwin']:
41
- # Suggest 'git pull' if repo is out of date
42
  s = subprocess.check_output('if [ -d .git ]; then git fetch && git status -uno; fi', shell=True).decode('utf-8')
43
  if 'Your branch is behind' in s:
44
  print(s[s.find('Your branch is behind'):s.find('\n\n')] + '\n')
45
 
46
 
 
 
 
 
 
 
 
47
  def make_divisible(x, divisor):
48
  # Returns x evenly divisble by divisor
49
  return math.ceil(x / divisor) * divisor
 
37
 
38
 
39
  def check_git_status():
40
+ # Suggest 'git pull' if repo is out of date
41
  if platform in ['linux', 'darwin']:
 
42
  s = subprocess.check_output('if [ -d .git ]; then git fetch && git status -uno; fi', shell=True).decode('utf-8')
43
  if 'Your branch is behind' in s:
44
  print(s[s.find('Your branch is behind'):s.find('\n\n')] + '\n')
45
 
46
 
47
+ def check_img_size(img_size, s=32):
48
+ # Verify img_size is a multiple of stride s
49
+ if img_size % s != 0:
50
+ print('WARNING: --img-size %g must be multiple of max stride %g' % (img_size, s))
51
+ return make_divisible(img_size, s) # nearest gs-multiple
52
+
53
+
54
  def make_divisible(x, divisor):
55
  # Returns x evenly divisble by divisor
56
  return math.ceil(x / divisor) * divisor