预期activation_4的尺寸为X,但数组的形状为()

时间:2018-12-08 21:28:47

标签: tensorflow machine-learning keras neural-network

    from sklearn.metrics import f1_score, precision_score, recall_score
    from keras.models import Sequential
    from keras.layers import Activation
    from keras.layers import Dense, Flatten
    from keras.layers import Conv2D, MaxPooling2D
    from keras.callbacks import Callback
    import keras
    from keras.datasets import cifar10
    import numpy as np


    (X_train, y_train), (X_test, y_test) = cifar10.load_data()

    X_train1 = X_train.copy().ravel()
    y_train1 = y_train.copy().ravel()

    X_train2 = np.resize(X_train1, 64*64*500)
    y_train2 = np.resize(y_train1, 64*64*500)

   X_train = X_train2.reshape((-1, 64, 64, 1))
   y_train = y_train2.reshape((-1, 64, 64, 1))


    metrics = Metrics()

    model = Sequential()
    model.add(Conv2D(32, (3, 3), input_shape=(64, 64, 1)))
    model.add(Activation('tanh'))
    model.add(MaxPooling2D(pool_size=(2, 2)))
    model.add(Conv2D(32, (3, 3)))
    model.add(Activation('relu'))
    model.add(MaxPooling2D(pool_size=(2, 2)))
    model.add(Conv2D(64, (3, 3)))
    model.add(Activation('relu'))
    model.add(MaxPooling2D(pool_size=(2, 2)))
    model.add(Flatten())
    model.add(Dense(1))
    model.add(Activation('sigmoid'))

    model.compile(loss=keras.losses.binary_crossentropy,
     optimizer=keras.optimizers.Adam(),
    )

    model.fit(X_train, y_train, epochs=20, batch_size=1024, verbose=1, validation_data=(X_test, y_test), callbacks=[metrics])
    model.save('bushtranser.model')

我对此不感兴趣。 ValueError:检查目标时出错:预期activation_4具有2个维,但数组的形状为(500,64,64,1)。如何解决呢?可以解决此问题的最小更改是可以的,现在并不真的担心模型性能。

1 个答案:

答案 0 :(得分:0)

我可以问你,你想要什么吗?将500个形状从(32、32、1)调整为(64、64、1)的数据用于火车模型?