diff --git a/export.py b/export.py index 7b398fdc4d93..166b5f406a20 100644 --- a/export.py +++ b/export.py @@ -436,8 +436,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.?.?"}, ' diff --git a/utils/loggers/__init__.py b/utils/loggers/__init__.py index 34704b625294..b95a463717f8 100644 --- a/utils/loggers/__init__.py +++ b/utils/loggers/__init__.py @@ -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'))] @@ -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)