【问题标题】:tensorflow - ValueError: Could not find matching function to call loaded from the SavedModeltensorflow - ValueError:找不到匹配的函数来调用从 SavedModel 加载
【发布时间】:2021-07-26 18:40:09
【问题描述】:

我正在尝试使用下面的代码从教科书中遵循迁移学习指南,并收到上面的错误消息。我假设input_shapeIMAGE_SHAPE 不匹配,但我无法确定正确的尺寸。

代码:

import tensorflow as tf
import tensorflow_hub as hub
import numpy as np
import matplotlib.pyplot as plt

module_url = "https://tfhub.dev/google/imagenet/mobilenet_v2_100_160/feature_vector/4"
my_model = hub.KerasLayer(module_url)

classifier_url = "https://tfhub.dev/google/imagenet/mobilenet_v2_100_160/feature_vector/4"
IMAGE_SHAPE = (224,224)

classifier = tf.keras.Sequential([hub.KerasLayer(classifier_url, input_shape = IMAGE_SHAPE+(3,))])

错误信息:

    graph_function = self._create_graph_function(args, kwargs)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/eager/function.py:3289 _create_graph_function
    capture_by_value=self._capture_by_value),
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/func_graph.py:999 func_graph_from_py_func
    func_outputs = python_func(*func_args, **func_kwargs)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/eager/def_function.py:672 wrapped_fn
    out = weak_wrapped_fn().__wrapped__(*args, **kwds)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/saved_model/function_deserialization.py:291 restored_function_body
    "\n\n".join(signature_descriptions)))

ValueError: Could not find matching function to call loaded from the SavedModel. Got:
  Positional arguments (4 total):
    * Tensor("inputs:0", shape=(None, 224, 224, 3), dtype=float32)
    * False
    * False
    * 0.99
  Keyword arguments: {}

Expected these arguments to match one of the following 4 option(s):

Option 1:
  Positional arguments (4 total):
    * TensorSpec(shape=(None, 160, 160, 3), dtype=tf.float32, name='inputs')
    * False
    * False
    * TensorSpec(shape=(), dtype=tf.float32, name='batch_norm_momentum')
  Keyword arguments: {}

Option 2:
  Positional arguments (4 total):
    * TensorSpec(shape=(None, 160, 160, 3), dtype=tf.float32, name='inputs')
    * False
    * True
    * TensorSpec(shape=(), dtype=tf.float32, name='batch_norm_momentum')
  Keyword arguments: {}

Option 3:
  Positional arguments (4 total):
    * TensorSpec(shape=(None, 160, 160, 3), dtype=tf.float32, name='inputs')
    * True
    * True
    * TensorSpec(shape=(), dtype=tf.float32, name='batch_norm_momentum')
  Keyword arguments: {}

Option 4:
  Positional arguments (4 total):
    * TensorSpec(shape=(None, 160, 160, 3), dtype=tf.float32, name='inputs')
    * True
    * False
    * TensorSpec(shape=(), dtype=tf.float32, name='batch_norm_momentum')
  Keyword arguments: {}

【问题讨论】:

    标签: tensorflow transfer-learning


    【解决方案1】:

    您可以在https://tfhub.dev/google/imagenet/mobilenet_v2_100_160/feature_vector/4 找到您想使用的模型的文档。在错误消息中,它说输入图像的形状必须为(160, 160, 3)

    classifier_url = "https://tfhub.dev/google/imagenet/mobilenet_v2_100_160/feature_vector/4"
    IMAGE_SHAPE = (160, 160)
    classifier = tf.keras.Sequential([hub.KerasLayer(classifier_url, input_shape = IMAGE_SHAPE+(3,))])
    

    【讨论】:

      猜你喜欢
      • 2019-12-25
      • 2020-08-28
      • 2020-02-22
      • 2020-07-08
      • 2020-09-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-09
      • 1970-01-01
      相关资源
      最近更新 更多