Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
UltralyticsAssistant committed Feb 4, 2024
1 parent 6fd222c commit 8fd5518
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ def train(hyp, opt, device, callbacks): # hyp is path/to/hyp.yaml or hyp dictio

total_training_hours = (time.time() - t0) / 3600
if RANK in {-1, 0}:
LOGGER.info(f'\n{epoch - start_epoch + 1} epochs completed in {total_training_hours:.3f} hours.')
LOGGER.info(f"\n{epoch - start_epoch + 1} epochs completed in {total_training_hours:.3f} hours.")
for f in last, best:
if f.exists():
strip_optimizer(f) # strip optimizers
Expand All @@ -500,7 +500,7 @@ def train(hyp, opt, device, callbacks): # hyp is path/to/hyp.yaml or hyp dictio
if is_coco:
callbacks.run("on_fit_epoch_end", list(mloss) + list(results) + lr, epoch, best_fitness, fi)

callbacks.run('on_train_end', last, best, epoch, results, total_training_hours)
callbacks.run("on_train_end", last, best, epoch, results, total_training_hours)

torch.cuda.empty_cache()
return results
Expand Down
16 changes: 11 additions & 5 deletions utils/loggers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def __init__(self, save_dir=None, weights=None, opt=None, hyp=None, logger=None,
self.csv = True # always log to csv
self.ndjson_console = "ndjson_console" in self.include # log ndjson to console
self.ndjson_file = "ndjson_file" in self.include # log ndjson to file
self.metrics = True # log to metrics file at the end of the run
self.metrics = True # log to metrics file at the end of the run
# Messages
if not comet_ml:
prefix = colorstr("Comet: ")
Expand Down Expand Up @@ -304,10 +304,16 @@ def on_train_end(self, last, best, epoch, results, total_train_time):
self.tb.add_image(f.stem, cv2.imread(str(f))[..., ::-1], epoch, dataformats="HWC")

if self.metrics:
file = self.save_dir / 'metrics.json'
m={"precision":results[0],"recall":results[1],"mAP_0_5":results[2],"mAP_0_5-0_95":results[3], "total_train_hours":total_train_time}

with open(file, 'w') as f:
file = self.save_dir / "metrics.json"
m = {
"precision": results[0],
"recall": results[1],
"mAP_0_5": results[2],
"mAP_0_5-0_95": results[3],
"total_train_hours": total_train_time,
}

with open(file, "w") as f:
f.write(json.dumps(m))

if self.wandb:
Expand Down

0 comments on commit 8fd5518

Please sign in to comment.