zhongyy/Face-Transformer

visualize the data

mtk380 opened this issue · 2 comments

Maybe the data is converted to bin files for faster dataloader, but I am confused about how to visualize the data such as the figure in your paper.

You can convert the bin to jpg.

qqice commented
import torch

from datetime import datetime
import matplotlib.pyplot as plt
plt.switch_backend('agg')
import numpy as np
from PIL import Image
import mxnet as mx
import io
import os, pickle, sklearn
import time
from IPython import embed


def load_bin(path, image_size=[112,112]):
    bins, issame_list = pickle.load(open(path, 'rb'), encoding='bytes')
    data_list = []
    for flip in [0,1]:
        data = torch.zeros((len(issame_list)*2, 3, image_size[0], image_size[1]))
        data_list.append(data)
    for i in range(len(issame_list)*2):
        _bin = bins[i]
        img = mx.image.imdecode(_bin)
        if img.shape[1]!=image_size[0]:
            img = mx.image.resize_short(img, image_size[0])
        img = mx.nd.transpose(img, axes=(2, 0, 1))
        for flip in [0,1]:
            if flip==1:
                img = mx.ndarray.flip(data=img, axis=2)
            img_pil = Image.fromarray(img.asnumpy().astype(np.uint8).transpose(1,2,0))
            img_pil.save('./lfw/'+str(i)+'_'+str(flip)+'.jpg')
            data_list[flip][i][:] = torch.tensor(img.asnumpy())
        if i%1000==0:
            print('loading bin', i)
    print(data_list[0].shape)
    return data_list, issame_list

datalist, issamelist = load_bin("eval/lfw.bin")
print(len(issamelist))

I've modified the code so that it can extract the bin file to thousands of jpgs.
Hope that helps.