首页 > 编程知识 正文

python语言程序设计,python教程

时间:2023-05-03 13:05:35 阅读:40195 作者:2615

I ' vemadeapicklefileusingthefollowing。

来自pil导入图像

import pickle

导入操作系统

导入编号

导入时间

train pixels=numpy.empty ([ 80000,6400 ]

trainlabels=numpy.empty(80000 )。

valid pixels=numpy.empty ([ 10000,6400 ]

可变标签=numpy.empty (10000 ) )。

test pixels=numpy.empty ([ 10408,6400 ]

测试标签=numpy.empty (10408 ) )。

i=0

tr=0

va=0

te=0

for (根、直、文件名) inOS.walk ) Indir1) :

print 'hello '

for f in filenames:

try:

im=image.open (OS.path.join (根,f ) )

Imv=im.load (

x,y=im.size

pixelv=numpy.empty(6400 ) )。

ind=0

foriiinrange(x ) :

forjinrange(y ) :

TEMP=float(imv[j,ii] ) ) ) ) ) ) ) ) ) ) ) ) ) )。

时间=浮动(时间/255.0 ) )。

pixelv[ind]=temp

ind=1

if i40000:

trainpixels[tr]=pixelv

tr=1

elif i45000:

validpixels[va]=pixelv

va=1

else:

testpixels[te]=pixelv

打印str (I ) (t ) str (f ) )。

i=1

except IOError:

连续

output=open('data.pkl ',' wb ' )。

pickle.dump (三线图像,输出) )。

pickle.dump(validimage,output )。

pickle.dump(testimage,output ) )。

but it returns the following error。

utnopersistent _ loadfunctionwasspecified。

itseemslikedatastructureisunmatched,but I can' figure out how it should be .

For reference,thesizeofthepicklefileisover 16gb,with its gzip over 1GB

I ' vefoundthatpicklingandunpicklingissmart。

hereyoudon ' tunpicklethesamewayyoupickle,soitcannotwork.inyourcodeyoupickleobjectsoneaftertheotherinthesamefile.youpickioudethed

If you want to read them back,you have to make sequential reading。

whatyouhavetodoisopenthefileforunpickling,then pickle.loadeachofyourobjectssequentially。

withgzip.open(dataset,' rb ' ) as f:

train_set=cpickle.load(f ) )。

valid_set=cpickle.load(f ) )。

test_set=cpickle.load(f ) )。

youmightwanttotryasimplercodewheretrain _ set,valid_set,test _ set (dothepicklingandunpicklingwithgzip ) aresimpleplepingzip

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。