示例#1
0
def multi_driver_training(options):
    """ Train model using all drivers' data in the given datapath."""
    print("Loading data...")
    dataset = load_all(options)

    print("Building model and compiling functions...")
    net = models.cnn_1(options, output_size=len(dataset['label_map']))
    # net = models.softmax_only(output_size=len(dataset['label_map']))

    print("Starting training...")
    start_time = time.time()
    try:
        train_loop(dataset['train_data'], dataset['val_data'], net, options)
        print('Training Complete...')
    except KeyboardInterrupt:
        print('Keyboard Interrupt...')
    end_time = time.time()

    print('--------------------')
    print('   Saving model, check logs for results.\n'
          '   Time taken: {0}\n'
          .format(end_time - start_time))

    utils.save_model(model=get_all_param_values(net), options=options)
    return net
示例#2
0
def _train_single(driver_index, dataset, options):
    print('Building model and compiling functions...')
    net = models.cnn_1(options, output_size=2)
    # net = models.softmax_only(output_size=len(dataset['label_map']))
    train_labels = (dataset['train_data']['y'] == driver_index)
    val_labels = (dataset['val_data']['y'] == driver_index)
    assert(train_labels.dtype == bool)
    assert(val_labels.dtype == bool)
    driver_dataset = dict(train_data=dict(x=dataset['train_data']['x'], y=train_labels),
                          val_data=dict(x=dataset['val_data']['x'], y=val_labels))
    train_loop(driver_dataset['train_data'], driver_dataset['val_data'], net, options)
    return net