问题描述
我正在尝试确定张量流分类器模型的预期图像大小。来自
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。