问题描述
import os
import numpy as np
from keras.preprocessing.image import load_img,img_to_array
filePath = 'Petimages/'
photos,labels = list(),list()
width = 100
height = 100
counter = 0
for folder in os.listdir(filePath):
main = os.listdir(filePath + folder)
for file in os.listdir(filePath + folder):
print(filePath + folder)
counter = counter + 1
try:
if folder == 'Cat':
output = 1.0
else:
output = 0.0
photo = load_img(filePath + folder + '/' + file,target_size=(width,height))
photo = img_to_array(photo)
photos.append(photo)
labels.append(output)
except:
break
photos = np.asarray(photos)
labels = np.asarray(labels)
print(photos.shape,labels.shape)
#np.save('CatDogPhotos.npy',photos)
#np.save('CatDogLabels.npy',labels)
输出: (10685,100,3) (10685,)
我正在尝试加载典型的 Cat/Dog 数据集。但是,使用此代码,我只能加载 10685 张照片的数组,而不是所有 25000 张图像。
我不明白为什么会这样。任何人都可以帮忙对此发表评论吗?非常感谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)