* CLI fire prep updates * revert unintentional TF export changemodifyDataloader
parser.add_argument('--dnn', action='store_true', help='use OpenCV DNN for ONNX inference') | parser.add_argument('--dnn', action='store_true', help='use OpenCV DNN for ONNX inference') | ||||
opt = parser.parse_args() | opt = parser.parse_args() | ||||
opt.imgsz *= 2 if len(opt.imgsz) == 1 else 1 # expand | opt.imgsz *= 2 if len(opt.imgsz) == 1 else 1 # expand | ||||
print_args(FILE.stem, opt) | |||||
print_args(vars(opt)) | |||||
return opt | return opt | ||||
default=['torchscript', 'onnx'], | default=['torchscript', 'onnx'], | ||||
help='torchscript, onnx, openvino, engine, coreml, saved_model, pb, tflite, edgetpu, tfjs') | help='torchscript, onnx, openvino, engine, coreml, saved_model, pb, tflite, edgetpu, tfjs') | ||||
opt = parser.parse_args() | opt = parser.parse_args() | ||||
print_args(FILE.stem, opt) | |||||
print_args(vars(opt)) | |||||
return opt | return opt | ||||
parser.add_argument('--dynamic', action='store_true', help='dynamic batch size') | parser.add_argument('--dynamic', action='store_true', help='dynamic batch size') | ||||
opt = parser.parse_args() | opt = parser.parse_args() | ||||
opt.imgsz *= 2 if len(opt.imgsz) == 1 else 1 # expand | opt.imgsz *= 2 if len(opt.imgsz) == 1 else 1 # expand | ||||
print_args(FILE.stem, opt) | |||||
print_args(vars(opt)) | |||||
return opt | return opt | ||||
parser.add_argument('--test', action='store_true', help='test all yolo*.yaml') | parser.add_argument('--test', action='store_true', help='test all yolo*.yaml') | ||||
opt = parser.parse_args() | opt = parser.parse_args() | ||||
opt.cfg = check_yaml(opt.cfg) # check YAML | opt.cfg = check_yaml(opt.cfg) # check YAML | ||||
print_args(FILE.stem, opt) | |||||
print_args(vars(opt)) | |||||
device = select_device(opt.device) | device = select_device(opt.device) | ||||
# Create model | # Create model |
def main(opt, callbacks=Callbacks()): | def main(opt, callbacks=Callbacks()): | ||||
# Checks | # Checks | ||||
if RANK in [-1, 0]: | if RANK in [-1, 0]: | ||||
print_args(FILE.stem, opt) | |||||
print_args(vars(opt)) | |||||
check_git_status() | check_git_status() | ||||
check_requirements(exclude=['thop']) | check_requirements(exclude=['thop']) | ||||
parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu') | parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu') | ||||
parser.add_argument('--half', action='store_true', help='use FP16 half-precision inference') | parser.add_argument('--half', action='store_true', help='use FP16 half-precision inference') | ||||
opt = parser.parse_args() | opt = parser.parse_args() | ||||
print_args(FILE.stem, opt) | |||||
print_args(vars(opt)) | |||||
return opt | return opt | ||||
import contextlib | import contextlib | ||||
import glob | import glob | ||||
import inspect | |||||
import logging | import logging | ||||
import math | import math | ||||
import os | import os | ||||
from multiprocessing.pool import ThreadPool | from multiprocessing.pool import ThreadPool | ||||
from pathlib import Path | from pathlib import Path | ||||
from subprocess import check_output | from subprocess import check_output | ||||
from typing import Optional | |||||
from zipfile import ZipFile | from zipfile import ZipFile | ||||
import cv2 | import cv2 | ||||
return [f for f in dir(instance) if callable(getattr(instance, f)) and not f.startswith("__")] | return [f for f in dir(instance) if callable(getattr(instance, f)) and not f.startswith("__")] | ||||
def print_args(name, opt): | |||||
# Print argparser arguments | |||||
LOGGER.info(colorstr(f'{name}: ') + ', '.join(f'{k}={v}' for k, v in vars(opt).items())) | |||||
def print_args(args: Optional[dict] = None, show_file=True, show_fcn=False): | |||||
# Print function arguments (optional args dict) | |||||
x = inspect.currentframe().f_back # previous frame | |||||
file, _, fcn, _, _ = inspect.getframeinfo(x) | |||||
if args is None: # get args automatically | |||||
args, _, _, frm = inspect.getargvalues(x) | |||||
args = {k: v for k, v in frm.items() if k in args} | |||||
s = (f'{Path(file).stem}: ' if show_file else '') + (f'{fcn}: ' if show_fcn else '') | |||||
LOGGER.info(colorstr(s) + ', '.join(f'{k}={v}' for k, v in args.items())) | |||||
def init_seeds(seed=0): | def init_seeds(seed=0): | ||||
if isinstance(imgsz, int): # integer i.e. img_size=640 | if isinstance(imgsz, int): # integer i.e. img_size=640 | ||||
new_size = max(make_divisible(imgsz, int(s)), floor) | new_size = max(make_divisible(imgsz, int(s)), floor) | ||||
else: # list i.e. img_size=[640, 480] | else: # list i.e. img_size=[640, 480] | ||||
imgsz = list(imgsz) # convert to list if tuple | |||||
new_size = [max(make_divisible(x, int(s)), floor) for x in imgsz] | new_size = [max(make_divisible(x, int(s)), floor) for x in imgsz] | ||||
if new_size != imgsz: | if new_size != imgsz: | ||||
LOGGER.warning(f'WARNING: --img-size {imgsz} must be multiple of max stride {s}, updating to {new_size}') | LOGGER.warning(f'WARNING: --img-size {imgsz} must be multiple of max stride {s}, updating to {new_size}') |
opt.data = check_yaml(opt.data) # check YAML | opt.data = check_yaml(opt.data) # check YAML | ||||
opt.save_json |= opt.data.endswith('coco.yaml') | opt.save_json |= opt.data.endswith('coco.yaml') | ||||
opt.save_txt |= opt.save_hybrid | opt.save_txt |= opt.save_hybrid | ||||
print_args(FILE.stem, opt) | |||||
print_args(vars(opt)) | |||||
return opt | return opt | ||||