简体   繁体   English

如何摆脱“sequential_2”层的错误输入 0 与该层不兼容:预期形状 =(None, 32, 1200),找到形状 =(None, 1148)

[英]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.

相关问题 sequential_2 层的输入 0 与该层不兼容:预期 ndim=3,发现 ndim=2。 收到完整形状:(无,1) - Input 0 of layer sequential_2 is incompatible with the layer: expected ndim=3, found ndim=2. Full shape received: (None, 1) ValueError: 层“sequential_2”的输入 0 与层不兼容:预期形状=(None, 256, 256, 3),发现形状=(None, 1, 256, 256, 3) - ValueError: Input 0 of layer "sequential_2" is incompatible with the layer: expected shape=(None, 256, 256, 3), found shape=(None, 1, 256, 256, 3) ValueError:层“顺序”的输入 0 与层不兼容:预期形状=(无,32,32,3),找到形状=(32,32,3) - ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 32, 32, 3), found shape=(32, 32, 3) ValueError:层“顺序”的输入 0 与层不兼容:预期形状=(无,32,32,3),找到形状=(32,32,3) - ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 32, 32, 3), found shape=(32, 32, 3) ValueError: 层“sequential_32”的输入 0 与层不兼容:预期形状=(None, 3, 1),发现形状=(32, 0, 1) - ValueError: Input 0 of layer "sequential_32" is incompatible with the layer: expected shape=(None, 3, 1), found shape=(32, 0, 1) ValueError:“顺序”层的输入 0 与该层不兼容:预期形状=(无,128,128,3),找到形状=(32,128,3) - ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 128, 128, 3), found shape=(32, 128, 3) ValueError:“顺序”层的输入 0 与层不兼容:预期形状 =(无,223461,5),找到形状 =(无,5) - ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 223461, 5), found shape=(None, 5) ValueError: 层“sequential_1”的输入 0 与层不兼容:预期形状=(None, 60, 1),发现形状=(None, 59, 1) - ValueError: Input 0 of layer "sequential_1" is incompatible with the layer: expected shape=(None, 60, 1), found shape=(None, 59, 1) ValueError:层“顺序”的输入0与层不兼容:预期形状=(无,90),发现形状=(无,2,90) - ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 90), found shape=(None, 2, 90) ValueError:“顺序”层的输入 0 与该层不兼容:预期形状 =(None, 455, 30),找到的形状 =(None, 30) - ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 455, 30), found shape=(None, 30)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM