def multimodel_timestep_hist(test_set, optimizer): model_names = [ 'quad-test_t1.345xsig_seed-11-test0f_vehicles-nobike_7-fold_G3-64_adam-lr0.00146-b10.9-b20.999_bs512_epochs600', 'cubic-test_t1.345xsig_seed-11-test0f_vehicles-nobike_7-fold_G3-64_adam-lr0.00146-b10.9-b20.999_bs512_epochs600', 'quartic-test_t1.345xsig_seed-11-test0f_vehicles-nobike_7-fold_G3-64_adam-lr0.00146-b10.9-b20.999_bs512_epochs600', 'quintic-test_t1.345xsig_seed-11-test0f_vehicles-nobike_7-fold_G3-64_adam-lr0.00146-b10.9-b20.999_bs512_epochs600', 'sextic-test_t1.345xsig_seed-11-test0f_vehicles-nobike_7-fold_G3-64_adam-lr0.00146-b10.9-b20.999_bs512_epochs600', ] model_names = [ 'd5_past2-test_t1.345xsig_seed-11-test0_vehicles-nobike_7-fold_G3-64_adam-lr0.00146-b10.9-b20.999_bs512_epochs600', 'd5_past3-test_t1.345xsig_seed-11-test0_vehicles-nobike_7-fold_G3-64_adam-lr0.00146-b10.9-b20.999_bs512_epochs600', 'd5_past5-test_t1.345xsig_seed-11-test0_vehicles-nobike_7-fold_G3-64_adam-lr0.00146-b10.9-b20.999_bs512_epochs600', 'd5_past7-test_t1.345xsig_seed-11-test0_vehicles-nobike_7-fold_G3-64_adam-lr0.00146-b10.9-b20.999_bs512_epochs600', 'quintic-test_t1.345xsig_seed-11-test0f_vehicles-nobike_7-fold_G3-64_adam-lr0.00146-b10.9-b20.999_bs512_epochs600' ] epochs = [550,550,551,550,550] past_frames = [2,3,5,7,10] # x = x.reshape((-1, past_frames*4)) # y = y.reshape((-1, 4, 10, 1)) x, y, set_info = data_extract_1obj.get_kitti_raw_tracklets(np.linspace(0.1, 1.0, 10), sets=test_set, class_types=['Car', 'Van', 'Truck'], past_frames=10) num_samples = y.shape[0] all_ious = np.empty((len(model_names), num_samples, 10)) tau = 1.345 poly_order = 5 for i, model_name in enumerate(model_names): #poly_order = 2 + i x, y, set_info = data_extract_1obj.get_kitti_raw_tracklets(np.linspace(0.1, 1.0, 10), sets=test_set, class_types=['Car', 'Van', 'Truck'], past_frames=past_frames[i]) x = x.reshape((-1, past_frames[i]*4)) y = y.reshape((-1, 4, 10, 1)) weights_path = os.path.join('/playpen/mhudnell_cvpr_2019/mhudnell/maxgan/models', model_name, 'weights/m_weights_epoch-{}.h5'.format(epochs[i])) M = poly_model.get_model_poly(None, poly_order, np.linspace(0.1, 1.0, 10), tau, past_frames[i], optimizer=optimizer, weights_path=weights_path) out = M.predict(x) gen_transforms = out[0] print(weights_path) print(gen_transforms.shape) np.savez( os.path.join(OUTPUT_DIR, "past_{}.npz".format(past_frames[i])), target=y, pred=gen_transforms) ious = np.empty((num_samples, 10)) des = np.empty((num_samples, 10)) for j in range(num_samples): ious[j], des[j] = calc_metrics_all(x[j][-4:], y[j], gen_transforms[j]) all_ious[i] = ious print("ADE:", np.mean(des)) print("FDE:", np.mean(des[:, 9])) print("FIOU:", np.mean(ious[:, 9])) mult_iou_threshold(all_ious)
def run_tests(generator_model, discriminator_model, combined_model, model_name, seed=6, dataset='kitti_tracking'): np.random.seed(seed) if dataset == 'kitti_tracking': all_sets = np.arange(21) test_sets = np.random.choice(all_sets, 3, replace=False) # train_sets = np.setdiff1d(all_sets, test_sets) test_data, test_data_info = data_extract_1obj.get_kitti_data(test_sets) elif dataset == 'kitti_raw_tracklets': all_sets = np.arange(38) test_sets = np.random.choice(all_sets, 8, replace=False) test_data, test_data_info = data_extract_1obj.get_kitti_raw_tracklets(sets=test_sets) # train_sets = np.setdiff1d(all_sets, test_sets) else: raise Exception("`dataset` parameter must be one of: ['kitti_tracking', 'kitti_raw_tracklets']") gan_1obj.test_model_multiple(generator_model, discriminator_model, combined_model, model_name, test_data, test_data_info, dataset)
def get_baseline_data(): # get test sets timepoints = np.linspace(0.1, 1.0, 10) np.random.seed(11) all_sets = np.arange(38) test_sets = np.random.choice(all_sets, (3, 10), replace=False) # get test data (ie X: the normalized bbs and Y: the offset transformations to the 10 future frames) x_val, y_val, val_info = get_kitti_raw_tracklets( timepoints, sets=test_sets[0], class_types=['Car', 'Van', 'Truck'], past_frames=2, offset_t=True) y_val = np.reshape(y_val, (len(y_val), 4, 10, 1)) #print(np.shape(x_val)) #print(np.shape(y_val)) return x_val, y_val
ax2.set_title('+1.0s IoU distributions') fig2.savefig(os.path.join(output_dir, 'd5-poly_past_threshold.png')) for i in range(len(y)): print(i+2, "AUC:", np.sum(y[i]) / 100) if __name__ == '__main__': optimizer = { 'name': 'adam', 'lr': .00146, # default: .001 'beta_1': .9, # default: .9 'beta_2': .999, # default: .999 'decay': 0 # default: 0 } np.random.seed(DATA_SEED) all_sets = np.arange(38) test_sets = np.random.choice(all_sets, (3,10), replace=False) #print(test_sets) x_test, y_test, _ = data_extract_1obj.get_kitti_raw_tracklets(np.linspace(0.1, 1.0, 10), sets=test_sets[0], class_types=['Car', 'Van', 'Truck'], past_frames=PAST_FRAMES, offset_t=OFFSET_T) weights_path = os.path.join(MODEL_DIR, MODEL_NAME, 'weights/m_weights_epoch-{}.h5'.format(EPOCH)) M = poly_model.get_model_poly(None, POLY_ORDER, np.linspace(0.1, 1.0, 10), TAU, PAST_FRAMES, optimizer=optimizer, weights_path=weights_path) get_metrics(M, x_test, y_test) #multimodel_timestep_hist(test_sets[0], optimizer=optimizer)
def train_single(model_specs, train_sets, val_sets, dataset='kitti_tracking'): """Train a single model on the given data""" [ model_name, starting_step, data_cols, label_cols, label_dim, optimizer, w_adv, epochs, batch_size, k_d, k_g, show, output_dir ] = model_specs timepoints = np.linspace(0.1, 1.0, 10) # Get Data if dataset == 'kitti_tracking': ... # train_data, train_data_info = data_extract_1obj.get_kitti_data(train_sets) # val_data, val_data_info = data_extract_1obj.get_kitti_data(val_sets) elif dataset == 'kitti_raw_tracklets': x_train, y_train, train_info = data_extract_1obj.get_kitti_raw_tracklets( timepoints, sets=train_sets, class_types=['Car', 'Van', 'Truck'], past_frames=PAST_FRAMES, offset_t=OFFSET_T) x_val, y_val, val_info = data_extract_1obj.get_kitti_raw_tracklets( timepoints, sets=val_sets, class_types=['Car', 'Van', 'Truck'], past_frames=PAST_FRAMES, offset_t=OFFSET_T) # print(train_data.shape, train_data.shape[0] / (train_data.shape[0] + val_data.shape[0])) # print(val_data.shape, val_data.shape[0] / (train_data.shape[0] + val_data.shape[0])) else: raise Exception( "`dataset` parameter must be one of: ['kitti_tracking', 'kitti_raw_tracklets']" ) # Log hyperparameters steps_per_epoch = len(x_train) // batch_size nb_steps = steps_per_epoch * epochs log_hyperparams(model_name=model_name, output_dir=output_dir, train_sets=train_sets, val_sets=val_sets, epochs=epochs, batch_size=batch_size, k_d=k_d, k_g=k_g, optimizer=optimizer, show=show, dataset=dataset) # Get Model M = poly_model.get_model_poly(output_dir, POLY_ORDER, timepoints, TAU, PAST_FRAMES, optimizer=optimizer) # Train Model model_components = [ model_name, starting_step, data_cols, label_cols, label_dim, # optimizer, M, epochs, batch_size, k_d, k_g, show, output_dir ] # [G_losses, D_losses, val_losses, train_ious, val_ious, train_des, val_des, avg_gen_pred, avg_real_pred] = gan_1obj.training_steps_GAN(x_train, x_val, y_train, y_val, train_info, val_info, model_components) [M_losses, val_losses, train_ious, val_ious, train_des, val_des] = poly_model.train_poly(x_train, x_val, y_train, y_val, train_info, val_info, model_components, PAST_FRAMES) # Save losses save_losses(output_dir, val_losses, val_ious, val_des) # Plot losses plot_loss(model_name, epochs, nb_steps, steps_per_epoch, output_dir, M_losses, val_losses, train_ious, val_ious, train_des, val_des, show_adv=(w_adv != 0.0)) min_smoothl1_idx = np.argmin(val_losses) max_iou_idx = np.argmax(val_ious, axis=0) min_de_idx = np.argmin(val_des, axis=0) final_epoch = len(val_ious) print("Training / Testing completed. Showing test scores:\n") print("Best smoothL1 ({}): {}".format(min_smoothl1_idx + 1, val_losses[min_smoothl1_idx])) print("Best IoU ({}): {}".format(max_iou_idx + 1, val_ious[max_iou_idx])) print("Best DE ({}): {}".format(min_de_idx + 1, val_des[min_de_idx])) print("Final smoothL1 ({}): {}".format(final_epoch, val_losses[-1])) print("Final IoU ({}): {}".format(final_epoch, val_ious[-1])) print("Final DE ({}): {}".format(final_epoch, val_des[-1])) resultsFile = open(os.path.join(model_specs[-1], 'results.txt'), 'w') print("Training / Testing completed. Showing test scores:\n", file=resultsFile) print("Best smoothL1 ({}): {}".format(min_smoothl1_idx + 1, val_losses[min_smoothl1_idx]), file=resultsFile) print("Best IoU ({}): {}".format(max_iou_idx + 1, val_ious[max_iou_idx]), file=resultsFile) print("Best DE ({}): {}".format(min_de_idx + 1, val_des[min_de_idx]), file=resultsFile) print("Final smoothL1 ({}): {}".format(final_epoch, val_losses[-1]), file=resultsFile) print("Final IoU ({}): {}".format(final_epoch, val_ious[-1]), file=resultsFile) print("Final DE ({}): {}".format(final_epoch, val_des[-1]), file=resultsFile) return [val_losses, val_ious, val_des]
print("ADE:", np.mean(des)) print("FDE:", np.mean(des[:, 9])) print("FIOU:", np.mean(ious[:, 9])) if __name__ == '__main__': optimizer = { 'name': 'adam', 'lr': .00146, # default: .001 'beta_1': .9, # default: .9 'beta_2': .999, # default: .999 'decay': 0 # default: 0 } np.random.seed(11) all_sets = np.arange(38) test_sets = np.random.choice(all_sets, (3, 10), replace=False) timesteps = np.linspace(0.1, 1.0, 10) x_test, y_test, _ = get_kitti_raw_tracklets( timesteps, sets=test_sets[0], class_types=['Car', 'Van', 'Truck'], past_frames=PAST_FRAMES, offset_t=OFFSET_T) weights_path = os.path.join( MODEL_DIR, MODEL_NAME, 'weights', 'm_weights_epoch-{}.h5'.format(EPOCH) ) M = get_model_poly(None, POLY_ORDER, timesteps, TAU, PAST_FRAMES, optimizer=optimizer, weights_path=weights_path) save_to_npz(M, x_test, y_test)
g_bb = data_extract_1obj.unnormalize_bb(g_bb, sample_set=sample_set) target = Rect.make_cXcYWH(t_bb[0], t_bb[1], t_bb[2], t_bb[3]) generated = Rect.make_cXcYWH(g_bb[0], g_bb[1], g_bb[2], g_bb[3]) ious[i] = Rect.get_IoU(target, generated) des[i] = Rect.get_DE(target, generated) return ious, des if __name__ == '__main__': # samples, samples_info = data_extract_1obj.get_kitti_data(sets=None) # samples, samples_info = data_extract_1obj.get_kitti_raw_data() xs, ys, samples_info = data_extract_1obj.get_kitti_raw_tracklets( np.linspace(0.1, 1.0, 10)) print(xs.shape) # print(len(ys)) x = xs[0] x_info = samples_info[0] print(x) print(x_info) # drawFrameRects(x_info[0], x_info[1], x_info[2], x, False, None, dataset='kitti_raw', display=True) # drawFrameRects(x_info[0], x_info[1], x_info[2], x, False, None, dataset='kitti_raw_tracklets', display=True) # drawFrameRects(x_info[0], x_info[1], x_info[2], x, True, None, dataset='kitti_raw_tracklets', display=True) # View multiple # for i in range(5):