def test_cps(model, evals, model_type, scaler, features_used): for i in range(int(len(files)*0.8), len(files)): current_file_x = np.load(files[i]) fileName = files[i].split('/')[-1].split('.')[0] current_fps = int(np.round(sio.loadmat(mat_files+fileName+'.mat').get('FPS')[0][0])) normalised_features = scaler.transform(current_file_x) K = np.dot(normalised_features, normalised_features.T) m = get_cps_number(current_file_x.shape[0], current_fps) # avergae 5sec cps cps, scores = cpd_auto(K, m, 1) # cps = np.arange(0,current_file_x.shape[0], current_fps*5, dtype=int) X, _ = create_cuboids(normalised_features, np.zeros([normalised_features.shape[0]]), window_size) preds = model.predict(X) # np.save('../../saved_numpy_arrays/predictions/I3D/MLP/'+fileName+'_'+features_used+'.npy', preds) if model_type =='categorical': preds = np.argmax(preds, axis=1) print(fileName) targets, ks_targets = create_key_shots(preds, cps) np.save('../../saved_numpy_arrays/predictions/I3D/MLP/'+fileName+'_greedy_'+features_used+'.npy', targets) np.save('../../saved_numpy_arrays/predictions/I3D/MLP/'+fileName+'_ks_'+features_used+'.npy', ks_targets) evals.evaluateSumMe(targets, fileName) evals.evaluateSumMe(ks_targets, fileName)
def test_cps(model, model_type, scaler, features_used, test_files): all_cps = [] all_fileNames = [] all_ks_targets = [] for i in range(len(test_files)): current_file_x = np.load(test_files[i]) fileName = test_files[i].split('/')[-1].split('.')[0] current_fps = getFPS_tvSum50(fileName) normalised_features = scaler.transform(current_file_x) K = np.dot(normalised_features, normalised_features.T) m = get_cps_number(current_file_x.shape[0], current_fps) # avergae 5sec cp cps, scores = cpd_auto(K, m, 1) # cps = np.arange(0,current_file_x.shape[0], current_fps*5, dtype=int) X, _ = create_cuboids(normalised_features, np.zeros([normalised_features.shape[0]]), window_size) preds = model.predict(X) # np.save('../../saved_numpy_arrays/predictions/I3D/MLP/'+fileName+'_'+features_used+'.npy', preds) if model_type == 'categorical': preds = np.argmax(preds, axis=1) print(fileName) targets, ks_targets = create_key_shots(preds, cps) all_fileNames.append(fileName) all_cps.append(cps) all_ks_targets.append(ks_targets) sio.savemat( '../../saved_numpy_arrays/TvSum50/predictions/I3D/MLP/' + fileName + '_' + features_used + '.mat', dict(x=preds)) sio.savemat( '../../saved_numpy_arrays/TvSum50/predictions/I3D/MLP/AllData_' + features_used + '_.mat', dict(fileName=all_fileNames, shot_boundaries=all_cps, targets=all_ks_targets))
def test_cps(model, evals, model_type, scaler): f_score1 = [] f_score2 = [] for i in range(int(len(files) * 0.8), len(files)): current_file_x = np.load(files[i]) fileName = files[i].split('/')[-1].split('.')[0] current_fps = int( np.round( sio.loadmat(mat_files + fileName + '.mat').get('FPS')[0][0])) # normalised_features = np.array([power_norm(e) for e in current_file_x]) normalised_features = scaler.transform(current_file_x) K = np.dot(normalised_features, normalised_features.T) m = get_cps_number(current_file_x.shape[0], current_fps) # avergae 5sec cps cps, scores = cpd_auto(K, m, 1) # cps = np.arange(0,current_file_x.shape[0], current_fps*5, dtype=int) X, _ = create_cuboids(normalised_features, np.zeros([normalised_features.shape[0]]), window_size) preds = model.predict(X) # pdb.set_trace() if model_type == 'categorical': preds = np.argmax(preds, axis=1) print(fileName) targets, ks_targets = create_key_shots(preds, cps) # pdb.set_trace() # print(np.count_nonzero(targets)/float(current_file_x.shape[0])) # print(np.count_nonzero(ks_targets)/float(current_file_x.shape[0])) f1_max, f1_mean = evals.evaluateSumMe(targets, fileName) f2_max, f2_mean = evals.evaluateSumMe(ks_targets, fileName) f_score1.append(f1_max) f_score2.append(f2_max) print "greedy mean: ", np.mean(f_score1) print "ks mean: ", np.mean(f_score2)
def test_cps(model_rgb, model_flow, enc_model_rgb, enc_model_flow, evals, model_type, scaler_rgb, scaler_flow, files_rgb, files_flow, mat_files, window_size): rgb = [] flow = [] comb_r = [] comb_f = [] for i in range(int(len(files_rgb) * 0.8), len(files_rgb)): current_file_x_rgb = np.load(files_rgb[i]) current_file_x_flow = np.load(files_flow[i]) fileName = files_rgb[i].split('/')[-1].split('.')[0] current_fps = int( np.round( sio.loadmat(mat_files + fileName + '.mat').get('FPS')[0][0])) print(fileName) normalised_features_flow = scaler_flow.transform(current_file_x_flow) normalised_features_rgb = scaler_rgb.transform(current_file_x_rgb) K = np.dot(normalised_features_flow, normalised_features_flow.T) m = get_cps_number(current_file_x_flow.shape[0], current_fps) # avergae 5sec cps cps, scores = cpd_auto(K, m, 1) cps = add_cps(cps, current_fps) K_rgb = np.dot(normalised_features_rgb, normalised_features_rgb.T) m_rgb = get_cps_number(current_file_x_rgb.shape[0], current_fps) # avergae 5sec cps cps_rgb, scores_rgb = cpd_auto(K_rgb, m_rgb, 1) cps_rgb = add_cps(cps_rgb, current_fps) # cps = np.arange(0,current_file_x.shape[0], current_fps*5, dtype=int) x_rgb, _ = create_cuboids(normalised_features_rgb, np.zeros([normalised_features_rgb.shape[0]]), window_size) x_flow, _ = create_cuboids( normalised_features_flow, np.zeros([normalised_features_flow.shape[0]]), window_size) if model_type == 'AE': x_rgb = enc_model_rgb.predict(x_rgb) x_flow = enc_model_flow.predict(x_flow) preds_rgb = model_rgb.predict(x_rgb) preds_flow = model_flow.predict(x_flow) preds = (preds_rgb + preds_flow) / 2. targets, ks_targets_rgb = create_key_shots(preds_rgb, cps_rgb) targets, ks_targets_flow = create_key_shots(preds_flow, cps) targets, ks_targets_comb_r = create_key_shots(preds_flow, cps_rgb) targets, ks_targets_comb_f = create_key_shots(preds, cps) # np.save('../../saved_numpy_arrays/predictions/I3D/Conv_RNN/'+fileName+'_greedy_'+'.npy', targets) np.save( '../../saved_numpy_arrays/predictions/I3D/Conv_RNN/' + fileName + '_ks_' + '.npy', ks_targets_comb_f) # pdb.set_trace() # evals.evaluateSumMe(targets, fileName) r_max, _ = evals.evaluateSumMe(ks_targets_rgb, fileName) f_max, _ = evals.evaluateSumMe(ks_targets_flow, fileName) comb_r_max, _ = evals.evaluateSumMe(ks_targets_comb_r, fileName) comb_f_max, _ = evals.evaluateSumMe(ks_targets_comb_f, fileName) rgb.append(r_max) flow.append(f_max) comb_r.append(comb_r_max) comb_f.append(comb_f_max) print('rgb: ', np.mean(rgb)) print('flow: ', np.mean(flow)) print('comb rgb - cps: ', np.mean(comb_r)) print('comb flow - cps: ', np.mean(comb_f))
def test_cps(model_rgb, model_flow, enc_model_rgb, enc_model_flow, model_type, scaler_rgb, scaler_flow, files_rgb, files_flow, window_size): all_cps_flow=[] all_cps_rgb=[] all_cps_comb=[] all_fileNames = [] all_ks_targets = [] for i in range(len(files_rgb)): current_file_x_rgb = np.load(files_rgb[i]) current_file_x_flow = np.load(files_flow[i]) fileName = files_rgb[i].split('/')[-1].split('.')[0] current_fps = getFPS_tvSum50(fileName) print(fileName) normalised_features_flow = scaler_flow.transform(current_file_x_flow) normalised_features_rgb = scaler_rgb.transform(current_file_x_rgb) normalised_features_comb = np.concatenate((normalised_features_flow, normalised_features_rgb)) K = np.dot(normalised_features_flow, normalised_features_flow.T) m = get_cps_number(current_file_x_flow.shape[0], current_fps) # avergae 5sec cps cps, scores = cpd_auto(K, m, 1) K_r = np.dot(normalised_features_rgb, normalised_features_rgb.T) m_r = get_cps_number(current_file_x_rgb.shape[0], current_fps) # avergae 5sec cps cps_r, scores_r = cpd_auto(K_r, m_r, 1) # K_comb = np.dot(normalised_features_comb, normalised_features_comb.T) # m_comb = get_cps_number(current_file_x_rgb.shape[0], current_fps) # avergae 5sec cps # cps_comb, scores_comb = cpd_auto(K_comb, m_comb, 1) # cps = add_cps(cps, current_fps) # cps = np.arange(0,current_file_x.shape[0], current_fps*5, dtype=int) x_rgb, _ = create_cuboids(normalised_features_rgb, np.zeros([normalised_features_rgb.shape[0]]), window_size) x_flow, _ = create_cuboids(normalised_features_flow, np.zeros([normalised_features_flow.shape[0]]), window_size) if model_type=='AE': x_rgb = enc_model_rgb.predict(x_rgb) x_flow = enc_model_flow.predict(x_flow) preds_rgb = model_rgb.predict(x_rgb) preds_flow = model_flow.predict(x_flow) if preds_rgb.shape[0] > preds_flow.shape[0]: preds_rgb = preds_rgb[:preds_flow.shape[0]] preds = (preds_rgb+preds_flow) / 2. targets, ks_targets = create_key_shots(preds, cps) # pdb.set_trace() all_fileNames.append(fileName) all_cps_flow.append(cps) all_cps_rgb.append(cps_r) # all_cps_comb.append(cps_comb) all_ks_targets.append(ks_targets) sio.savemat('../../saved_numpy_arrays/TvSum50/predictions/I3D/3D_AE/' + fileName + '_rgb.mat', dict(x=preds_rgb)) sio.savemat('../../saved_numpy_arrays/TvSum50/predictions/I3D/3D_AE/' + fileName + '_flow.mat', dict(x=preds_flow)) sio.savemat('../../saved_numpy_arrays/TvSum50/predictions/I3D/3D_AE/' + fileName + '_combined.mat', dict(x=preds)) sio.savemat('../../saved_numpy_arrays/TvSum50/predictions/I3D/3D_AE/AllData_flow_.mat', dict(fileName = all_fileNames, shot_boundaries=all_cps_flow, targets=all_ks_targets)) sio.savemat('../../saved_numpy_arrays/TvSum50/predictions/I3D/3D_AE/AllData_rgb_.mat', dict(fileName = all_fileNames, shot_boundaries=all_cps_rgb, targets=all_ks_targets))