简体   繁体   English

层“sequential_3”的输入0与层不兼容:预期形状=(无,60),找到形状=(5,174)

[英]Input 0 of layer "sequential_3" is incompatible with the layer: expected shape=(None, 60), found shape=(5, 174)

I am doing binary classification for 1000 molecules with smiles as input.我正在对 1000 个以微笑作为输入的分子进行二进制分类。 My dataset is from <moleculenet.org>, Biophysics HIV data.我的数据集来自 <moleculenet.org>,Biophysics HIV 数据。 I first tokenized them, padded them.我首先标记它们,填充它们。

data = slice(1000)
data1 = df[data]
tokenizer = tf.keras.preprocessing.text.Tokenizer(
vocab_size, filters="", char_level=True)
tokenizer.fit_on_texts(data1.smiles)
seqs = tokenizer.texts_to_sequences(data1.smiles)
padded_seqs = tf.keras.preprocessing.sequence.pad_sequences(seqs, padding="post")

Then i built dense models and took cross entropy as loss function.然后我建立了密集模型并将交叉熵作为损失 function。

model = Sequential()
model.add(Dense(60, input_dim=60, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
# Compile model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
model.summary()
estimators = []
estimators.append(('standardize', StandardScaler()))
estimators.append(('mlp', KerasClassifier(build_fn= lambda: model, epochs=100, 
batch_size=5, verbose=0)))
pipeline = Pipeline(estimators)
kfold = StratifiedKFold(n_splits=10, shuffle=True)
results = cross_val_score(pipeline,padded_seqs,data1.HIV_active, cv=kfold)
print("Standardized: %.2f%% (%.2f%%)" % (results.mean()*100, results.std()*100))

My error log is the following我的错误日志如下

/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:3: DeprecationWarning: 
KerasClassifier is deprecated, use Sci-Keras (https://github.com/adriangb/scikeras) 
instead.
This is separate from the ipykernel package so we can avoid doing imports until
Standardized: nan% (nan%)
/usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py:372: 
FitFailedWarning: 
10 fits failed out of a total of 10.
The score on these train-test partitions for these parameters will be set to nan.
If these failures are not expected, you can try to debug them by setting 
error_score='raise'.

Below are more details about the failures:

10 fits failed with the following error:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py", 
line 681, in _fit_and_score
estimator.fit(X_train, y_train, **fit_params)
File "/usr/local/lib/python3.7/dist-packages/sklearn/pipeline.py", line 394, in fit
self._final_estimator.fit(Xt, y, **fit_params_last_step)
File "/usr/local/lib/python3.7/dist-packages/keras/wrappers/scikit_learn.py", line 232, in fit
return super(KerasClassifier, self).fit(x, y, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/keras/wrappers/scikit_learn.py", line 164, in fit
history = self.model.fit(x, y, **fit_args)
File "/usr/local/lib/python3.7/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.7/dist-packages/tensorflow/python/framework/func_graph.py", line 1129, in autograph_handler
raise e.ag_error_metadata.to_exception(e)

ValueError: in user code: ValueError:在用户代码中:

File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 878, in train_function  *
    return step_function(self, iterator)
File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 867, in step_function  **
    outputs = model.distribute_strategy.run(run_step, args=(data,))
File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 860, in run_step  **
    outputs = model.train_step(data)
File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 808, in train_step
    y_pred = self(x, training=True)
File "/usr/local/lib/python3.7/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.7/dist-packages/keras/engine/input_spec.py", line 263, in assert_input_compatibility
    raise ValueError(f'Input {input_index} of layer "{layer_name}" is '

ValueError: Input 0 of layer "sequential_3" is incompatible with the layer: expected shape=(None, 60), found shape=(5, 174)


     warnings.warn(some_fits_failed_message, FitFailedWarning)

ValueError: is the main error.I am sorry for long code. ValueError: 是主要错误。很抱歉长代码。 Please tell me if my question is understandable or worded wrongly.请告诉我我的问题是否可以理解或措辞错误。

The shape of your input padded_seqs.shape is (1000, 174) , so input shape should be 174, use this:输入padded_seqs.shape的形状是(1000, 174) ,所以输入形状应该是 174,使用这个:

model.add(tf.keras.layers.Dense(60, input_dim=(174), activation='relu'))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ValueError:“顺序”层的输入 0 与该层不兼容:预期形状 =(None, 60, 5),找到的形状 =(None, 60, 7) - ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 60, 5), found shape=(None, 60, 7) 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:层 sequential_3 的输入 0 与层不兼容::预期 min_ndim=4,发现 ndim=3。 已收到完整形状:(无、224、256) - ValueError: Input 0 of layer sequential_3 is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: (None, 224, 256) 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:层“顺序”的输入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) “sequential_23”层的输入 0 与该层不兼容:预期形状=(None, 1797, 8, 8),找到的形状=(None, 8, 8) - Input 0 of layer "sequential_23" is incompatible with the layer: expected shape=(None, 1797, 8, 8), found shape=(None, 8, 8) ValueError:“顺序”层的输入 0 与该层不兼容:预期形状 =(无,33714,12),找到形状 =(无,12) - ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 33714, 12), found shape=(None, 12) | ValueError:“顺序”层的输入 0 与该层不兼容:预期形状 =(None, 28, 28),找到的形状 =(None, 28, 3) - | ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 28, 28), found shape=(None, 28, 3) ValueError:“顺序”层的输入 0 与该层不兼容:预期形状=(无,256、256、3),找到的形状=(无,33) - ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 256, 256, 3), found shape=(None, 33)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM