ValueError:检查输入时出错:期望input_44有4个维度,但得到的形状为数组(0,1)

时间:2017-11-07 13:05:27

标签: python-3.x tensorflow neural-network keras conv-neural-network

我是CNN,keras和tf的新手。我正在尝试为keras 2.0构建SqueezNet,如此处所示https://github.com/DT42/squeezenet_demo。它对我不起作用,所以我只是尝试只创建一个层网络并再次失败。下面是一层的代码。

作为输入,我使用带有2个等级的白色黑色图像90 * 90。

我有点失落,因为我尝试过并阅读了很多不同的东西,但不知道如何解决这个问题。

import h5py
from keras.models import Model
from keras.layers import Input, Activation, Concatenate
from keras.layers import Flatten, Dropout, Dense
from keras.layers import Conv2D, MaxPooling2D
from keras.layers import AveragePooling2D
from keras import backend as K

import numpy as np
import cv2
import glob
from sklearn.model_selection import train_test_split





class_names = {
        "class_A": 0,
        "class_B": 1
}

#all imgs in one file
X = list()
y = list()

for img_folder in ["class_A", "class_B"]:
    for img in glob.glob("path" + img_folder +  "*.jpg"):
        input_img = cv2.imread(img)
        X.append(input_img)
        y.append(class_names[img_folder])

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25)

input_img = Input(shape=(90,90,1))
b = Dense(32)(input_img)
model = Model(inputs=input_img, outputs=b)
print(model.summary())


model.compile(optimizer='adam',
              loss='binary_crossentropy',
              metrics=["accuracy"])


model.fit(X_train, y_train,
          epochs=20, batch_size=32)

0 个答案:

没有答案