glenn-jocher commited on
Commit
2c32218
1 Parent(s): c3d5ac1

CLI `fire` prep updates (#7229)

Browse files

* CLI fire prep updates

* revert unintentional TF export change

Files changed (8) hide show
  1. detect.py +1 -1
  2. export.py +1 -1
  3. models/tf.py +1 -1
  4. models/yolo.py +1 -1
  5. train.py +1 -1
  6. utils/benchmarks.py +1 -1
  7. utils/general.py +12 -3
  8. val.py +1 -1
detect.py CHANGED
@@ -238,7 +238,7 @@ def parse_opt():
238
  parser.add_argument('--dnn', action='store_true', help='use OpenCV DNN for ONNX inference')
239
  opt = parser.parse_args()
240
  opt.imgsz *= 2 if len(opt.imgsz) == 1 else 1 # expand
241
- print_args(FILE.stem, opt)
242
  return opt
243
 
244
 
 
238
  parser.add_argument('--dnn', action='store_true', help='use OpenCV DNN for ONNX inference')
239
  opt = parser.parse_args()
240
  opt.imgsz *= 2 if len(opt.imgsz) == 1 else 1 # expand
241
+ print_args(vars(opt))
242
  return opt
243
 
244
 
export.py CHANGED
@@ -566,7 +566,7 @@ def parse_opt():
566
  default=['torchscript', 'onnx'],
567
  help='torchscript, onnx, openvino, engine, coreml, saved_model, pb, tflite, edgetpu, tfjs')
568
  opt = parser.parse_args()
569
- print_args(FILE.stem, opt)
570
  return opt
571
 
572
 
 
566
  default=['torchscript', 'onnx'],
567
  help='torchscript, onnx, openvino, engine, coreml, saved_model, pb, tflite, edgetpu, tfjs')
568
  opt = parser.parse_args()
569
+ print_args(vars(opt))
570
  return opt
571
 
572
 
models/tf.py CHANGED
@@ -480,7 +480,7 @@ def parse_opt():
480
  parser.add_argument('--dynamic', action='store_true', help='dynamic batch size')
481
  opt = parser.parse_args()
482
  opt.imgsz *= 2 if len(opt.imgsz) == 1 else 1 # expand
483
- print_args(FILE.stem, opt)
484
  return opt
485
 
486
 
 
480
  parser.add_argument('--dynamic', action='store_true', help='dynamic batch size')
481
  opt = parser.parse_args()
482
  opt.imgsz *= 2 if len(opt.imgsz) == 1 else 1 # expand
483
+ print_args(vars(opt))
484
  return opt
485
 
486
 
models/yolo.py CHANGED
@@ -308,7 +308,7 @@ if __name__ == '__main__':
308
  parser.add_argument('--test', action='store_true', help='test all yolo*.yaml')
309
  opt = parser.parse_args()
310
  opt.cfg = check_yaml(opt.cfg) # check YAML
311
- print_args(FILE.stem, opt)
312
  device = select_device(opt.device)
313
 
314
  # Create model
 
308
  parser.add_argument('--test', action='store_true', help='test all yolo*.yaml')
309
  opt = parser.parse_args()
310
  opt.cfg = check_yaml(opt.cfg) # check YAML
311
+ print_args(vars(opt))
312
  device = select_device(opt.device)
313
 
314
  # Create model
train.py CHANGED
@@ -515,7 +515,7 @@ def parse_opt(known=False):
515
  def main(opt, callbacks=Callbacks()):
516
  # Checks
517
  if RANK in [-1, 0]:
518
- print_args(FILE.stem, opt)
519
  check_git_status()
520
  check_requirements(exclude=['thop'])
521
 
 
515
  def main(opt, callbacks=Callbacks()):
516
  # Checks
517
  if RANK in [-1, 0]:
518
+ print_args(vars(opt))
519
  check_git_status()
520
  check_requirements(exclude=['thop'])
521
 
utils/benchmarks.py CHANGED
@@ -92,7 +92,7 @@ def parse_opt():
92
  parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
93
  parser.add_argument('--half', action='store_true', help='use FP16 half-precision inference')
94
  opt = parser.parse_args()
