Issue
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
I'm using tensorflow 2.8.0 and spyder from anaconda3
Thanks
Solution
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.
Answered By - Crackerslover
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.