Skip to content

Commit

Permalink
Refactor for simplification 2 (ultralytics#9055)
Browse files Browse the repository at this point in the history
* Refactor for simplification 2

* Update __init__.py

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
  • Loading branch information
glenn-jocher authored and Clay Januhowski committed Sep 8, 2022
1 parent 8bf7f13 commit 67d6832
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
3 changes: 1 addition & 2 deletions export.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,7 @@ def export_tfjs(file, prefix=colorstr('TensorFlow.js:')):
f'--output_node_names=Identity,Identity_1,Identity_2,Identity_3 {f_pb} {f}'
subprocess.run(cmd.split())

with open(f_json) as j:
json = j.read()
json = Path(f_json).read_text()
with open(f_json, 'w') as j: # sort JSON Identity_* in ascending order
subst = re.sub(
r'{"outputs": {"Identity.?.?": {"name": "Identity.?.?"}, '
Expand Down
20 changes: 7 additions & 13 deletions utils/loggers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,16 @@ def on_fit_epoch_end(self, vals, epoch, best_fitness, fi):

def on_model_save(self, last, epoch, final_epoch, best_fitness, fi):
# Callback runs on model save event
if self.wandb:
if ((epoch + 1) % self.opt.save_period == 0 and not final_epoch) and self.opt.save_period != -1:
if (epoch + 1) % self.opt.save_period == 0 and not final_epoch and self.opt.save_period != -1:
if self.wandb:
self.wandb.log_model(last.parent, self.opt, epoch, fi, best_model=best_fitness == fi)

if self.clearml:
if ((epoch + 1) % self.opt.save_period == 0 and not final_epoch) and self.opt.save_period != -1:
if self.clearml:
self.clearml.task.update_output_model(model_path=str(last),
model_name='Latest Model',
auto_delete_file=False)

def on_train_end(self, last, best, plots, epoch, results):
# Callback runs on training end
# Callback runs on training end, i.e. saving best model
if plots:
plot_results(file=self.save_dir / 'results.csv') # save results.png
files = ['results.png', 'confusion_matrix.png', *(f'{x}_curve.png' for x in ('F1', 'PR', 'P', 'R'))]
Expand All @@ -220,15 +218,11 @@ def on_train_end(self, last, best, plots, epoch, results):
aliases=['latest', 'best', 'stripped'])
self.wandb.finish_run()

if self.clearml:
# Save the best model here
if not self.opt.evolve:
self.clearml.task.update_output_model(model_path=str(best if best.exists() else last),
name='Best Model')
if self.clearml and not self.opt.evolve:
self.clearml.task.update_output_model(model_path=str(best if best.exists() else last), name='Best Model')

def on_params_update(self, params):
def on_params_update(self, params: dict):
# Update hyperparams or configs of the experiment
# params: A dict containing {param: value} pairs
if self.wandb:
self.wandb.wandb_run.config.update(params, allow_val_change=True)

Expand Down

0 comments on commit 67d6832

Please sign in to comment.