Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate best.pt on train end #4889

Merged
merged 7 commits into from
Sep 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,7 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary
single_cls=single_cls,
dataloader=val_loader,
save_dir=save_dir,
save_json=is_coco and final_epoch,
verbose=nc < 50 and final_epoch,
plots=plots and final_epoch,
plots=False,
callbacks=callbacks,
compute_loss=compute_loss)

Expand Down Expand Up @@ -404,23 +402,24 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary
# end training -----------------------------------------------------------------------------------------------------
if RANK in [-1, 0]:
LOGGER.info(f'\n{epoch - start_epoch + 1} epochs completed in {(time.time() - t0) / 3600:.3f} hours.')
if not evolve:
if is_coco: # COCO dataset
for m in [last, best] if best.exists() else [last]: # speed, mAP tests
for f in last, best:
if f.exists():
strip_optimizer(f) # strip optimizers
if f is best:
LOGGER.info(f'\nValidating {f}...')
results, _, _ = val.run(data_dict,
batch_size=batch_size // WORLD_SIZE * 2,
imgsz=imgsz,
model=attempt_load(m, device).half(),
iou_thres=0.7, # NMS IoU threshold for best pycocotools results
model=attempt_load(f, device).half(),
iou_thres=0.7 if is_coco else 0.6, # best pycocotools results at 0.7
single_cls=single_cls,
dataloader=val_loader,
save_dir=save_dir,
save_json=True,
plots=False)
# Strip optimizers
for f in last, best:
if f.exists():
strip_optimizer(f) # strip optimizers
save_json=is_coco,
verbose=True,
plots=True,
callbacks=callbacks) # val best model with plots

callbacks.run('on_train_end', last, best, plots, epoch)
LOGGER.info(f"Results saved to {colorstr('bold', save_dir)}")

Expand Down
3 changes: 1 addition & 2 deletions val.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ def run(data,

# Half
half &= device.type != 'cpu' # half precision only supported on CUDA
if half:
model.half()
model.half() if half else model.float()

# Configure
model.eval()
Expand Down