Validate `best.pt` on train end (#4889)
Browse files* Validate best.pt on train end
* 0.7 iou for COCO only
* pass callbacks
* active model.float() if not half
* print Validating best.pt...
* add newline
train.py
CHANGED
@@ -356,9 +356,7 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary
|
|
356 |
single_cls=single_cls,
|
357 |
dataloader=val_loader,
|
358 |
save_dir=save_dir,
|
359 |
-
|
360 |
-
verbose=nc < 50 and final_epoch,
|
361 |
-
plots=plots and final_epoch,
|
362 |
callbacks=callbacks,
|
363 |
compute_loss=compute_loss)
|
364 |
|
@@ -404,23 +402,24 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary
|
|
404 |
# end training -----------------------------------------------------------------------------------------------------
|
405 |
if RANK in [-1, 0]:
|
406 |
LOGGER.info(f'\n{epoch - start_epoch + 1} epochs completed in {(time.time() - t0) / 3600:.3f} hours.')
|
407 |
-
|
408 |
-
if
|
409 |
-
|
|
|
|
|
410 |
results, _, _ = val.run(data_dict,
|
411 |
batch_size=batch_size // WORLD_SIZE * 2,
|
412 |
imgsz=imgsz,
|
413 |
-
model=attempt_load(
|
414 |
-
iou_thres=0.7
|
415 |
single_cls=single_cls,
|
416 |
dataloader=val_loader,
|
417 |
save_dir=save_dir,
|
418 |
-
save_json=
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
strip_optimizer(f) # strip optimizers
|
424 |
callbacks.run('on_train_end', last, best, plots, epoch)
|
425 |
LOGGER.info(f"Results saved to {colorstr('bold', save_dir)}")
|
426 |
|
|
|
356 |
single_cls=single_cls,
|
357 |
dataloader=val_loader,
|
358 |
save_dir=save_dir,
|
359 |
+
plots=False,
|
|
|
|
|
360 |
callbacks=callbacks,
|
361 |
compute_loss=compute_loss)
|
362 |
|
|
|
402 |
# end training -----------------------------------------------------------------------------------------------------
|
403 |
if RANK in [-1, 0]:
|
404 |
LOGGER.info(f'\n{epoch - start_epoch + 1} epochs completed in {(time.time() - t0) / 3600:.3f} hours.')
|
405 |
+
for f in last, best:
|
406 |
+
if f.exists():
|
407 |
+
strip_optimizer(f) # strip optimizers
|
408 |
+
if f is best:
|
409 |
+
LOGGER.info(f'\nValidating {f}...')
|
410 |
results, _, _ = val.run(data_dict,
|
411 |
batch_size=batch_size // WORLD_SIZE * 2,
|
412 |
imgsz=imgsz,
|
413 |
+
model=attempt_load(f, device).half(),
|
414 |
+
iou_thres=0.7 if is_coco else 0.6, # best pycocotools results at 0.7
|
415 |
single_cls=single_cls,
|
416 |
dataloader=val_loader,
|
417 |
save_dir=save_dir,
|
418 |
+
save_json=is_coco,
|
419 |
+
verbose=True,
|
420 |
+
plots=True,
|
421 |
+
callbacks=callbacks) # val best model with plots
|
422 |
+
|
|
|
423 |
callbacks.run('on_train_end', last, best, plots, epoch)
|
424 |
LOGGER.info(f"Results saved to {colorstr('bold', save_dir)}")
|
425 |
|
val.py
CHANGED
@@ -133,8 +133,7 @@ def run(data,
|
|
133 |
|
134 |
# Half
|
135 |
half &= device.type != 'cpu' # half precision only supported on CUDA
|
136 |
-
if half
|
137 |
-
model.half()
|
138 |
|
139 |
# Configure
|
140 |
model.eval()
|
|
|
133 |
|
134 |
# Half
|
135 |
half &= device.type != 'cpu' # half precision only supported on CUDA
|
136 |
+
model.half() if half else model.float()
|
|
|
137 |
|
138 |
# Configure
|
139 |
model.eval()
|