MCPcopy
hub / github.com/ultralytics/yolov5 / run

Function run

val.py:98–336  ·  view source on GitHub ↗
(
        data,
        weights=None,  # model.pt path(s)
        batch_size=32,  # batch size
        imgsz=640,  # inference size (pixels)
        conf_thres=0.001,  # confidence threshold
        iou_thres=0.6,  # NMS IoU threshold
        max_det=300,  # maximum detections per image
        task='val',  # train, val, test, speed or study
        device='',  # cuda device, i.e. 0 or 0,1,2,3 or cpu
        workers=8,  # max dataloader workers (per RANK in DDP mode)
        single_cls=False,  # treat as single-class dataset
        augment=False,  # augmented inference
        verbose=False,  # verbose output
        save_txt=False,  # save results to *.txt
        save_hybrid=False,  # save label+prediction hybrid results to *.txt
        save_conf=False,  # save confidences in --save-txt labels
        save_json=False,  # save a COCO-JSON results file
        project=ROOT / 'runs/val',  # save to project/name
        name='exp',  # save to project/name
        exist_ok=False,  # existing project/name ok, do not increment
        half=True,  # use FP16 half-precision inference
        dnn=False,  # use OpenCV DNN for ONNX inference
        model=None,
        dataloader=None,
        save_dir=Path(''),
        plots=True,
        callbacks=Callbacks(),
        compute_loss=None,
)

Source from the content-addressed store, hash-verified

96
97@smart_inference_mode()
98def run(
99 data,
100 weights=None, # model.pt path(s)
101 batch_size=32, # batch size
102 imgsz=640, # inference size (pixels)
103 conf_thres=0.001, # confidence threshold
104 iou_thres=0.6, # NMS IoU threshold
105 max_det=300, # maximum detections per image
106 task='val', # train, val, test, speed or study
107 device='', # cuda device, i.e. 0 or 0,1,2,3 or cpu
108 workers=8, # max dataloader workers (per RANK in DDP mode)
109 single_cls=False, # treat as single-class dataset
110 augment=False, # augmented inference
111 verbose=False, # verbose output
112 save_txt=False, # save results to *.txt
113 save_hybrid=False, # save label+prediction hybrid results to *.txt
114 save_conf=False, # save confidences in --save-txt labels
115 save_json=False, # save a COCO-JSON results file
116 project=ROOT / 'runs/val', # save to project/name
117 name='exp', # save to project/name
118 exist_ok=False, # existing project/name ok, do not increment
119 half=True, # use FP16 half-precision inference
120 dnn=False, # use OpenCV DNN for ONNX inference
121 model=None,
122 dataloader=None,
123 save_dir=Path(''),
124 plots=True,
125 callbacks=Callbacks(),
126 compute_loss=None,
127):
128 # Initialize/load model and set device
129 training = model is not None
130 if training: # called by train.py
131 device, pt, jit, engine = next(model.parameters()).device, True, False, False # get model device, PyTorch model
132 half &= device.type != 'cpu' # half precision only supported on CUDA
133 model.half() if half else model.float()
134 else: # called directly
135 device = select_device(device, batch_size=batch_size)
136
137 # Directories
138 save_dir = increment_path(Path(project) / name, exist_ok=exist_ok) # increment run
139 (save_dir / 'labels' if save_txt else save_dir).mkdir(parents=True, exist_ok=True) # make dir
140
141 # Load model
142 model = DetectMultiBackend(weights, device=device, dnn=dnn, data=data, fp16=half)
143 stride, pt, jit, engine = model.stride, model.pt, model.jit, model.engine
144 imgsz = check_img_size(imgsz, s=stride) # check image size
145 half = model.fp16 # FP16 supported on limited backends with CUDA
146 if engine:
147 batch_size = model.batch_size
148 else:
149 device = model.device
150 if not (pt or jit):
151 batch_size = 1 # export.py models default to batch-size 1
152 LOGGER.info(f'Forcing --batch-size 1 square inference (1,3,{imgsz},{imgsz}) for non-PyTorch models')
153
154 # Data
155 data = check_dataset(data) # check

Callers 1

mainFunction · 0.70

Calls 15

warmupMethod · 0.95
process_batchMethod · 0.95
plotMethod · 0.95
CallbacksClass · 0.90
select_deviceFunction · 0.90
increment_pathFunction · 0.90
DetectMultiBackendClass · 0.90
check_img_sizeFunction · 0.90
check_datasetFunction · 0.90
create_dataloaderFunction · 0.90
colorstrFunction · 0.90
ConfusionMatrixClass · 0.90

Tested by

no test coverage detected