def prepare_diff_folder(fusion_param): diff_predict_path = fusion_param['renew_pid_path'].replace(ctrl_msg['data_folder_path'], ctrl_msg['data_folder_path'] + '_diff') diff_folder_path = folder(diff_predict_path) safe_mkdir(diff_folder_path) # although copy all info including pid info, but not use in later training shutil.copy(fusion_param['renew_pid_path'], diff_predict_path)
def write_unequal_rand_st_model(fusion_param): # fusion_param = get_fusion_param() rand_answer_path = fusion_param['answer_path'].replace(ctrl_msg['data_folder_path'], ctrl_msg['data_folder_path'] + '_uerand') rand_folder_path = folder(rand_answer_path) safe_mkdir(rand_folder_path) # although copy all info including pid info, but not use in later training shutil.copy(fusion_param['answer_path'], rand_answer_path) rand_path = rand_folder_path + '/renew_pid.log' safe_remove(rand_path) origin_tracks = get_tracks(fusion_param) pid_cnt = len(origin_tracks) origin_pids = map(lambda x: x + 1, range(pid_cnt)) persons_rand_predict_idx_s = [random.sample(origin_pids, pid_cnt) for _ in range(pid_cnt)] viz_pid_path = fusion_param['renew_pid_path'] viz_score_path = fusion_param['renew_ac_path'] viz_pids = read_lines(viz_pid_path) viz_pids = [per_viz_pids.split() for per_viz_pids in viz_pids] viz_scores = read_lines(viz_score_path) viz_scores = [per_viz_scores.split() for per_viz_scores in viz_scores] viz_same_pids = [ [ int(viz_pid) for viz_pid, viz_score in zip(per_viz_pids, per_viz_scores) if float(viz_score) > 0.7 ] for per_viz_scores, per_viz_pids in zip(viz_scores, viz_pids) ] persons_unequal_rand_predict_idx_s = list() for i in range(pid_cnt): diff_persons = list(set(persons_rand_predict_idx_s[i]) ^ set(viz_same_pids[i])) diff_cnt = len(diff_persons) persons_unequal_rand_predict_idx_s.append( random.sample(diff_persons, diff_cnt) ) write_content = '' for rand_predict_idx_s in persons_unequal_rand_predict_idx_s: for rand_predict_idx in rand_predict_idx_s: write_content += str(rand_predict_idx) + ' ' write_content += '\n' write(rand_path, write_content)
def write_rand_pid(fusion_param): # 对每张左图, 随机生成250个右图的pid,相当于一个随机的renew_pid.log,rand_path也会每次都删除,所以不存在缓存 # todo 不一定需要生成250个右图 # fusion_param = get_fusion_param() rand_answer_path = fusion_param['answer_path'].replace(ctrl_msg['data_folder_path'], ctrl_msg['data_folder_path'] + '_rand') rand_folder_path = folder(rand_answer_path) safe_mkdir(rand_folder_path) # although copy all info including pid info, but not use in later training shutil.copy(fusion_param['answer_path'], rand_answer_path) rand_path = rand_folder_path + '/renew_pid.log' safe_remove(rand_path) origin_tracks = get_tracks(fusion_param) pid_cnt = len(origin_tracks) origin_pids = map(lambda x: x+1, range(pid_cnt)) persons_rand_predict_idx_s = [random.sample(origin_pids, pid_cnt) for _ in range(pid_cnt)] write_content = '' for rand_predict_idx_s in persons_rand_predict_idx_s: for rand_predict_idx in rand_predict_idx_s: write_content += str(rand_predict_idx) + ' ' write_content += '\n' write(rand_path, write_content)
def percent_shot_eval(target_path, top_cnt, test_mode=False): global gallery_cnt gallery_cnt = 0 answer_path = folder(target_path) + '/test_tracks.txt' predict_path = target_path answer_lines = read_lines(answer_path) real_pids = [int(answer.split('_')[0]) for answer in answer_lines] def is_shot(line): global line_idx global shot_line_cnt global shot_cnt global predict_cnt global predict_line_cnt global gallery_cnt predict_idx_es = line.split() has_shot = False if len(predict_idx_es) > top_cnt: predict_cnt += top_cnt else: predict_cnt += len(predict_idx_es) if len(predict_idx_es) > 0: predict_line_cnt += 1 # line_idx > 774 means label img, # gallery_idxs[(line_idx - 775)/2] means iseven in gallery, # if iseven is equal, means gallery img if test_mode and line_idx > 774 and (line_idx - 774) % 2 == 1: gallery_cnt += 1 line_idx += 1 return for i, predict_idx in enumerate(predict_idx_es): if i >= top_cnt: break # print(line_idx) if real_pids[int(predict_idx) - 1] == real_pids[line_idx]: if not has_shot: shot_line_cnt += 1 has_shot = True shot_cnt += 1 line_idx += 1 read_lines_and(predict_path, is_shot) global line_idx global shot_line_cnt global shot_cnt global predict_cnt global predict_line_cnt # print('all predict shot(ac1): %f' % (float(shot_cnt) / predict_cnt)) if test_mode: valid_line_cnt = 125 else: valid_line_cnt = 250 shot_rate = shot_line_cnt / float(valid_line_cnt) print('top%d shot: %f' % (top_cnt, shot_rate)) print('gallery cnt: %d' % gallery_cnt) line_idx = 0 shot_cnt = 0 shot_line_cnt = 0 predict_cnt = 0 predict_line_cnt = 0 return shot_rate