我正在尝试使用imageio.imread加载图像。图片列表存储在一个文件中,每行一个图片名称,并将其添加到我尝试加载图片的路径中。这是我的代码:
import numpy as np
import imageio
import locale
def CatvsDogClassifier():
print("Loading images for training ")
locale.getdefaultlocale()
X = np.zeros((750000, 4000))
Fd = open("dog.txt","r", encoding=locale.getdefaultlocale()[1])
Fc = open("cat.txt", "r", encoding=locale.getdefaultlocale()[1])
for line in Fd:
line=line[2:-1]
i = 1
arr = np.zeros((500, 500, 3))
image = 'C:\\Users\\Gianluca\\Desktop\\kittens\\dataset\\trainingset\\dogs\\' + line
print (image)
arr = imageio.imread(image)
arr = np.reshape(750000, 1)
X = np.hstack((X[:, :i], arr, X[:, i:]))
i+=1
print(X)
if __name__ == '__main__':
CatvsDogClassifier()
但是我遇到以下错误:
C:\ Users \ Gianluca \ PycharmProjects \ lreg \ venv \ Scripts \ python.exe C:/Users/Gianluca/PycharmProjects/lreg/main.py加载图像 训练C:\ Users \ Gianluca \ Desktop \ kitten \ dataset \ trainingset \ dogs \ d g。 1。 j回溯(最近一次通话):文件 “ C:/Users/Gianluca/PycharmProjects/lreg/main.py”,第26行,在 CatvsDogClassifier()文件“ C:/Users/Gianluca/PycharmProjects/lreg/main.py”,第18行,在 CatvsDogClassifier arr = imageio.imread(image)文件“ C:\ Users \ Gianluca \ PycharmProjects \ lreg \ venv \ lib \ site-packages \ imageio \ core \ functions.py”, 第221行,未读 reader = read(uri,格式,“ i”,** kwargs)文件“ C:\ Users \ Gianluca \ PycharmProjects \ lreg \ venv \ lib \ site-packages \ imageio \ core \ functions.py”, 第130行,在get_reader中 request = Request(uri,“ r” +模式,** kwargs)文件“ C:\ Users \ Gianluca \ PycharmProjects \ lreg \ venv \ lib \ site-packages \ imageio \ core \ request.py”, 第126行,在 init self._parse_uri(uri)文件“ C:\ Users \ Gianluca \ PycharmProjects \ lreg \ venv \ lib \ site-packages \ imageio \ core \ request.py”, _parse_uri中的第252行 如果(不是os.path.exists(fn))和(在EXAMPLE_IMAGES中为fn):文件“ C:\ Users \ Gianluca \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ genericpath.py”, 存在的第19行 os.stat(path)ValueError:stat:路径中嵌入空字符
以退出代码1完成的过程