hub.get_expected_image_size 产生错误

问题描述

我正在尝试确定张量流分类器模型的预期图像大小。来自

https://www.tensorflow.org/hub/tutorials/image_feature_vector

这是通过

   image_module = hub.Module('https://tfhub.dev/google/imagenet/mobilenet_v2_035_128/feature_vector/2')
   image_size = hub.get_expected_image_size(image_module)

我有一个我正在尝试的本地模型 imagenet/inception/resnet/v2/classification/4。我的代码

    export_path = "/home/adi/Desktop/oni/tensor_flow/tf_model_clas/imagenet_inception_resnet_v2_classification_4/"
    module_spec = hub.load_module_spec(export_path)
    height,width = hub.get_expected_image_size(model_spec)
    print(height,width)

使用此代码,我收到以下错误

Traceback (most recent call last):
  File "./evaluate_models_class.py",line 203,in <module>
    height,width = hub.get_expected_image_size(classifier_model)
  File "/home/adi/.local/lib/python3.7/site-packages/tensorflow_hub/image_util.py",line 77,in get_expected_image_size
    image_module_info = get_image_module_info(module_or_spec)
  File "/home/adi/.local/lib/python3.7/site-packages/tensorflow_hub/image_util.py",line 54,in get_image_module_info
    return module_or_spec.get_attached_message(
AttributeError: '_UserObject' object has no attribute 'get_attached_message'

当我加载它时我获得了一个功能模型

    classifier_model = keras.models.load_model(export_path)
    classifier = tf.keras.Sequential([hub.KerasLayer(classifier_model)])

我做错了什么?

解决方法

hub.get_expected_image_size 仅适用于某些以某种方式导出的 Hub.Module 格式的模型,此功能不适用于 TF2 SavedModels。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...