我正在上初学者神经网络课,而且确实很挣扎。
我的图像数据集不够大,无法用来训练我的网络,因此我试图对其进行增强(旋转/噪声添加等),并将增强后的图像添加到原始图像集中。我正在遵循在Medium上找到的代码:https://medium.com/@thimblot/data-augmentation-boost-your-image-dataset-with-few-lines-of-python-155c2dc1baec
但是,我遇到了ValueError: Could not find a format to read the specified file in mode 'i'
不确定此错误的含义或解决方法。任何帮助将不胜感激。
import random
from scipy import ndarray
import skimage as sk
from skimage import transform
from skimage import util
path1 = "/Users/.../"
path2 = "/Users/.../"
listing = os.listdir(path1)
num_files_desired = 1000
image = [os.path.join(path2, f) for f in os.listdir(path2) if os.path.isfile(os.path.join(path2, f))]
num_generated_files = 0
while num_generated_files <= num_files_desired:
image_path = random.choice(image)
image_to_transform = sk.io.imread(image_path)
137 if format is None:
138 raise ValueError(
--> 139 "Could not find a format to read the specified file " "in mode %r" % mode
140 )
141
ValueError: Could not find a format to read the specified file in mode 'i'
我几乎看不到任何可能性。在传递给他们之前。我想表达您的错误。它基本上是sk.io.imread()
无法读取图像的指示。让我谈谈可能要做的事情:
您的[os.path.join(path2, f) for f in os.listdir(path2) if os.path.isfile(os.path.join(path2, f))]
部分可能无法正确给出图像路径。您必须手动更正。如果是这样,您可以手动指定确切的文件夹,而无需执行此类循环。只需使用os.listdir()
并手动读取文件即可。
您也可以使用glob
来读取具有相同扩展名的文件,例如.jpg
或其他内容。
您的文件可能已损坏。您可以简单地通过使用PIL
消除它们,并像PIL
一样先使用image = Image.open()
读取图像,然后使用image.verify()
方法。
尝试阅读有关sk.io.imread(filename, plugin=''
的插件部分可能会解决您的问题。
希望有帮助。