【发布时间】:2020-03-23 08:53:11
【问题描述】:
我一直在尝试从特定路径读取一堆图像,我使用的代码是~
images = [os.path.join(folder_path, f) for f in os.listdir(folder_path) if
os.path.isfile(os.path.join(folder_path, f))]
num_generated_files = 0
while num_generated_files <= num_files_desired:
# random image from the folder
image_path = random.choice(images)
# read image as an two dimensional array of pixels
image_to_transform = sk.io.imread(image_path)
当我尝试使用单个图像时,它工作正常,但是当我使用图像路径获取随机图像时,它正在显示
File "C:\Users\subhr\Anaconda3\lib\site-packages\imageio\core\functions.py", line 182, in get_reader
"Could not find a format to read the specified file " "in mode %r" % mode
ValueError: Could not find a format to read the specified file in mode 'i'
任何想法我做错了什么,任何帮助将不胜感激。
【问题讨论】:
-
在您粘贴的代码中,缩进是错误的(循环不起作用)。尽管如此,尝试打印文件名 - 您可能遇到过不是图像的文件,而是文本或 docx 文件。
-
嘿@VBB 非常感谢您指出,文件夹内有一些网页。另外你为什么说循环不起作用?你能解释一下吗?
-
尝试使用
imagelist = glob("*.png")或者imagelist.extend(glob("*.jpg")) -
python 循环需要缩进 - 您在此处粘贴的代码没有任何缩进。
标签: python anaconda scikit-image data-augmentation