How can I save models after each epoch so that I can pick the best model with lowest loss for testing? This is my training loop:
  # get the model using our helper function
    model = get_model_instance_segmentation(num_classes)
  # move model to the right device
    model.to(device)
    PATH = 'home/Train/ArT_dataset/models/'
    ml =[] 
    vl = []
    for epoch in range(num_epochs):
        # train for one epoch, printing every 10 iterations
        loss_value = train_one_epoch(model, optimizer, data_loader, device, epoch, print_freq=10)
        ml.append(loss_value)
        # update the learning rate
        lr_scheduler.step()
        # evaluate on the test dataset
        #evaluate(model, data_loader_test, device=device)
        #val_loss = eval_forward(model, data_loader_val, device=device)
        val_loss  = evaluate_loss(model, data_loader_val, device=device)
        #print(val_loss)
        # val_loss = evaluate_loss(model,data_loader_val, device)
        vl.append(val_loss)
        torch.save(model, PATH)
    print(ml,vl)
    draw_loss(ml,vl)
error says me:
FileNotFoundError: [Errno 2] No such file or directory: 'home/Train/ArT_dataset/models/'
I followed this: https://stackoverflow.com/a/56119670/15147370 but nothing. +
And tried with this:
torch.save(model.state_dict(), os.path.join(PATH, 'epoch-{}.pt'.format(epoch)))
and the same error I got:
FileNotFoundError: [Errno 2] No such file or directory: 'home/Train/ArT_dataset/models/epoch-0.pt'
Please can somebody help
