小编LoK*_*LoK的帖子

ValueError: 密集层的输入 0 与该层不兼容: : 预期 min_ndim=2,发现 ndim=1。收到完整形状:[无]

我是 Tensorflow 新手,并尝试使用下面的示例代码来处理它:

def build_model():
    model = keras.Sequential([
            layers.Dense(10, activation=tf.nn.relu),
            layers.Dense(10, activation=tf.nn.relu),
            layers.Dense(1)
        ])
    optimizer = tf.keras.optimizers.RMSprop(0.001)

    model.compile(loss='mean_squared_error',
            optimizer=optimizer,
            metrics=['mean_absolute_error', 'mean_squared_error'])
    return model

model = build_model()
model.fit(training_dataset, epochs=5, steps_per_epoch=179)
Run Code Online (Sandbox Code Playgroud)

训练数据集如下,有 179 行:

features:[29225 29259 29210 29220] Label:2
features:[29220 29236 29201 29234] Label:1
features:[29234 29241 29211 29221] Label:2
features:[29221 29224 29185 29185] Label:2
features:[29185 29199 29181 29191] Label:2
features:[29191 29195 29171 29195] Label:1
features:[29195 29228 29189 29225] Label:1
features:[29225 29236 29196 29199] Label:2
features:[29199 29222 29197 29218] Label:1
features:[29218 29235 29207 …
Run Code Online (Sandbox Code Playgroud)

python machine-learning keras tensorflow

5
推荐指数
1
解决办法
8598
查看次数

标签 统计

keras ×1

machine-learning ×1

python ×1

tensorflow ×1