-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
packrgbd.py
41 lines (38 loc) · 1.06 KB
/
packrgbd.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
from rgbd import rgbd
import os
import numpy as np
import cPickle as pickle
from cifar2im import load_CIFAR_batch
def packrgbd(rgbPath,dPath):
ext='.jpg'
datadict=dict()
data=[]
labels=np.loadtxt('label.csv',delimiter=',')
labels=labels.T[1].astype(int)
l=[]
percent=0
for i in range(60000):
percent+=1
if percent%1000==0:
print 'done',percent
dfile=os.path.join(dPath,str(i)+ext)
rgbfile=os.path.join(rgbPath,str(i)+ext)
try:
img=rgbd(dfile,rgbfile)
except:
continue
l.append(labels[i])
#r=im[:,:,0].flatten()
#g=im[:,:,1].flatten()
#b=im[:,:,2].flatten()
#d=im[:,:,3].flatten()
data.append(img.flatten())
datadict['data']=np.array(data)
datadict['labels']=np.array(l)
with open('data_batch','wb') as f:
pickle.dump(datadict,f)
if __name__=="__main__":
packrgbd('images','fayao-dcnf-fcsp-f66628a4a991/results/images')
exit()
for i in load_CIFAR_batch('data_batch'):
print i.shape