(data,
weights=None,
batch_size=32,
imgsz=640,
conf_thres=0.001,
iou_thres=0.6, # for NMS
save_json=False,
single_cls=False,
augment=False,
verbose=False,
model=None,
dataloader=None,
save_dir=Path(''), # for saving images
save_txt=False, # for auto-labelling
save_hybrid=False, # for hybrid auto-labelling
save_conf=False, # save auto-label confidences
plots=True,
wandb_logger=None,
compute_loss=None,
half_precision=True,
trace=False,
is_coco=False)
| 19 | |
| 20 | |
| 21 | def test(data, |
| 22 | weights=None, |
| 23 | batch_size=32, |
| 24 | imgsz=640, |
| 25 | conf_thres=0.001, |
| 26 | iou_thres=0.6, # for NMS |
| 27 | save_json=False, |
| 28 | single_cls=False, |
| 29 | augment=False, |
| 30 | verbose=False, |
| 31 | model=None, |
| 32 | dataloader=None, |
| 33 | save_dir=Path(''), # for saving images |
| 34 | save_txt=False, # for auto-labelling |
| 35 | save_hybrid=False, # for hybrid auto-labelling |
| 36 | save_conf=False, # save auto-label confidences |
| 37 | plots=True, |
| 38 | wandb_logger=None, |
| 39 | compute_loss=None, |
| 40 | half_precision=True, |
| 41 | trace=False, |
| 42 | is_coco=False): |
| 43 | # Initialize/load model and set device |
| 44 | training = model is not None |
| 45 | if training: # called by train.py |
| 46 | device = next(model.parameters()).device # get model device |
| 47 | |
| 48 | else: # called directly |
| 49 | set_logging() |
| 50 | device = select_device(opt.device, batch_size=batch_size) |
| 51 | |
| 52 | # Directories |
| 53 | save_dir = Path(increment_path(Path(opt.project) / opt.name, exist_ok=opt.exist_ok)) # increment run |
| 54 | (save_dir / 'labels' if save_txt else save_dir).mkdir(parents=True, exist_ok=True) # make dir |
| 55 | |
| 56 | # Load model |
| 57 | model = attempt_load(weights, map_location=device) # load FP32 model |
| 58 | gs = max(int(model.stride.max()), 32) # grid size (max stride) |
| 59 | imgsz = check_img_size(imgsz, s=gs) # check img_size |
| 60 | |
| 61 | if trace: |
| 62 | model = TracedModel(model, device, opt.img_size) |
| 63 | |
| 64 | # Half |
| 65 | half = device.type != 'cpu' and half_precision # half precision only supported on CUDA |
| 66 | if half: |
| 67 | model.half() |
| 68 | |
| 69 | # Configure |
| 70 | model.eval() |
| 71 | if isinstance(data, str): |
| 72 | is_coco = data.endswith('coco.yaml') |
| 73 | with open(data) as f: |
| 74 | data = yaml.load(f, Loader=yaml.SafeLoader) |
| 75 | check_dataset(data) # check |
| 76 | nc = 1 if single_cls else int(data['nc']) # number of classes |
| 77 | iouv = torch.linspace(0.5, 0.95, 10).to(device) # iou vector for mAP@0.5:0.95 |
| 78 | niou = iouv.numel() |
no test coverage detected