Esempio n. 1
0
def fusion_dir_prepare(source, target):
    fusion_data_path = '/home/cwh/coding/TrackViz/data/'
    fusion_train_dir = fusion_data_path + '/' + source + '_' + target + '-train'
    fusion_test_dir = fusion_data_path + '/' + source + '_' + target + '-test'
    safe_mkdir(fusion_train_dir)
    safe_mkdir(fusion_test_dir)
    return fusion_train_dir, fusion_test_dir
Esempio n. 2
0
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)
Esempio n. 3
0
def init_strict_img_st_fusion():
    # 全局调度入口,会同时做训练集和测试集上的融合与评分
    fusion_param = get_fusion_param()
    safe_mkdir('data/' + ctrl_msg['data_folder_path'])
    get_predict_delta_tracks(fusion_param)
    # # only get rand model for train dataset
    prepare_rand_folder(fusion_param)
    prepare_diff_folder(fusion_param)

    ctrl_msg['data_folder_path'] = ctrl_msg['data_folder_path'] + '_rand'
    fusion_param = get_fusion_param()
    # 生成随机时空点的时空模型
    get_predict_delta_tracks(fusion_param, random=True)

    ctrl_msg['data_folder_path'] = ctrl_msg['data_folder_path'].replace(
        'rand', 'diff')
    fusion_param = get_fusion_param()
    get_predict_delta_tracks(fusion_param, diff_person=True)

    # 改回非随机的train目录
    ctrl_msg['data_folder_path'] = ctrl_msg['data_folder_path'][:-5]

    # has prepared more accurate ep, en
    print('fusion on training dataset')
    iter_strict_img_st_fusion(on_test=False)
    # 改成测试目录
    print('fusion on test dataset')
    ctrl_msg['data_folder_path'] = ctrl_msg['data_folder_path'][:-4] + 'est'
    safe_mkdir('data/' + ctrl_msg['data_folder_path'])
    iter_strict_img_st_fusion(on_test=True)
Esempio n. 4
0
def split_duke(img_list_path, data_type):
    tracks, camera_cnt = load_train_img_infos(img_list_path)
    mid = calculate_mid_frame(tracks)
    head_tracks = filter(lambda x: x[2] < mid, tracks)
    tail_tracks = filter(lambda x: x[2] > mid, tracks)
    track_name = 'dukehead'
    duke_tracks_realloc(head_tracks, track_name, data_type)
    track_name = 'duketail'
    safe_mkdir('../data/%s' % track_name)
    duke_tracks_realloc(tail_tracks, track_name, data_type)
Esempio n. 5
0
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)
Esempio n. 6
0
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)
Esempio n. 7
0
def duke_tracks_realloc(tracks, track_name, data_type):
    target_list_path = '../data/%s/%s.list' % (track_name, data_type)
    target_track_info_dir_path = '/home/cwh/coding/TrackViz/data/%s' % track_name
    safe_mkdir(target_track_info_dir_path)
    target_track_dir_path = '/home/cwh/coding/%s' % track_name
    safe_mkdir(target_track_dir_path)
    target_track_type_dir_path = '/home/cwh/coding/%s/%s' % (track_name,
                                                             data_type)
    safe_mkdir(target_track_type_dir_path)
    for track in tracks:
        source_img_name = '%04d_c%d_f%07d.jpg' % (int(
            track[0]), track[1], track[2])
        target_img_name = '%05d%07d%03d.jpg' % (int(
            track[0]), track[2], track[1])
        shutil.copyfile(
            '/home/cwh/coding/DukeMTMC-reID/%s/%s' %
            (data_type, source_img_name),
            '%s/%s' % (target_track_type_dir_path, target_img_name))
    safe_remove(target_list_path)
Esempio n. 8
0
def duke_tracks_realloc(tracks, track_name, data_type):
    target_list_path = '../data/%s/%s.list' % (track_name, data_type)
    target_track_info_dir_path = '/home/cwh/coding/TrackViz/data/%s' % track_name
    safe_mkdir(target_track_info_dir_path)
    target_track_dir_path = '/home/cwh/coding/%s' % track_name
    safe_mkdir(target_track_dir_path)
    target_track_type_dir_path = '/home/cwh/coding/%s/%s' % (track_name,
                                                             data_type)
    safe_mkdir(target_track_type_dir_path)
    names = list()
    for track in tracks:
        img_name = '%04d_c%d_f%07d.jpg' % (int(track[0]), track[1], track[2])
        shutil.copyfile(
            '/home/cwh/coding/DukeMTMC-reID/%s/%s' % (data_type, img_name),
            '%s/%s' % (target_track_type_dir_path, img_name))
        names.append(img_name)
        names.append('\n')
    list_stmt = ''.join(names)
    safe_remove(target_list_path)
    write(target_list_path, list_stmt)
