【发布时间】:2021-08-20 19:10:36
【问题描述】:
我是tensorflow 的新手。尝试开发具有多个输入和单个输出的简单模型。如果有人可以帮助我,我将不胜感激。我发现以下代码可能有效,但无效。另外,在这种情况下如何传递预测参数?
trainx1 = np.array([-1, 0, 1, 2, 3, 4], dtype=float)
trainx2 = np.array([-1, 0, 1, 2, 3, 4], dtype=float)
labely1 = np.array([-2, 0, 2, 4, 6, 8], dtype=float)
x1 = Input(shape =(1,))
x2 = Input(shape =(1,))
input_layer = concatenate([x1,x2])
hidden_layer = Dense(units=4, activation='relu')(input_layer)
prediction = Dense(1, activation='linear')(hidden_layer)
model = Model(inputs=[x1, x2], outputs=prediction)
model.compile(loss="mean_squared_error",
optimizer="adam", metrics=['accuracy'])
model.fit([trainx1, trainx2], labely1,
epochs=100, batch_size=1, verbose=2, shuffle=False)
model.summary()
【问题讨论】:
-
这段代码遇到了什么错误?
-
谢谢 Inna!实际上,我在模型中看到零精度。两个输入和输出之间的关系只是两个输入的总和。所以模型应该能够达到100%的准确率。同样当我使用 model.predict([5,5]) 时。它抛出错误“ValueError:层模型需要 2 个输入,但它接收到 1 个输入张量。收到的输入:[
]”跨度>
标签: tensorflow python tensorflow machine-learning keras deep-learning