【问题标题】:Errno 13 while Transfer-learning Inception v3Errno 13 迁移学习 Inception v3
【发布时间】:2018-11-01 01:36:26
【问题描述】:

所以我几周前刚刚学习了 python,而且我是 tensorflow 的新手。但我需要微调初始模型。在尝试遵循一些教程时,当我终于开始看到一些曙光时,我遇到了这个我无法摆脱的可怕错误。以下是有错误的部分代码:

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'

我基本上需要一种将图像制作成数组的方法,但我想不通。 任何帮助将不胜感激,非常感谢。和平!

-我在 anaconda 环境中使用 pycharm-

【问题讨论】:

    标签: python tensorflow matplotlib deep-learning conv-neural-network


    【解决方案1】:

    编辑:您为一个目录调用了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 错误,这让我很困惑。如果我的回答可以帮助您解决问题,这意味着错误不是由于所有权引起的,所以我不知道为什么会发生这种Permission denied


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

    【讨论】:

    • 我确实有访问权限。我正在读那个。是的,我很困惑,因为我在某处读到,在尝试将目录作为文件读取时,问题可能会激增。 Idk 如果这相关
    • 我刚刚编辑了我的答案,因为评论不支持足够的格式
    猜你喜欢
    • 2017-11-23
    • 1970-01-01
    • 2021-09-27
    • 2017-09-14
    • 2020-05-13
    • 2018-10-04
    • 2020-10-31
    • 2019-12-17
    • 1970-01-01
    相关资源
    最近更新 更多