【发布时间】:2021-03-23 20:17:57
【问题描述】:
我正在尝试从 tensorflow hub 加载预训练模型(链接:https://tfhub.dev/google/on_device_vision/classifier/landmarks_classifier_north_america_V1/1)。当我对单个图像进行推理时,我得到长度为 99424 的输出,但相应的标签图的长度为 99676。这对我来说没有任何意义,因为两者的长度应该是相同的长度。由于这个错误,模型无法准确分类。有没有其他人有同样的错误。如果没有,任何指导将不胜感激。
import tensorflow.compat.v2 as tf
import tensorflow_hub as hub
model = hub.KerasLayer(model_url, output_key='predictions:logits')
landmarks = pd.read_csv(landmark_file)
image = load_image(im_path) # (321, 321, 3) scaled between [0,1]
output = model(image)
prediction = landmarks['name'][int(tf.math.argmax(output, 1))]
另外,加载模型时出现此错误:
INFO:tensorflow:Saver not created because there are no variables in the graph to restore
我觉得是 tensorflow hub 的模型有问题,但不完全确定
【问题讨论】: