def get_oracle_summary_self(user_summary): """ create a single ground-truth set of keyframes from multiple user-annotated ones for each video. Args: user_summary: [n_user,n_frame] """ n_user, n_frame = user_summary.shape # [n_user,n_frame] e.g.[15,4494] for video oracle_summary = np.zeros(n_frame) # single ground-truth priority_idx = np.argsort( -(user_summary.sum(axis=0)) ) # [n_frame], the most select frame -> the least select frame(because of "-" sign) best_fscore = 0 for idx in priority_idx: oracle_summary[idx] = 1 # assume fake sum n_user_fscore = np.zeros(n_user) # record of every user to fake sum for usr_i in range(n_user): y_pred = user_summary[usr_i] y_true = oracle_summary fscore = eval_tools.eval_metrics(y_pred, y_true)[2] # only get fscore n_user_fscore[usr_i] = fscore cur_fscore = n_user_fscore.mean() # avg. of each sum to fake sum if cur_fscore > best_fscore: best_fscore = cur_fscore else: oracle_summary[idx] = 0 # assume sum is not real #print("pcshih", best_fscore) return oracle_summary
320) # [1,2,320] -> [2,320] # we only want key frame prob. -> [1] pred_score = torch.softmax(pred_score, dim=0)[1] # [320] #print("epoch:{:0>3d} video_index:{:0>2d} key_frame_score(first20):{}".format(epoch, index, pred_score[:20])) video_name = "video_{}".format(index) video_info = data_file[video_name] # select key shots by video_info and pred_score # pred_summary: [N] binary keyshot N, pred_score_upsample, _, pred_summary = eval_tools.select_keyshots( video_info, pred_score) true_summary_arr = video_info['user_summary'][( )] # shape (n_users,N), summary from some users, each row is a binary vector eval_res = [ eval_tools.eval_metrics(pred_summary, true_summary) for true_summary in true_summary_arr ] # shape [n_user,3],3 for[precision, recall, fscore] #eval_res = np.mean(eval_res, axis=0).tolist() # for tvsum eval_res = np.max(eval_res, axis=0).tolist() # for summe eval_res_avg.append( eval_res ) # [[precision1, recall1, fscore1], [precision2, recall2, fscore2]......] # plot split 0 and first test histogram only save epoch4 and epoch last # if (i==0 and j==1 and (epoch==4 or epoch==EPOCHS-1)): # fig, ax = plt.subplots(nrows=2, ncols=1, figsize=(100, 60)) # ax[0].bar(list(range(320)), pred_score.tolist(), alpha=1.0, width=0.6) # ax[0].set_xlabel('frame_index', fontsize=50) # ax[0].set_ylabel('Probability', fontsize=50) # ax[0].tick_params(axis='both', which='major', labelsize=50)