Exemplo n.º 1
0
                try:
                    mesh, stats_dict = out
                except TypeError:
                    mesh, stats_dict = out, {}

                mesh.export(
                    os.path.join(
                        out_dir, 'vis',
                        '{}_{}_{}.off'.format(it, data_vis['category'],
                                              data_vis['it'])))

        # Save checkpoint
        if (checkpoint_every > 0 and (it % checkpoint_every) == 0):
            print('Saving checkpoint')
            checkpoint_io.save('model.pt',
                               epoch_it=epoch_it,
                               it=it,
                               loss_val_best=metric_val_best)

        # Backup if necessary
        if (backup_every > 0 and (it % backup_every) == 0):
            print('Backup checkpoint')
            checkpoint_io.save('model_%d.pt' % it,
                               epoch_it=epoch_it,
                               it=it,
                               loss_val_best=metric_val_best)
        # Run validation
        if validate_every == -1:
            #if (validate_every > 0 and (it % validate_every) == 0) or (it0 + 1 == it):
            eval_dict = trainer.evaluate(val_loader)
            metric_val = eval_dict[model_selection_metric]
            print('Validation metric (%s): %.4f' %
                try:
                    mesh, stats_dict = out
                except TypeError:
                    mesh, stats_dict = out, {}

                mesh.export(
                    os.path.join(
                        out_dir, 'vis',
                        '{}_{}_{}.off'.format(it, data_vis['category'],
                                              data_vis['it'])))

        # Save checkpoint
        if (checkpoint_every > 0 and (it % checkpoint_every) == 0):
            print('Saving checkpoint')
            checkpoint_io.save(f'{model_name}.pt',
                               epoch_it=epoch_it,
                               it=it,
                               loss_val_best=metric_val_best)

        # Backup if necessary
        if (backup_every > 0 and (it % backup_every) == 0):
            print('Backup checkpoint')
            checkpoint_io.save(f'{model_name}_{it}.pt',
                               epoch_it=epoch_it,
                               it=it,
                               loss_val_best=metric_val_best)
        # Run validation
        if (validate_every > 0 and
            (it % validate_every) == 0) or (it0 + 1 == it):
            eval_dict = trainer.evaluate(val_loader)
            metric_val = eval_dict[model_selection_metric]
            print('Validation metric (%s): %.4f' %