예제 #1
0
def viz_per_tracklet(dataset, feature_path, track_path):
    safe_mkdir(dataset)
    result = scipy.io.loadmat(feature_path)
    features = result['ft']
    print('feature shape', features.shape)
    cameras_tracks = pickle_load(track_path)
    tsne = manifold.TSNE(n_components=2, init='pca', random_state=501)
    plt.figure(figsize=(6, 6))
    colors = ['#EE0000', '#00EE00', '#0000EE',
              '#EEEE00', '#EE00EE', '#00EEEE',
              '#EE8800', '#EE0088', '#0088EE', '#8800EE', '#00EE88', '#88EE00']

    for ci, camera_track in enumerate(cameras_tracks):
        if ci > 2:
            break
        x = []
        y = []
        z = []
        info_size = len(camera_track[0])
        print('collect %d infos for c%d' % (info_size, ci + 1))
        frame_idx = 0
        last_track_id = 0
        while frame_idx < info_size and last_track_id < 10:
            info = camera_track[0][frame_idx]
            if info[3] != last_track_id:
                if len(x) > 1:
                    print('tsne on c%d track %d' % (ci + 1, last_track_id))
                    x_tsne = tsne.fit_transform(x)
                    print('norm')
                    x_norm = (x_tsne - x_tsne.min(0)) / (x_tsne.max(0) - x_tsne.min(0))
                    print('plot')
                    color_map = {}
                    color_use_cnt = 0
                    for i in range(x_norm.shape[0]):
                        if not str(y[i]) in color_map:
                            color_use_cnt += 1
                            color_map[str(y[i])] = color_use_cnt
                        plt.text(x_norm[i, 0], x_norm[i, 1], str(y[i]), color=colors[color_map[str(y[i])] % 12],
                                 fontdict={'size': 11})
                        plt.scatter(x_norm[i, 0] + 0.02, x_norm[i, 1] - 0.025, c=colors[color_map[str(y[i])] % 12], linewidths=0., s=100)
                    plt.xticks([])
                    plt.yticks([])
                    plt.tight_layout()
                    plt.savefig(dataset + '/c%dt%d.pdf' % (ci + 1, last_track_id))
                    plt.clf()
                    print('plot')
                    color_map = {}
                    color_use_cnt = 0
                    for i in range(x_norm.shape[0]):
                        if not str(z[i]) in color_map:
                            color_use_cnt += 1
                            color_map[str(z[i])] = color_use_cnt
                        plt.text(x_norm[i, 0], x_norm[i, 1], str(z[i]), color=colors[color_map[str(z[i])] % 12],
                                 fontdict={'size': 11})
                        plt.scatter(x_norm[i, 0] + 0.02, x_norm[i, 1] - 0.025, c=colors[color_map[str(z[i])] % 12], linewidths=0., s=100)
                    plt.xticks([])
                    plt.yticks([])
                    plt.tight_layout()
                    plt.savefig(dataset + '/c%dp%d.pdf' % (ci + 1, last_track_id))
                    plt.clf()
                del x[:]
                del y[:]
                del z[:]
            y.append(info[0])
            z.append(info[-1])
            x.append(features[info[2]])
            last_track_id = info[3]
            if last_track_id > 6:
                break
            frame_idx += 1
예제 #2
0
파일: test.py 프로젝트: ahangchen/deep_reid
else:
    model_structure = ft_net(opt.class_cnt)

if opt.PCB:
    model_structure = PCB(opt.class_cnt)

model = load_network(model_structure)

# Remove the final fc layer and classifier layer
if not opt.PCB:
    model.model.fc = nn.Sequential()
    model.classifier = nn.Sequential()
else:
    model = PCB_test(model)

# Change to test mode
model = model.eval()
if use_gpu:
    model = model.cuda()

# Extract feature
gallery_feature = extract_feature(model,dataloaders['gallery'])
query_feature = extract_feature(model,dataloaders['query'])

# Save to Matlab for check
result = {'gallery_f':gallery_feature.numpy(),'gallery_label':gallery_label,'gallery_cam':gallery_cam,'query_f':query_feature.numpy(),'query_label':query_label,'query_cam':query_cam}
safe_mkdir('eval')
transfer_name = opt.name
safe_mkdir(os.path.join('eval', transfer_name))
scipy.io.savemat(os.path.join('eval', transfer_name, 'pytorch_result.mat'),result)