所以我几周前刚学了python,我对tensorflow还不熟悉。但我需要对inception模型进行微调。当我试着学习一些教程时,当我终于开始看到一些光明时,我犯了一个可怕的错误,我无法摆脱。以下是代码中出现错误的部分:
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()
这就是终点站吐出的东西:
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'
我基本上需要一种方法把一个图像做成一个数组,但我想不出来。 任何帮助都将不胜感激,非常感谢。和平!你知道吗
-我在水蟒环境中使用pycharm-
编辑:您调用了
imread
来获取一个目录,它实际上不是一个图像。你的图像在C:\tf_files
吗?如果是这样,请使用os.listdir()
获取目录中的所有(包括非映像)文件。所以你的代码应该是这样的:还有一件事:引发了
Permission denied
错误,这让我感到困惑。如果我的回答能帮助您解决问题,这意味着错误不是由于所有权引起的,所以我不知道为什么会发生这种情况。你知道吗这就是问题所在
PermissionError: [Errno 13] Permission denied: 'C:\\tf_files'
您有权访问
C:\\tf_files
目录吗?试着获得所有权,或者只是编辑你可以访问的某个地方的路径相关问题 更多 >
编程相关推荐