加载TF集线器模型时,使用@ tf.function的表未初始化问题

问题描述 投票:0回答:1

我正在尝试加载Tf集线器模型并使用@ tf.function装饰器预测输出。它抛出tensorflow.python.framework.errors_impl.FailedPreconditionError:表未初始化。错误。

TF版本-2.1.0

TF hub版本-0.8.0

Note:无需使用@ tf.function装饰器即可工作

import tensorflow as tf
import tensorflow_hub as hub

image_tensor = tf.constant(2.0, shape=[1, 298, 298, 3])


@tf.function
def run_function(method, args):
    return method(args)


detector = hub.KerasLayer("https://tfhub.dev/google/openimages_v4/ssd/mobilenet_v2/1", 
signature_outputs_as_dict=True)
detector_output = run_function(detector, image_tensor)
class_names = detector_output["detection_class_entities"]
print(class_names)

谁能知道为什么它不能与@ tf.function一起使用的原因吗?

tensorflow tensorflow-hub
1个回答
0
投票

您正在hub.KerasLayer中使用TensorFlow V1集线器模型,该模型将用于tf2.0模型

在TensorFlow集线器中,您可以找到一个切换按钮以查看特定TensorFlow版本的tf集线器模型。

enter image description here

要使用hub.KeralLayer使其工作,请将URL更改为以下tf2.0移动网络版本之一

  1. https://tfhub.dev/google/tf2-preview/mobilenet_v2/classification/4
  2. https://tfhub.dev/google/imagenet/mobilenet_v2_050_96/classification/4

或如果您必须使用示例中的确切网址。使用hub.Module代替hub.KeralLayer

© www.soinside.com 2019 - 2024. All rights reserved.