我正在尝试使用带有keras,tensorflow-gpu的python3读取文件名。 代码在这里。 我省略了一些代码。
imgdir_train = './trainval_Animals/train'
imgdir_test = './trainval_Animals/val'
for eachimg in imgs:
if eachimg[0] == '.':
continue
img_path = classpath+'/'+eachimg
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
feature = model.predict(x)
features_all[idx, :] = feature
labels_all.append(eachclass)
images_all.append(eachimg)
idx += 1
Load_img无法正确获取文件路径。 错误在这里。
File "feature_extract.py", line 126, in <module>
main()
File "feature_extract.py", line 101, in main
img = image.load_img(img_path, target_size=(224, 224))
File "C:\Users\dunghwa\AppData\Local\Programs\Python\Python36\lib\site-packages\keras_preprocessing\image.py", line 498, in load_img
img = pil_image.open(path)
File "C:\Users\dunghwa\AppData\Local\Programs\Python\Python36\lib\site-packages\PIL\Image.py", line 2634, in open
fp = builtins.open(filename, "rb")
PermissionError: [Errno 13] Permission denied: './trainval_Animals/val/A_ant'
即使我正确指定了路径,也会发生权限错误。 我该怎么办..?