【发布时间】:2018-08-03 19:05:37
【问题描述】:
我想将特定目录中的所有 jpg 图像导入我的 python 脚本,但不是一次全部导入,而是每次导入 500 张图像。
一种可能的解决方案如下:
from glob import glob
i = 0
batch= 500
# Read images from file
for filename in glob('Directory/*.jpg'):
i = i + 1
if i % batch == 0:
# apply an algorithm with this data-batch #
这对吗?
有没有更有效的方法来做到这一点?
【问题讨论】:
-
使用迭代器,更适合搭配
iglob:stackoverflow.com/a/5389547/418374