Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python神经网络模型_Python_Tensorflow_Keras - Fatal编程技术网

Python神经网络模型

Python神经网络模型,python,tensorflow,keras,Python,Tensorflow,Keras,我花了这么多时间来解决这个问题。如果你能提供任何建议,我们将不胜感激 #define model def nn_model_1(): model = Sequential() model.add(Dense(256, activation='relu')) model.add(Dense(128, activation='relu')) model.add(Dense(64, activation='relu')) model.add(Dens

我花了这么多时间来解决这个问题。如果你能提供任何建议,我们将不胜感激

#define model 
    
def nn_model_1():
    model = Sequential()
    model.add(Dense(256, activation='relu'))
    model.add(Dense(128, activation='relu'))
    model.add(Dense(64, activation='relu'))
    model.add(Dense(32, activation='relu'))
    model.add(Dense(1, activation='softmax'))

# Compile model  
    adam = tf.keras.optimizers.Adam(lr=1e-3)
    model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
    
    return model

# Call function here

model_1 = nn_model_1()

# Fit the model and store the history
history_model_1 = model_1.fit(X_train, 
                              y_train,
                              epochs=30,
                              verbose=1,
                              validation_split=0.2,
                              batch_size=128)
我想拟合模型,但它给了我以下错误。我不知道如何解决这个问题

ValueError: Shapes (None, 10) and (None, 1, 32, 1) are incompatible." 

这是否意味着我必须检查有关大小的初始编码?看起来您缺少验证\u split=0.2和批处理\u size=128之间的逗号,请尝试:

history_model_1 = model_1.fit(X_train, 
                              y_train,
                              epochs=30,
                              verbose=1,
                              validation_split=0.2,
                              batch_size=128)

非常感谢你的回答!我更正了它,但仍然看到一条错误消息。“ValueError:形状(无,10)和(无,1,32,1)不兼容。”这是否意味着我必须检查关于大小的初始编码?最有可能的是,X_train和y_train的形状是什么?如果这是一个分类问题,有多少类?