使用scipy.misc.imread时发生错误

时间:2017-08-07 09:26:54

标签: python machine-learning deep-learning

我正在开发CNN来对图像进行分类,我的图像存储在包含一些子文件夹的文件夹中,现在我想使用scipy.misc.imread读取图像然后输入到tensorflow

我的代码如下:

import numpy as np
import os
import tensorflow as tf
import pandas as pd
from scipy import misc
from sklearn.preprocessing import LabelEncoder



IMAGE_SIZE = 150
data = pd.read_excel('class.xlsx')
root = 'dragonfly'




def label_image(image):
    le = LabelEncoder().fit(data.种) 
    classes = list(le.classes_)
    for i, item in enumerate (classes):
        if os.path.dirname(image) == item:
            label = i
    return label


def create_train_data():
    train_data = []
    for files in os.walk(root):
        for file in files:
            image = misc.imread(file)
            label = label_image(file)
            image = misc.imresize(image, (IMAGE_SIZE, IMAGE_SIZE))
            train_data.append(np.array(image),np.array(label))
    return train_data


train_data = create_train_data()

'dragonfly'是包含我所有图像的文件夹。现在发生错误:

PermissionError:[Errno 13]权限被拒绝:'蜻蜓'

0 个答案:

没有答案