[英]Errno 13 while Transfer-learning Inception v3
So I just learned python a couple of weeks ago, and I'm new to tensorflow.所以几周前我刚刚学习了 python,我是 tensorflow 的新手。 But I need to fine-tune the inception model.
但我需要微调初始模型。 While trying to follow some tutorials, when I finally started to see some light, I got this horrible error that I can´t get rid of.
在尝试遵循一些教程时,当我终于开始看到一些曙光时,我遇到了这个我无法摆脱的可怕错误。 Here is the part of the code that has the error:
这是有错误的代码部分:
import matplotlib.pyplot as plt
train_dir=r'C:\tf_files'
image_paths=train_dir
images = [plt.imread(train_dir) for path in image_paths]
def plot_images(images, cls_true, cls_pred=None, smooth=True):
assert len(images) == len(cls_true)
# Create figure with sub-plots.
fig, axes = plt.subplots(3, 3)
# Adjust vertical spacing.
if cls_pred is None:
hspace = 0.3
else:
hspace = 0.6
fig.subplots_adjust(hspace=hspace, wspace=0.3)
# Interpolation type.
if smooth:
interpolation = 'spline16'
else:
interpolation = 'nearest'
for i, ax in enumerate(axes.flat):
# There may be less than 9 images, ensure it doesn't crash.
if i < len(images):
# Plot image.
ax.imshow(images[i],
interpolation=interpolation)
# Name of the true class.
cls_true_name = class_names[cls_true[i]]
# Show true and predicted classes.
if cls_pred is None:
xlabel = "True: {0}".format(cls_true_name)
else:
# Name of the predicted class.
cls_pred_name = class_names[cls_pred[i]]
xlabel = "True: {0}\nPred: {1}".format(cls_true_name, cls_pred_name)
# Show the classes as the label on the x-axis.
ax.set_xlabel(xlabel)
# Remove ticks from the plot.
ax.set_xticks([])
ax.set_yticks([])
# Ensure the plot is shown correctly with multiple plots
# in a single Notebook cell.
plt.show()
and this is what the terminal spits:这就是终端吐出来的:
Traceback (most recent call last):
File "C:/Users/Shangai/PycharmProjects/PSai/Testing.py", line 14, in <module>
images = [plt.imread(train_dir) for path in image_paths]
File "C:/Users/Shangai/PycharmProjects/PSai/Testing.py", line 14, in <listcomp>
images = [plt.imread(train_dir) for path in image_paths]
File "C:\Users\Shangai\AppData\Local\conda\conda\envs\PSAI\lib\site-packages\matplotlib\pyplot.py", line 2152, in imread
return matplotlib.image.imread(fname, format)
File "C:\Users\Shangai\AppData\Local\conda\conda\envs\PSAI\lib\site-packages\matplotlib\image.py", line 1359, in imread
with Image.open(fname) as image:
File "C:\Users\Shangai\AppData\Local\conda\conda\envs\PSAI\lib\site-packages\PIL\Image.py", line 2609, in open
fp = builtins.open(filename, "rb")
PermissionError: [Errno 13] Permission denied: 'C:\\tf_files'
I basically need a way to make an image an array, but I can´t figure it out.我基本上需要一种方法来使图像成为数组,但我无法弄清楚。 Any help would be appreciated, thank you so much.
任何帮助将不胜感激,非常感谢。 Peace!
和平!
-I'm using pycharm with an anaconda environment- -我在 anaconda 环境中使用 pycharm-
EDIT: You called imread
for a directory, which is actually not an image.编辑:您为一个目录调用了
imread
,该目录实际上不是一个图像。 Are your images in C:\\tf_files
?你的图片在
C:\\tf_files
吗? If so, use os.listdir()
to get ALL (including non-image) files within a directory.如果是这样,请使用
os.listdir()
获取目录中的所有(包括非图像)文件。 So your code (should be) like this:所以你的代码(应该)是这样的:
train_dir=r'C:\tf_files' # The directory contains images
image_paths=os.listdir(train_dir) # Get the image file only, you can check by checking its extension
images = [plt.imread(train_dir) for path in image_paths]
There is one more thing: The Permission denied
error is raised, which is confused to me.还有一件事:引发了
Permission denied
错误,这让我感到困惑。 If my answer help you solve the problem, which mean the error is not due to ownership, so I have no idea why this Permission denied
happen.如果我的回答可以帮助您解决问题,这意味着错误不是由所有权引起的,所以我不知道为什么会发生此
Permission denied
。
This is the problem PermissionError: [Errno 13] Permission denied: 'C:\\\\tf_files'
这是问题
PermissionError: [Errno 13] Permission denied: 'C:\\\\tf_files'
Do you have access to C:\\\\tf_files
directory?您是否有权访问
C:\\\\tf_files
目录? Try to gain ownership, or just edit the path to somewhere you have access尝试获得所有权,或者只是编辑您有权访问的某个地方的路径
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.