src/similarity/siamese.py [228:257]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            if  BEST_MODEL_METRIC[args.best_model_metric] < best_loss:
                best_loss = BEST_MODEL_METRIC[args.best_model_metric]

                logger.info('Saving the best model: {}'.format(best_loss))
                with open(CHECKPOINT_PATH, 'wb') as f:
                    torch.save(model.state_dict(), f)
                with open(CHECKPOINT_STATE_PATH, 'w') as f:
                    f.write('epoch {:3d} | lr: {:5.2f} | loss {:.8f}'
                            .format(epoch, args.learning_rate, best_loss))

        time_elapsed = time.time() - since
        logger.info('Training complete in {:.0f}m {:.0f}s'.format(time_elapsed // 60, time_elapsed % 60))
        logger.info('Best Loss: {:8f}'.format(best_loss))

        # Load the best saved model.
        with open(CHECKPOINT_PATH, 'rb') as f:
            model.load_state_dict(torch.load(f))

    except: 
        
        # Load the best saved model.
        with open(CHECKPOINT_PATH, 'rb') as f:
            model.load_state_dict(torch.load(f))
        
        if model != None :
            # Move the best model to cpu and resave it
            with open(MODEL_PATH, 'wb') as f:
                torch.save(model.cpu().state_dict(), f)
                   
    return model
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



src/similarity/siamese2.py [181:210]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            if  BEST_MODEL_METRIC[args.best_model_metric] < best_loss:
                best_loss = BEST_MODEL_METRIC[args.best_model_metric]

                logger.info('Saving the best model: {}'.format(best_loss))
                with open(CHECKPOINT_PATH, 'wb') as f:
                    torch.save(model.state_dict(), f)
                with open(CHECKPOINT_STATE_PATH, 'w') as f:
                    f.write('epoch {:3d} | lr: {:5.2f} | loss {:.8f}'
                            .format(epoch, args.learning_rate, best_loss))

        time_elapsed = time.time() - since
        logger.info('Training complete in {:.0f}m {:.0f}s'.format(time_elapsed // 60, time_elapsed % 60))
        logger.info('Best Loss: {:8f}'.format(best_loss))

        # Load the best saved model.
        with open(CHECKPOINT_PATH, 'rb') as f:
            model.load_state_dict(torch.load(f))

    except: 
        
        # Load the best saved model.
        with open(CHECKPOINT_PATH, 'rb') as f:
            model.load_state_dict(torch.load(f))
        
        if model != None :
            # Move the best model to cpu and resave it
            with open(MODEL_PATH, 'wb') as f:
                torch.save(model.cpu().state_dict(), f)
                   
    return model
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



