Esempio n. 1
0
    )
    test_loss[epoch - 1] = process_epoch(
        "test",
        epoch,
        model,
        loss_fn,
        optimizer,
        dataloader_test,
        batch_preprocessing_fn=None,
        log_interval=1,
    )

    # remember best loss
    is_best = test_loss[epoch - 1] < best_test_loss
    best_test_loss = min(test_loss[epoch - 1], best_test_loss)
    save_checkpoint(
        {
            "epoch": epoch,
            "args": args,
            "state_dict": model.state_dict(),
            "best_test_loss": best_test_loss,
            "optimizer": optimizer.state_dict(),
            "train_loss": train_loss,
            "test_loss": test_loss,
        },
        is_best,
        checkpoint_name,
    )

print("Done!")
Esempio n. 2
0
                                          eval_model_fn,
                                          loss_fn,
                                          optimizer,
                                          dataloader,
                                          batch_preprocessing_fn,
                                          log_interval=1)
    test_loss[epoch - 1] = process_epoch('test',
                                         epoch,
                                         eval_model_fn,
                                         loss_fn,
                                         optimizer,
                                         dataloader_test,
                                         batch_preprocessing_fn,
                                         log_interval=1)

    # remember best loss
    is_best = test_loss[epoch - 1] < best_test_loss
    best_test_loss = min(test_loss[epoch - 1], best_test_loss)
    save_checkpoint(
        {
            'epoch': epoch,
            'args': args,
            'state_dict': model.state_dict(),
            'best_test_loss': best_test_loss,
            'optimizer': optimizer.state_dict(),
            'train_loss': train_loss,
            'test_loss': test_loss,
        }, is_best, checkpoint_name)

print('Done!')
Esempio n. 3
0
    st = time.time()
    val_pck_curepoch = pfdataset_pck(dataloader=dataloader_val_pck,model=model,verbose=False)
    time_valpck = time.time()-st

    train_loss[epoch - 1] = train_loss_curepoch
    val_loss[epoch - 1] = val_loss_curepoch
    val_pcks[epoch-1] = val_pck_curepoch

    # remember best loss
    is_best = val_pcks[epoch - 1] > best_val_pck
    best_val_pck = max(val_pcks[epoch - 1], best_val_pck)
    save_checkpoint({
        'epoch': epoch,
        'args': args,
        'state_dict': model.state_dict(),
        'optimizer' : optimizer.state_dict(),
        'train_loss': train_loss,
        'val_loss': val_loss,
        'val_pck': val_pcks,
        'best_val_pck':best_val_pck,
    }, is_best,checkpoint_name,save_all_epochs=False)

    message = 'Epoch{}\tTrain_loss{:.6f}\tcost time{:.1f}\tVal_loss{:.6f}\tcost time{:.1f}\tVal_pck{:.6f}\tcost time{:.1f}\n'.format\
        (epoch, train_loss_curepoch, time_train, val_loss_curepoch, time_valloss,val_pck_curepoch,time_valpck,)
    print(message)
    with open(log_name, "a") as log_file:
        log_file.write('%s\n' % message)


print('Done!')