在 Mnist 数据集上,MobileNet 在 tff 学习环境中显示出较低的准确率,但在 TensorFlow 环境中显示出较高的准确率。如何提高准确率?
每轮的准确率都停留在 0.111。但同一模型在正常张量流环境下的准确率达到 91%。两种场景中使用的优化器都是 SGD。模型函数: `
def model_fn():
model=tf.keras.Sequential()
model.add(tf.keras.applications.MobileNetV2(include_top = False, pooling = 'avg',
weights = 'imagenet',input_shape=(96,96,3)))
model.add(tf.keras.layers.Dense(10, activation = 'softmax'))
model.layers[0].trainable = False
return tff.learning.from_keras_model(model,input_spec=collections.OrderedDict([('x',
tf.TensorSpec(shape(None,96,96,3),dtype=tf.float32, name=None)),
('y', tf.TensorSpec(shape=(None,), dtype=tf.int32, name=None))]),
loss=tf.keras.losses.SparseCategoricalCrossentropy(),
metrics=[tf.keras.metrics.SparseCategoricalAccuracy()])
`
The accuracy is stuck on 0.111 on every round. But the same model gives an accuracy of 91% in the normal tensorflow environment. The optimizer used in both scenarios is SGD. The model function :
`
def model_fn():
model=tf.keras.Sequential()
model.add(tf.keras.applications.MobileNetV2(include_top = False, pooling = 'avg',
weights = 'imagenet',input_shape=(96,96,3)))
model.add(tf.keras.layers.Dense(10, activation = 'softmax'))
model.layers[0].trainable = False
return tff.learning.from_keras_model(model,input_spec=collections.OrderedDict([('x',
tf.TensorSpec(shape(None,96,96,3),dtype=tf.float32, name=None)),
('y', tf.TensorSpec(shape=(None,), dtype=tf.int32, name=None))]),
loss=tf.keras.losses.SparseCategoricalCrossentropy(),
metrics=[tf.keras.metrics.SparseCategoricalAccuracy()])
`
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论