Tensorflow Hub 上的地标模块提供的标签图与模型输出不匹配
Label map provided by landmarks module on Tensorflow Hub does not match model output
我正在尝试在 https://tfhub.dev/google/on_device_vision/classifier/landmarks_classifier_asia_V1/1
提供的 tensorflow hub 上使用地标模型
它说输出是“预测:logits:99543 相似度分数的向量”。但是,我的输出形状是 (1, 98960).
标签映射文件有99543行与指令对齐,但输出大小与映射文件不匹配。
预测结果很不准确,以0.76的分数将东方铁塔的图像声称为以色列博物馆。
我的输入图像被预处理为 [321, 321, 3],每条指令缩放为 [0, 1]。
有什么问题吗?是 model/labelmap 问题还是我的尝试有问题?
import tensorflow.compat.v2 as tf
import tensorflow_hub as hub
import pandas as pd
IMAGE_HEIGHT = 321
IMAGE_WIDTH = 321
def load_img(path):
img = tf.io.read_file(path)
img = tf.image.decode_jpeg(img, channels=3)
img = tf.image.resize(img, [IMAGE_HEIGHT, IMAGE_WIDTH])
img = tf.keras.preprocessing.image.img_to_array(img) / 255.0
img = tf.expand_dims(img, 0)
return img
module_handle = "https://tfhub.dev/google/on_device_vision/classifier/landmarks_classifier_asia_V1/1"
detector = hub.KerasLayer(module_handle, output_key='predictions:logits')
image_path = 'xxx'
img = load_img(image_path)
output_tensor = detector(img)
output_tensor.shape
结果如下:
(1, 98960)
提前致谢!
自 2021 年 3 月 18 日起,标签图中的不一致问题已得到修复,模型文档的更新(即输出向量的长度实际上应为 98960 而不是 99543)正在进行中。您已经可以重新下载在 tfhub.dev 的模型页面上引用的标签映射文件。抱歉给您带来不便!
我正在尝试在 https://tfhub.dev/google/on_device_vision/classifier/landmarks_classifier_asia_V1/1
提供的 tensorflow hub 上使用地标模型它说输出是“预测:logits:99543 相似度分数的向量”。但是,我的输出形状是 (1, 98960).
标签映射文件有99543行与指令对齐,但输出大小与映射文件不匹配。
预测结果很不准确,以0.76的分数将东方铁塔的图像声称为以色列博物馆。
我的输入图像被预处理为 [321, 321, 3],每条指令缩放为 [0, 1]。
有什么问题吗?是 model/labelmap 问题还是我的尝试有问题?
import tensorflow.compat.v2 as tf
import tensorflow_hub as hub
import pandas as pd
IMAGE_HEIGHT = 321
IMAGE_WIDTH = 321
def load_img(path):
img = tf.io.read_file(path)
img = tf.image.decode_jpeg(img, channels=3)
img = tf.image.resize(img, [IMAGE_HEIGHT, IMAGE_WIDTH])
img = tf.keras.preprocessing.image.img_to_array(img) / 255.0
img = tf.expand_dims(img, 0)
return img
module_handle = "https://tfhub.dev/google/on_device_vision/classifier/landmarks_classifier_asia_V1/1"
detector = hub.KerasLayer(module_handle, output_key='predictions:logits')
image_path = 'xxx'
img = load_img(image_path)
output_tensor = detector(img)
output_tensor.shape
结果如下: (1, 98960)
提前致谢!
自 2021 年 3 月 18 日起,标签图中的不一致问题已得到修复,模型文档的更新(即输出向量的长度实际上应为 98960 而不是 99543)正在进行中。您已经可以重新下载在 tfhub.dev 的模型页面上引用的标签映射文件。抱歉给您带来不便!