95
- print_args(FILE.stem, opt)
96
  return opt
97
 
98
 
 
92
  parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
93
  parser.add_argument('--half', action='store_true', help='use FP16 half-precision inference')
94
  opt = parser.parse_args()
95
+ print_args(vars(opt))
96
  return opt
97
 
98
 
utils/general.py CHANGED
@@ -5,6 +5,7 @@ General utils
5
 
6
  import contextlib
7
  import glob
 
8
  import logging
9
  import math
10
  import os
@@ -20,6 +21,7 @@ from itertools import repeat
20
  from multiprocessing.pool import ThreadPool
21
  from pathlib import Path
22
  from subprocess import check_output
 
23
  from zipfile import ZipFile
24
 
25
  import cv2
@@ -163,9 +165,15 @@ def methods(instance):
163
  return [f for f in dir(instance) if callable(getattr(instance, f)) and not f.startswith("__")]
164
 
165
 
166
- def print_args(name, opt):
167
- # Print argparser arguments
168
- LOGGER.info(colorstr(f'{name}: ') + ', '.join(f'{k}={v}' for k, v in vars(opt).items()))
 
 
 
 
 
 
169
 
170
 
171
  def init_seeds(seed=0):
@@ -346,6 +354,7 @@ def check_img_size(imgsz, s=32, floor=0):
346
  if isinstance(imgsz, int): # integer i.e. img_size=640
347
  new_size = max(make_divisible(imgsz, int(s)), floor)
348
  else: # list i.e. img_size=[640, 480]
 
349
  new_size = [max(make_divisible(x, int(s)), floor) for x in imgsz]
350
  if new_size != imgsz:
351
  LOGGER.warning(f'WARNING: --img-size {imgsz} must be multiple of max stride {s}, updating to {new_size}')
 
5
 
6
  import contextlib
7
  import glob
8
+ import inspect
9
  import logging
10
  import math
11
  import os
 
21
  from multiprocessing.pool import ThreadPool
22
  from pathlib import Path
23
  from subprocess import check_output
24
+ from typing import Optional
25
  from zipfile import ZipFile
26
 
27
  import cv2
 
165
  return [f for f in dir(instance) if callable(getattr(instance, f)) and not f.startswith("__")]
166
 
167
 
168
+ def print_args(args: Optional[dict] = None, show_file=True, show_fcn=False):
169
+ # Print function arguments (optional args dict)
170
+ x = inspect.currentframe().f_back # previous frame
171
+ file, _, fcn, _, _ = inspect.getframeinfo(x)
172
+ if args is None: # get args automatically
173
+ args, _, _, frm = inspect.getargvalues(x)
174
+ args = {k: v for k, v in frm.items() if k in args}
175
+ s = (f'{Path(file).stem}: ' if show_file else '') + (f'{fcn}: ' if show_fcn else '')
176
+ LOGGER.info(colorstr(s) + ', '.join(f'{k}={v}' for k, v in args.items()))
177
 
178
 
179
  def init_seeds(seed=0):
 
354
  if isinstance(imgsz, int): # integer i.e. img_size=640
355
  new_size = max(make_divisible(imgsz, int(s)), floor)
356
  else: # list i.e. img_size=[640, 480]
357
+ imgsz = list(imgsz) # convert to list if tuple
358
  new_size = [max(make_divisible(x, int(s)), floor) for x in imgsz]
359
  if new_size != imgsz:
360
  LOGGER.warning(f'WARNING: --img-size {imgsz} must be multiple of max stride {s}, updating to {new_size}')
val.py CHANGED
@@ -350,7 +350,7 @@ def parse_opt():
350
  opt.data = check_yaml(opt.data) # check YAML
351
  opt.save_json |= opt.data.endswith('coco.yaml')
352
  opt.save_txt |= opt.save_hybrid
353
- print_args(FILE.stem, opt)
354
  return opt
355
 
356
 
 
350
  opt.data = check_yaml(opt.data) # check YAML
351
  opt.save_json |= opt.data.endswith('coco.yaml')
352
  opt.save_txt |= opt.save_hybrid
353
+ print_args(vars(opt))
354
  return opt
355
 
356