【发布时间】:2020-01-03 22:55:29
【问题描述】:
我正在尝试将以下 TFlearn 代码转换为 Keras(因为我使用的是 tensorflow2.0,TFlearn 不兼容) - 我对这两个 FWorks 都比较陌生,所以我真的不知道它为什么不起作用(准确性保持不变在 1000 个 epoch 后为 0.04)
在原始 TFlearn 形状中,我有 traning[0] 输入和 output[0] 输出,中间有 2X 8 个隐藏层
这是 TFlearn 模型
tensorflow.reset_default_graph()
net = tflearn.input_data(shape=[None, len(training[0])])
net = tflearn.fully_connected(net, 8)
net = tflearn.fully_connected(net, 8)
net = tflearn.fully_connected(net, len(output[0]), activation="softmax")
net = tflearn.regression(net)
model = tflearn.DNN(net)
model.fit(training, output, n_epoch=1000, batch_size=8, show_metric=True)
model.save("model.tflearn")
这是 Keras 转换
tf.compat.v1.reset_default_graph()
# define the keras model
model = Sequential()
model.add(Dense(8, activation='relu', input_shape=(len(training[0]),)))
model.add(Dense(8, activation="relu"))
model.add(Dense(len(output[0]), activation="softmax"))
model.compile(loss='mean_squared_error', optimizer='adam', metrics=['accuracy'])
history = model.fit(training,output, epochs=100, batch_size=20)
【问题讨论】:
-
澄清一下,TFlearn 版本学习正常,而 Keras 版本不行?
-
完全可以。我正在训练一组单词(总是相同的 BOW 大小)。在 TFlearn 上达到 0.95 的准确度
-
tflearn 使用什么损失?对于分类,你不应该使用均方误差,更喜欢分类交叉熵
-
我首先尝试使用分类交叉熵,但结果相同,TFlearn 没有损失规范......所以,我迷路了
-
@YannMassard 你找到解决方案了吗?我也面临同样的问题,Keras模型的loss比tflearn模型高!
标签: python keras deep-learning tflearn