Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

visualize the data #31

Open
mtk380 opened this issue May 20, 2022 · 2 comments
Open

visualize the data #31

mtk380 opened this issue May 20, 2022 · 2 comments

Comments

@mtk380
Copy link

mtk380 commented May 20, 2022

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.

@zhongyy
Copy link
Owner

zhongyy commented May 29, 2022

You can convert the bin to jpg.

@qqice
Copy link

qqice commented Jun 7, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants