Tensorflow 离线使用预训练模型

Tensorflow use pretrained model in offline

我正在使用 Tensorflow 的 mobilenet 和以下代码。 当我从我的本地电脑 运行 这段代码时,它会下载权重文件。 但是,上传到服务器后,我无法在线下载。

  1. 有什么方法可以将 MobileNetV2 与 tensorflow 2.0 一起使用。

  2. 或者,我有自己的用 MobielNetV2 训练的权重文件,那么是否可以在没有权重选项的情况下使用下面的选项

    mobilenet = tf.keras.applications.mobilenet_v2.MobileNetV2(input_shape=(224, 224, 3), include_top=假, 权重='imagenet')

  3. 我想使用来自 linux 服务器的 supervisord。 看来我需要使用绝对路径而不是相对路径。 谁能帮我在离线环境中使用 MobileNetV2 和 supervisord

您可以先使用:

mobilenet = tf.keras.applications.mobilenet_v2.MobileNetV2(input_shape=(224, 224, 3), include_top=False, weights='imagenet')

然后将权重保存在某处:

mobilenet.save_weights('somefolder/mobilenetweights.h5')

那么当你处于离线状态时,你可以先拨打:

mobilenet = tf.keras.applications.mobilenet_v2.MobileNetV2(input_shape=(224, 224, 3), include_top=False, weights=None)

注意 weights 参数中的 None。之后,您可以从您之前保存的文件中加载权重:

mobilenet.load_weights('somefolder/mobilenetweights.h5')

这应该有效。

当你调用 mobilenet 模型时,如果你要求它使用 weights='imagenet' 给你 imagenet 权重,它需要互联网连接来下载这些权重。所以它不会脱机工作。此处说明的方法应该可以正常工作。