Ejemplo n.º 1
0
                    outputs = net(batch_x)

                    loss = criterion(outputs, batch_y)
                    optimizer.zero_grad()

                    loss.backward()
                    optimizer.step()
                    running_loss = loss.item()
                    total_loss += running_loss
                else:
                    break
            print('Epoch %d  RMSE loss: %.4f' %
                  (epoch, total_loss / steps_per_epoch))

        torch.save(net.state_dict(), model_name + '_.pt')
    else:
        net.load_state_dict(torch.load(model_name + '.pt'))

    net.eval()
    with torch.no_grad():
        yhat = []
        # test_y = []
        test_y = pd.read_csv('ch2_final_eval.csv')['steering_angle'].values
        # composed = transforms.Compose([Rescale(image_size),  Preprocess(model_name), ToTensor()])

        # dataset = UdacityDataset(dataset_path, ['HMB1', 'HMB2', 'HMB4', 'HMB5','HMB6'], composed)
        # steps_per_epoch = int(len(dataset) / batch_size)

        # train_generator = DataLoader(dataset, batch_size=batch_size, shuffle=True, num_workers=8)
        test_composed = transforms.Compose(
Ejemplo n.º 2
0
                                    batch_y = batch_y.to(device)

                                    outputs = net(batch_x)
                                    loss = criterion(outputs, batch_y)
                                    optimizer.zero_grad()

                                    loss.backward()
                                    optimizer.step()
                                    running_loss = loss.item()
                                    total_loss += running_loss
                                else:
                                    break
                            print('Epoch %d  RMSE loss: %.4f' %
                                  (epoch, total_loss / steps_per_epoch))

                        torch.save(net.state_dict(),
                                   'adv_training_models/' + advt_model + '.pt')

                net.eval()

                with torch.no_grad():
                    yhat = []
                    # test_y = []
                    test_y = pd.read_csv(
                        'ch2_final_eval.csv')['steering_angle'].values
                    # composed = transforms.Compose([Rescale(image_size),  Preprocess(model_name), ToTensor()])

                    # dataset = UdacityDataset(dataset_path, ['HMB1', 'HMB2', 'HMB4', 'HMB5','HMB6'], composed)
                    # steps_per_epoch = int(len(dataset) / batch_size)

                    # train_generator = DataLoader(dataset, batch_size=batch_size, shuffle=True, num_workers=8)