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
def per_driver_train_predict(options): """ Predict output probabilities for each driver. If `options.train` is true, this trains a model""" # TODO: support for predict only # TODO: support for pretrained weights print("Loading data...") dataset = load_all(options) all_outputs = deque([]) for driver_index in range(len(dataset['label_map'])): driver_id = dataset['label_map'][driver_index] print('Working on Driver {0}'.format(driver_id)) net = _train_single(driver_index, dataset, options) utils.save_model(model=get_all_param_values(net), options=options, driver_id=driver_id) print('Training complete for driver {0}, making predictions...'.format(driver_id)) outputs = _predict_single(net, driver_id, options) utils.save_outputs(outputs, options, driver_id=driver_id) all_outputs.extend(outputs) utils.save_outputs(all_outputs, options) return