def train_model(starting_epoch, num_epochs, model, optimizer, criterion, trainloader, testloader, device, weight_file, loss_weights=None): """ Function to train and validate the generator for all epochs. :return: None """ min_loss = 0.0 start_time = time.time() for epoch in range(starting_epoch, num_epochs): print('Training...') training_loop(epoch, num_epochs, model, optimizer, criterion, device, trainloader, loss_weights) print('Validation...') loss = validation_loop(epoch, num_epochs, model, criterion, device, testloader, loss_weights) sms.send('Epoch {} Loss: {}'.format(epoch + 1, loss), "6304876751", "att") if epoch == 0 or loss < min_loss: min_loss = loss torch.save(model.state_dict(), weight_file) sms.send('Weights saved', "6304876751", "att") end_time = time.time() print('Time: {}'.format(end_time - start_time))
def train_model(): """ Function to train and validate the generator for all epochs. :return: None """ min_loss = 0.0 start_time = time.time() for epoch in range(NUM_EPOCHS): print('Training...') training_loop(epoch) print('Validation...') loss = testing_loop(epoch) sms.send('Epoch {} Loss: {}'.format(epoch + 1, loss), "6304876751", "att") if epoch == 0 or loss < min_loss: min_loss = loss torch.save(model.state_dict(), weight_file) sms.send('Weights saved', "6304876751", "att") end_time = time.time() print('Time: {}'.format(end_time - start_time))