首页 > 解决方案 > 如何使用tfhub提供的efficientnet-lite进行tf2.1的二次训练

问题描述

我使用的版本是 tensorflow-gpu 2.1.0 版,从 pip 安装。

import tensorflow as tf
import tensorflow_hub as hub

tf.keras.backend.set_learning_phase(True)

module_url = "https://tfhub.dev/tensorflow/efficientnet/lite0/classification/2"

module2 = tf.keras.Sequential([
    hub.KerasLayer(module_url, trainable=False, input_shape=(224,224,3))])

output1 = module2(tf.ones(shape=(1,224,224,3)))
print(module2.summary())

当我设置trainable = True时,操作会报错。那么,我不能在 tf2.1 版本上重新训练它吗?

标签: tensorflowtensorflow-hub

解决方案


TFHub 上的 EfficientNet-Lite 模型基于 TensorFlow 1,因此受到 TF2 的许多限制,包括您发现的微调。EfficientNet 模型已更新到 TF2,但我们仍在等待它们的 lite 模型。

https://www.tensorflow.org/hub/model_compatibility

https://github.com/tensorflow/hub/issues/751

更新:从 2021 年 10 月 5 日开始,TFHub 上的 EfficientNet-Lite 模型可用于 TensorFlow 2。


推荐阅读