我正在尝试加载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一起使用的原因吗?
您正在hub.KerasLayer
中使用TensorFlow V1集线器模型,该模型将用于tf2.0模型
在TensorFlow集线器中,您可以找到一个切换按钮以查看特定TensorFlow版本的tf集线器模型。
要使用hub.KeralLayer
使其工作,请将URL更改为以下tf2.0移动网络版本之一
或如果您必须使用示例中的确切网址。使用hub.Module
代替hub.KeralLayer