コード例 #1
0
def train_epochs(args, data_transform):
    training_dataset = DrivingDataset(root_dir=args.train_dir,
                                      categorical=True,
                                      classes=args.n_steering_classes,
                                      transform=data_transform)

    validation_dataset = DrivingDataset(root_dir=args.validation_dir,
                                        categorical=True,
                                        classes=args.n_steering_classes,
                                        transform=data_transform)

    training_iterator = DataLoader(training_dataset,
                                   batch_size=args.batch_size,
                                   shuffle=True,
                                   num_workers=2)
    validation_iterator = DataLoader(validation_dataset,
                                     batch_size=args.batch_size,
                                     shuffle=True,
                                     num_workers=2)
    driving_policy = DiscreteDrivingPolicy(
        n_classes=args.n_steering_classes).to(DEVICE)

    opt = torch.optim.Adam(driving_policy.parameters(), lr=args.lr)
    args.start_time = time.time()

    args.class_dist = get_class_distribution(training_iterator, args)
    best_val_accuracy = 0
    for epoch in range(args.n_epochs):
        print('EPOCH ', epoch)

        train_discrete(driving_policy, training_iterator, opt, args)
        acc = test_discrete(driving_policy, validation_iterator, opt, args)
        if acc >= best_val_accuracy:
            torch.save(driving_policy.state_dict(), args.weights_out_file)
            best_val_accuracy = acc
コード例 #2
0
def main(args):

    data_transform = transforms.Compose([
        transforms.ToPILImage(),
        transforms.ColorJitter(brightness=0.1,
                               contrast=0.1,
                               saturation=0.1,
                               hue=0.1),
        transforms.RandomRotation(degrees=80),
        transforms.ToTensor()
    ])

    training_dataset = DrivingDataset(root_dir=args.train_dir,
                                      categorical=True,
                                      classes=args.n_steering_classes,
                                      transform=data_transform)

    validation_dataset = DrivingDataset(root_dir=args.validation_dir,
                                        categorical=True,
                                        classes=args.n_steering_classes,
                                        transform=data_transform)

    training_iterator = DataLoader(training_dataset,
                                   batch_size=args.batch_size,
                                   shuffle=True,
                                   num_workers=1)
    validation_iterator = DataLoader(validation_dataset,
                                     batch_size=args.batch_size,
                                     shuffle=True,
                                     num_workers=1)
    driving_policy = DiscreteDrivingPolicy(
        n_classes=args.n_steering_classes).to(DEVICE)

    opt = torch.optim.Adam(driving_policy.parameters(), lr=args.lr)
    args.start_time = time.time()

    print(driving_policy)
    print(opt)
    print(args)

    args.class_dist = get_class_distribution(training_iterator, args)

    best_val_accuracy = 0
    for epoch in range(args.n_epochs):
        print('EPOCH ', epoch)
        #
        # YOUR CODE GOES HERE
        #

        # Train the driving policy
        # Evaluate the driving policy on the validation set
        # If the accuracy on the validation set is a new high then save the network weights
        train_discrete(driving_policy, training_iterator, opt, args)
        acc = test_discrete(driving_policy, validation_iterator, opt, args)
        if acc > best_val_accuracy:
            torch.save(driving_policy.state_dict(), args.weights_out_file)
            best_val_accuracy = acc
    return driving_policy
コード例 #3
0
def main(args, driving_policy=None):

    data_transform = transforms.Compose([
        transforms.ToPILImage(),
        transforms.ColorJitter(brightness=0.1,
                               contrast=0.1,
                               saturation=0.1,
                               hue=0.1),
        transforms.RandomRotation(degrees=80),
        transforms.ToTensor()
    ])

    training_dataset = DrivingDataset(root_dir=args.train_dir,
                                      categorical=True,
                                      classes=args.n_steering_classes,
                                      transform=data_transform)

    validation_dataset = DrivingDataset(root_dir=args.validation_dir,
                                        categorical=True,
                                        classes=args.n_steering_classes,
                                        transform=data_transform)

    training_iterator = DataLoader(training_dataset,
                                   batch_size=args.batch_size,
                                   shuffle=True,
                                   num_workers=1)
    validation_iterator = DataLoader(validation_dataset,
                                     batch_size=args.batch_size,
                                     shuffle=True,
                                     num_workers=1)
    if (driving_policy == None):
        print("New policy instantiated.")
        driving_policy = DiscreteDrivingPolicy(
            n_classes=args.n_steering_classes).to(DEVICE)
        args.freeze_last_n_layers = 0

    opt = torch.optim.Adam(filter(lambda p: p.requires_grad,
                                  driving_policy.parameters()),
                           lr=args.lr)
    args.start_time = time.time()

    args.class_dist = get_class_distribution(training_iterator, args)

    best_val_accuracy = 0
    for epoch in range(args.n_epochs):
        print('EPOCH ', epoch)

        train_discrete(driving_policy, training_iterator, opt, args)
        curr_val_accuracy = test_discrete(driving_policy, validation_iterator,
                                          opt, args)
        if (curr_val_accuracy > best_val_accuracy):
            best_val_accuracy = curr_val_accuracy
            torch.save(driving_policy.state_dict(), args.weights_out_file)

    return driving_policy
