【发布时间】:2020-05-15 13:16:46
【问题描述】:
以下代码给我一个输入错误,我无法弄清楚。
import tensorflow as tf
import neural_structured_learning as nsl
.
.
.
b_size = 132
m = tf.keras.Sequential()
m.add(tf.keras.layers.Dense(980, activation = 'relu', input_shape = (2206,2,)))
m.add(tf.keras.layers.Dense(560, activation = 'relu'))
m.add(tf.keras.layers.Dense(10, activation = 'softmax'))
adv_config = nsl.configs.make_adv_reg_config(multiplier=0.2, adv_step_size=0.5)
adv_model = nsl.keras.AdversarialRegularization(m, adv_config=adv_config)
adv_model.compile(optimizer = "adam",
loss = "sparse_categorical_crossentropy",
metrics = ['accuracy'])
adv_model.fit({"feature" : x_Train, "label" : y}, epochs = 50, batch_size=b_size)
我的 x_Train 的形状为 (5002, 2206, 2)(大小为 (2206,2) 的 5002 个样本)。我试图在开头添加一个Flatten() 层,但它给了我一个object of type 'NoneType' has no len() 错误,即使这与 tf.keras 完美配合。我也尝试过不同的输入形状,但它们都不起作用。所以它抛出了以下错误之一
KeyError: 'dense_115_input'
ValueError: Input 0 of layer sequential_40 is incompatible with the layer: expected axis -1 of input shape to have value 2206 but received input with shape [None, 2206, 2]
TypeError: object of type 'NoneType' has no len()
【问题讨论】:
标签: python machine-learning keras tensorflow2.0 nsl