[英]How to get rid Error Input 0 of layer "sequential_2" is incompatible with the layer: expected shape=(None, 32, 1200), found shape=(None, 1148)
i am trying to do a text classification using ANN.我正在尝试使用 ANN 进行文本分类。 i used keras python which i got from inte.net to solve it.我使用从 inte.net 获得的 keras python 来解决它。 the number of words on my data is 1148 but I rounded it to 1200 for input_shape.我的数据中的单词数是 1148,但我将其四舍五入为 1200 for input_shape。 the code is as follows:代码如下:
#Arsitektur ANN
model = Sequential()
model.add(Dense(units = 100, activation = 'sigmoid', input_shape=(32, 1200)))
model.add(Dense(units = 2, activation = 'sigmoid'))
opt = Adam (learning_rate=0.001)
model.compile(loss = 'binary_crossentropy', optimizer = opt,
metrics = ['accuracy'])
print(model.summary())
next I included the hyperparameter with the following code:接下来,我将超参数包含在以下代码中:
# Hyperparameter
epochs= 100
batch_size= 32
es = EarlyStopping(monitor="val_loss",mode='min',patience=10)
model_prediction = model.fit(arr_Train_X_Tfidf, Train_Y, epochs=epochs,
batch_size=batch_size, verbose=1,
validation_split=0.1, callbacks =[es])
but get the following error:但出现以下错误:
/usr/local/lib/python3.8/dist-packages/keras/engine/training.py in tf__train_function(iterator)
13 try:
14 do_return = True
---> 15 retval_ = ag__.converted_call(ag__.ld(step_function), (ag__.ld(self), ag__.ld(iterator)), None, fscope)
16 except:
17 do_return = False
ValueError: in user code:
File "/usr/local/lib/python3.8/dist-packages/keras/engine/training.py", line 1051, in train_function *
return step_function(self, iterator)
File "/usr/local/lib/python3.8/dist-packages/keras/engine/training.py", line 1040, in step_function **
outputs = model.distribute_strategy.run(run_step, args=(data,))
File "/usr/local/lib/python3.8/dist-packages/keras/engine/training.py", line 1030, in run_step **
outputs = model.train_step(data)
File "/usr/local/lib/python3.8/dist-packages/keras/engine/training.py", line 889, in train_step
y_pred = self(x, training=True)
File "/usr/local/lib/python3.8/dist-packages/keras/utils/traceback_utils.py", line 67, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/usr/local/lib/python3.8/dist-packages/keras/engine/input_spec.py", line 264, in assert_input_compatibility
raise ValueError(f'Input {input_index} of layer "{layer_name}" is '
ValueError: Input 0 of layer "sequential_2" is incompatible with the layer: expected shape=(None, 32, 1200), found shape=(None, 1148)
does anyone know where the problem is?有谁知道问题出在哪里? and how to solve it?以及如何解决? thank you谢谢你
Input shape shouldn't include batch size.输入形状不应包括批量大小。 Please try the following (ie don't specify '32' for input_shape):请尝试以下操作(即不要为 input_shape 指定“32”):
model.add(Dense(units = 100, activation = 'sigmoid', input_shape=(1200)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.