コード例 #4
0
ファイル: racer.py プロジェクト: chaddy1004/csc2626w21
            scipy.misc.imsave(os.path.join(args.out_dir, 'expert_%d_%d_%f.jpg' % (args.run_id, t, expert_steer)), state)

    env.close()


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--out_dir", help="directory in which to save the expert's data", default='./dataset/train')
    parser.add_argument("--save_expert_actions", type=str2bool,
                        help="save the images and expert actions in the training set",
                        default=False)

    parser.add_argument("--expert_drives", type=str2bool, help="should the expert steer the vehicle?", default=False)
    parser.add_argument("--run_id", type=int,
                        help="Id for this particular data collection run (e.g. dagger iterations)", default=0)
    parser.add_argument("--timesteps", type=int,
                        help="timesteps of simulation to run, up to one full loop of the track", default=100000)
    parser.add_argument("--learner_weights", type=str,
                        help="filename from which to load learner weights for the steering network",
                        default='')
    parser.add_argument("--n_steering_classes", type=int, help="number of steering classes", default=20)

    args = parser.parse_args()

    steering_network = DiscreteDrivingPolicy(n_classes=args.n_steering_classes).to(DEVICE)
    if args.learner_weights:
        print("UAWEH;OEASUGHEA;SOIGHEAS;OGIASH")
        steering_network.load_weights_from(args.learner_weights)

    run(steering_network, args)
コード例 #5
0
    data_transform = transforms.Compose([
        transforms.ToPILImage(),
        transforms.ColorJitter(brightness=0.1,
                               contrast=0.1,
                               saturation=0.1,
                               hue=0.1),
        transforms.RandomRotation(degrees=80),
        transforms.ToTensor()
    ])

    args.weights_out_file = os.path.join(
        "./weights", "learner_{}_weights.weights".format(0))
    train_epochs(args, data_transform)
    cr = []
    for i in range(args.dagger_iterations):

        print('GETTING EXPERT DEMONSTRATIONS')
        args.run_id = i
        current_learner = DiscreteDrivingPolicy(
            n_classes=args.n_steering_classes).to(DEVICE)
        current_learner.load_weights_from(args.weights_out_file, device=DEVICE)
        cross_track_error = run(current_learner, args)[0]
        print(cross_track_error)
        cr.append(cross_track_error)
        print('RETRAINING LEARNER ON AGGREGATED DATASET')
        args.weights_out_file = os.path.join(
            "./weights", "learner_{}_weights.weights".format(i))
        train_epochs(args, data_transform)
    plt.plot(np.arange(args.dagger_iterations), np.array(cr))
    plt.show()
コード例 #6
0
ファイル: dagger.py プロジェクト: chaddy1004/csc2626w21
                                      transform=data_transform)

    validation_dataset = DrivingDataset(root_dir=args.validation_dir,
                                        categorical=True,
                                        classes=args.n_steering_classes,
                                        transform=data_transform)

    training_iterator = DataLoader(training_dataset,
                                   batch_size=args.batch_size,
                                   shuffle=True,
                                   num_workers=0)
    validation_iterator = DataLoader(validation_dataset,
                                     batch_size=args.batch_size,
                                     shuffle=True,
                                     num_workers=0)
    driving_policy = DiscreteDrivingPolicy(
        n_classes=args.n_steering_classes).to(DEVICE)

    opt = torch.optim.Adam(driving_policy.parameters(), lr=args.lr)
    args.start_time = time.time()

    print(driving_policy)
    print(opt)
    print(args)

    best_val_accuracy = 0

    opt = torch.optim.Adam(params=driving_policy.parameters(), lr=args.lr)

    #####
    ## Enter your DAgger code here
    ## Reuse functions in racer.py and train_policy.py