Esempio n. 9
0
def get_fusion_param():
    origin_dict = {
        'gt_fusion':
        False,
        'renew_pid_path':
        'data/' + ctrl_msg['data_folder_path'] + '/renew_pid.log',
        'renew_ac_path':
        'data/' + ctrl_msg['data_folder_path'] + '/renew_ac.log',
        'predict_pid_path':
        'data/' + ctrl_msg['data_folder_path'] + '/predict_pid.log',
        'answer_path':
        'data/' + ctrl_msg['data_folder_path'] + '/test_tracks.txt',
        'probe_path':
        '',
        'train_path':
        '',
        'gallery_path':
        '',
        'distribution_pickle_path':
        'data/' + ctrl_msg['data_folder_path'] + '/sorted_deltas.pickle',
        'src_distribution_pickle_path':
        'data/' + ctrl_msg['data_folder_path'].replace('test', 'train') +
        '/sorted_deltas.pickle',
        'persons_deltas_path':
        'data/' + ctrl_msg['data_folder_path'] +
        '/persons_deltas_score.pickle',
        'persons_ap_path':
        'data/' + ctrl_msg['data_folder_path'] + '/persons_ap_scores.pickle',
        'predict_person_path':
        'data/' + ctrl_msg['data_folder_path'] + '/predict_persons.pickle',
        'mid_score_path':
        'data/' + ctrl_msg['data_folder_path'] + '/cross_mid_score.log',
        'eval_fusion_path':
        'data/' + ctrl_msg['data_folder_path'] + '/cross_filter_pid.log',
        'fusion_normal_score_path':
        'data/' + ctrl_msg['data_folder_path'] + '/cross_filter_score.log',
        'ep':
        ctrl_msg['ep'],
        'en':
        ctrl_msg['en'],
        'window_interval':
        ctrl_msg['window_interval'],
        'filter_interval':
        ctrl_msg['filter_interval']
    }
    safe_mkdir('data/' + ctrl_msg['data_folder_path'])

    if '_grid' in ctrl_msg['data_folder_path'] and '_grid_' not in ctrl_msg[
            'data_folder_path']:
        origin_dict['probe_path'] = 'data/grid/grid-cv' + str(
            ctrl_msg['cv_num']) + '-probe.txt'
        origin_dict['train_path'] = 'data/grid/grid-cv' + str(
            ctrl_msg['cv_num']) + '-train.txt'
        origin_dict['gallery_path'] = 'data/grid/grid-cv' + str(
            ctrl_msg['cv_num']) + '-gallery.txt'
    elif '_market' in ctrl_msg[
            'data_folder_path'] and '_market_' not in ctrl_msg[
                'data_folder_path']:
        origin_dict['probe_path'] = 'data/market/probe.txt'
        origin_dict['train_path'] = 'data/market/train.txt'
        origin_dict['gallery_path'] = 'data/market/gallery.txt'
    elif '_dukehead' in ctrl_msg['data_folder_path']:
        origin_dict['probe_path'] = 'data/dukehead/probe.list'
        origin_dict['train_path'] = 'data/dukehead/train.list'
        origin_dict['gallery_path'] = 'data/dukehead/test.list'
    elif '_duketail' in ctrl_msg['data_folder_path']:
        origin_dict['probe_path'] = 'data/duketail/probe.list'
        origin_dict['train_path'] = 'data/duketail/train.list'
        origin_dict['gallery_path'] = 'data/duketail/test.list'
    elif '_duketqtail' in ctrl_msg['data_folder_path']:
        origin_dict['probe_path'] = 'data/duketqtail/probe.list'
        origin_dict['train_path'] = 'data/duketqtail/train.list'
        origin_dict['gallery_path'] = 'data/duketqtail/test.list'
    elif '_dukequerytail' in ctrl_msg['data_folder_path']:
        origin_dict['probe_path'] = 'data/dukequerytail/probe.list'
        origin_dict['train_path'] = 'data/dukequerytail/train.list'
        origin_dict['gallery_path'] = 'data/dukequerytail/test.list'
    elif '_duke' in ctrl_msg['data_folder_path']:
        origin_dict['probe_path'] = 'data/duke/probe.list'
        origin_dict['train_path'] = 'data/duke/train.list'
        origin_dict['gallery_path'] = 'data/duke/test.list'
    if 'train' in ctrl_msg['data_folder_path']:
        origin_dict['answer_path'] = origin_dict['train_path']
    else:
        origin_dict['answer_path'] = origin_dict['probe_path']
    if 'r-' in origin_dict['src_distribution_pickle_path']:
        # use track info before increment
        origin_dict['rand_distribution_pickle_path'] = origin_dict[
            'src_distribution_pickle_path'].replace('r-train', 'train_rand')
    else:
        # use track info after increment
        origin_dict['rand_distribution_pickle_path'] = origin_dict[
            'src_distribution_pickle_path'].replace('train', 'train_rand')
    origin_dict['rand_distribution_pickle_path'] = origin_dict[
        'src_distribution_pickle_path'].replace('train', 'train_rand')
    for (k, v) in update_msg.items():
        origin_dict[k] = v
    return origin_dict