ValueError:无法将大小为2395575的数组重塑为形状(3,227,227)

时间:2018-02-15 19:43:36

标签: python image keras

我正在尝试在keras中运行以下代码。

虚拟数据集包含大小为227x227x3的图像。火车文件夹中有21个图像,jpg的测试文件夹中有7个图像,当我运行以下代码时出现错误:

ValueError: cannot reshape array of size 2395575 into shape (3,227,227)

我努力想要得到结果,但是任何一个可以建议我解决问题的人都失败了:

def get_pixels(fnames,is_test):
    imgs = loadImages(fnames, is_test)
    pixel_list = []
    for img in imgs:
        img = img.resize((227, 227), Image.ANTIALIAS)
        arr = array(img, dtype="float32")
        pixel_list.append(list(arr))
    return np.array(pixel_list)


(X_train, y_train), (X_test, y_test), label_names = ((X_train, iy_train),
(X_test, y_test),class_names)
X_train = X_train.reshape(-1, 3, 227, 227).astype('float32')
X_test = X_test.reshape(-1, 3, 227, 227).astype('float32')
n_classes = len(label_names)
X_train = X_train[:, :, 16:-16, 16:-16]
X_test = X_test[:, :, 16:-16, 16:-16]


data_mean = X_train.mean(axis=0)
X_train -= data_mean
X_test -= data_mean

get_pixels函数获取图像并调整其大小。

0 个答案:

没有答案