forked from harpArk614/3d-pose-warping
-
Notifications
You must be signed in to change notification settings - Fork 1
/
extracting_dataset.py
86 lines (64 loc) · 2.03 KB
/
extracting_dataset.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import numpy as np
import tensorflow as tf
import pickle
import matplotlib.pyplot as plt
from matplotlib import image
import glob
import os
from PIL import Image
from numpy import asarray
import PIL
import pathlib
import tensorflow_datasets as tfds
# import tensorflow.keras.datasets.cifar10 as cf
!unzip '/content/drive/MyDrive/DeepFashion/In-shop Clothes Retrieval Benchmark/Img/img.zip'
infile = open('/content/drive/MyDrive/poses_fashion3d.pkl','rb')
poses = pickle.load(infile)
#Function For Converting image into numpy array
def img_to_tensor (path):
# load the image
image = Image.open(path)
# convert image to numpy array
data = asarray(image)
# print(type(data))
# # summarize shape
# print(data.shape)
# # create Pillow image
# image2 = Image.fromarray(data)
# print(type(image2))
# # summarize image details
# print(image2.mode)
# print(image2.size)
data.reshape(256,256,3)
return data
data = {}
for n in poses:
for i in poses[n]:
#data_men[i] = {}
for j in poses[n][i]:
#data_men[i][j]={}
for k in poses[n][i][j]:
#data_men[i][j][k]={}
for l in poses[n][i][j][k]:
path = '/content/img/'+n+'/'+i+'/'+j+'/'+k+'_'+l+'.jpg'
x = img_to_tensor(path)
data.update({path : x})
data_pose={}
for n in poses:
for i in poses[n]:
for j in poses[n][i]:
for k in poses[n][i][j]:
for l in poses[n][i][j][k]:
#for m in poses[n][i][j][k][l]:
path = '/content/img/'+n+'/'+i+'/'+j+'/'+k+'_'+l+'.jpg'
data_pose.update({path : poses[n][i][j][k][l]})
joint_order=['neck', 'nose', 'lsho', 'lelb', 'lwri', 'lhip', 'lkne', 'lank', 'rsho', 'relb', 'rwri', 'rhip', 'rkne', 'rank', 'leye', 'lear', 'reye', 'rear', 'pelv']
def give_name_to_keypoints(array, joint_order):
res = {}
for i, name in enumerate(joint_order):
res[name] = array[i]
return res
data_with_joints={}
for path,image in data.items():
array=data_pose.get(path)
data_with_joints[path]=give_name_to_keypoints(data_pose.get(path), joint_order)