python - 如何加载和运行 TensorFlow 模型
问题描述
超级简单的问题。
我正在关注本教程: https ://github.com/tensorflow/hub/blob/master/examples/colab/tf2_image_retraining.ipynb
我按照说明(不是可选部分)训练了一个模型,并使用 tf.saved_model.save 保存了它
现在我想针对新图片运行模型。我该怎么做呢?
我尝试了以下方法:
loaded = tf.saved_model.load("/tmp/saved_flowers_model")
print(list(loaded.signatures.keys())) # ["serving_default"]
infer = loaded.signatures["serving_default"]
print(infer.structured_outputs)
file = .../pic.jpg
output = loaded (file)
返回以下错误:
ValueError: Could not find matching function to call loaded from the SavedModel. Got:
Positional arguments (3 total):
* /Users/dansafdie/Documents/Code Repos/Image Classifier/flower_photos/daisy/19834392829_7d697871f6.jpg
* False
* None
Keyword arguments: {}
Expected these arguments to match one of the following 4 option(s):
Option 1:
Positional arguments (3 total):
* TensorSpec(shape=(None, 224, 224, 3), dtype=tf.float32, name='inputs')
* True
* None
Keyword arguments: {}
Option 2:
Positional arguments (3 total):
* TensorSpec(shape=(None, 224, 224, 3), dtype=tf.float32, name='inputs')
* False
* None
Keyword arguments: {}
Option 3:
Positional arguments (3 total):
* TensorSpec(shape=(None, 224, 224, 3), dtype=tf.float32, name='input_1')
* False
* None
Keyword arguments: {}
Option 4:
Positional arguments (3 total):
* TensorSpec(shape=(None, 224, 224, 3), dtype=tf.float32, name='input_1')
* True
* None
Keyword arguments: {}
解决方案
推荐阅读
- python - CGI - HTML 到 python
- assembly - 操作数必须是可重定位的程序集 x86 问题
- php - 我可以根据 URL 显示单一视图的不同部分吗?
- apache-kafka - 如何获取 Apache kafka 正在使用的配置文件名
- json - 使用数组解组 JSON
- powershell - 在 powershell 脚本中为 Nintex 设置凭据以迁移到 O365
- c# - 我在字符串的末尾得到了价值
- php - 从 URL 运行脚本时来自 cpanel 重新调整错误的 Cron 作业没有重新运行任何错误
- opencv - OpenMP 的结果令人失望
- git - 从 Azure DevOps 克隆存储库时出现致命错误