模块 'tensorflow_hub' 没有属性 'KerasLayer'

module 'tensorflow_hub' has no attribute 'KerasLayer'

当我尝试使用 tensorflow 重新训练模型时,它显示错误:

**error module 'tensorflow_hub' has no attribute 'KerasLayer'**

密码是:

print("Building model with", MODULE_HANDLE)
model = tf.keras.Sequential([
    hub.KerasLayer(MODULE_HANDLE, output_shape=[FV_SIZE],
    trainable=do_fine_tuning),
    tf.keras.layers.Dropout(rate=0.2),
    tf.keras.layers.Dense(train_generator.num_classes,
    activation='softmax',
    kernel_regularizer=tf.keras.regularizers.l2(0.0001))
])
model.build((None,)+IMAGE_SIZE+(3,))
model.summary()

错误如下:

      1 print("Building model with", MODULE_HANDLE)
      2 model = tf.keras.Sequential([
----> 3     hub.KerasLayer(MODULE_HANDLE, output_shape=[FV_SIZE],
      4                    trainable=do_fine_tuning),
      5     tf.keras.layers.Dropout(rate=0.2),

AttributeError: module 'tensorflow_hub' has no attribute 'KerasLayer'

通过使用 tensorflow hub 通过添加新的完全连接的 dence 重新训练以前的 hub 模型 layers.when 运行 它显示上面的代码 error.is 任何人都知道 that.please 帮助

请检查tensorflow版本。应该是最近的nightly版本。

当我使用1.13.1这样的版本时,在报错前看到如下警告,no attribute 'KerasLayer':

W0423 20:04:16.453974 139707130586880 __init__.py:56] Some hub symbols are not available because TensorFlow version is less than 1.14

之后,执行 pip install "tf-nightly",一切正常。

https://www.tensorflow.org/hub

对于 BatchNormalizationv1 问题,您可以使用 tf2.0 nightly 来处理原始问题。

pip install -U tf-nightly-2.0-preview

https://github.com/tensorflow/tfjs/issues/1255