简体   繁体   English

PermissionError:[Errno 13] 权限被拒绝:“。”

[英]PermissionError: [Errno 13] Permission denied: '.'

I tried to run this code below我尝试在下面运行此代码

import keras
import tensorflow as tf
from keras.preprocessing import image

fnames = sorted([os.path.join(train_cats_dir, fname) for
             fname in os.listdir(train_cats_dir)])

img_path = fname[3]

img = tf.keras.preprocessing.image.load_img(img_path, target_size=(150, 150))

However, I got the error like this.但是,我得到了这样的错误。

In [15]: img = tf.keras.preprocessing.image.load_img(img_path, target_size=(150, 150))
Traceback (most recent call last):

Input In [15] in <cell line: 1>
img = tf.keras.preprocessing.image.load_img(img_path, target_size=(150, 150))

File C:\Anaconda3\lib\site-packages\keras\preprocessing\image.py:313 in load_img
return image.load_img(path, grayscale=grayscale, color_mode=color_mode,

File C:\Anaconda3\lib\site-packages\keras_preprocessing\image\utils.py:113 in load_img
with open(path, 'rb') as f:

PermissionError: [Errno 13] Permission denied: '.'

The error occurred when I run the last line img当我运行最后一行 img 时发生错误

I'm using tensorflow 2.8.0 and spyder from anaconda3我正在使用来自 anaconda3 的 tensorflow 2.8.0 和 spyder

Thanks谢谢

I couldn't figure out what is the exact problem of it (Maybe version issue I believe), but I changed the code like below and it worked well.我无法弄清楚它的确切问题是什么(我相信可能是版本问题),但我更改了如下代码并且效果很好。

import keras.utils

fnames = sorted([os.path.join(train_cats_dir, fname) for
             fname in os.listdir(train_cats_dir)])

img_path = fnames[3]

img = keras.utils.load_img(img_path, target_size=(150, 150))

Importing keras.utils only solved it.导入keras.utils只能解决它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM