python - os.listdir 显示 25000 个输入,但只能加载 10685 个文件
问题描述
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, 100, 3) (10685,)
我正在尝试加载典型的猫/狗数据集。但是,使用此代码,我只能加载 10685 张照片的数组,而不是全部 25000 张图像。
我无法弄清楚为什么会这样。任何人都可以帮助对此发表评论吗?非常感谢!
解决方案
推荐阅读
- rust - 我是否需要使用某种内部可变性来创建两个弧之间的循环?
- java - Spring 应用程序上下文有我的 bean,但 @autowired 没有看到它
- bash - 将密码存储到变量中
- ruby - 如何指定类型参数
- azure-devops - 具有乘数变量的多配置部署组作业?
- kubernetes - 使 RabbitMQ 持久/持久队列在 Kubernetes pod 重启后存活
- java - 断言主页标题
- asp.net-core - @Html.ActionLink 链接的 id 不起作用
- c# - 错误类 (FluentValidation) 安装失败
- django - 为什么从管理页面的多选中删除选定的值?