我准备加载cifar集里面的数据,用的是CS231n,里面的代码,但是实际上代码中存在一个很严重的错误,程序如下
import pickle
import numpy as np
import os
datadir='/home/qwe2508/study/cifar-10-batches-bin'
def load_cifar_batch(filename):
with open(filename,'rb') as f :
datadict=pickle.load(f,encoding='bytes')
x=datadict[b'data']
y=datadict[b'labels']
x=x.reshape(10000,3,32,32).transpose(0,2,3,1).astype('float')
y=np.array(y)
return x,y
def load_cifar10(root):
xs=[]
ys=[]
for b in range(1,6):
f=os.path.join(root,'data_batch_%d' % (b,))
x,y=load_cifar_batch(f)
xs.append(x)
ys.append(y)
Xtrain=np.concatenate(xs) #1
Ytrain=np.concatenate(ys)
del x ,y
Xtest,Ytest=load_cifar_batch(os.path.join(root,'test_batch')) #2
return Xtrain,Ytrain,Xtest,Ytest
x_train,y_train,x_test,y_test=load_cifar10(datadir)
如果我的os.path.join,文件不加。bin,那么open函数会报错,没有此文件,如果加了,pickle.load会报错,综合错误。
实在知道怎么解决,求大牛拯救。