Errno 13在传输v3时

2024-04-24 00:28:26 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我几周前刚学了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-


Tags: thenameinimagetruedirtrainplt
1条回答
网友
1楼 · 发布于 2024-04-24 00:28:26

编辑:您调用了imread来获取一个目录,它实际上不是一个图像。你的图像在C:\tf_files吗?如果是这样,请使用os.listdir()获取目录中的所有(包括非映像)文件。所以你的代码应该是这样的:

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]  

还有一件事:引发了Permission denied错误,这让我感到困惑。如果我的回答能帮助您解决问题,这意味着错误不是由于所有权引起的,所以我不知道为什么会发生这种情况。你知道吗


这就是问题所在PermissionError: [Errno 13] Permission denied: 'C:\\tf_files'
您有权访问C:\\tf_files目录吗?试着获得所有权,或者只是编辑你可以访问的某个地方的路径

相关问题 更多 >