gpt4 book ai didi

python - Tensorflow 模型适用于 Python 但不适用于 C++

转载 作者:行者123 更新时间:2023-11-30 05:18:45 25 4
gpt4 key购买 nike

关于一些背景知识,我的主要目标是使用 Tensorflow 的 C++ API 对图像进行分类并在不同系统上对其计时。

我用过Ry's model converter将他的 Caffe 模型转换为 Tensorflow,它会生成 vgg16.tfmodel 文件,一旦您打开它,它似乎是一个 .pb 文件。

使用 Ry 的 tf_forward.py 来运行这个生成的文件似乎工作得很好,对猫、狗等进行分类。但是,当我修改 label_image 示例 (tensorflow/examples/label_image/) 以使用我的新 vgg16.pb 文件时,似乎出了点问题。

这是来自 tensorflow-vgg16 示例的猫图片分类输出:

I tensorflow/examples/label_image/main.cc:195] n03729826 matchstick (644): 0.0762781
I tensorflow/examples/label_image/main.cc:195] n01930112 nematode, nematode worm, roundworm (111): 0.0493599
I tensorflow/examples/label_image/main.cc:195] n03196217 digital clock (530): 0.0317698
I tensorflow/examples/label_image/main.cc:195] n03666591 lighter, light, igniter, ignitor (626): 0.0313151
I tensorflow/examples/label_image/main.cc:195] n04286575 spotlight, spot (818): 0.0252088

下面是我在修改 label_image/main.cc 时使用的设置:

string image = "tensorflow/examples/label_image/data/cat.jpg"; //from Ry's project
string graph = "tensorflow/examples/label_image/data/vgg16.pb"; //renamed from Ry's project
string labels ="tensorflow/examples/label_image/data/synset.txt"; //from Ry's project
int32 input_width = 224;
int32 input_height = 224;
int32 input_mean = 128;
int32 input_std = 128;
string input_layer = "mul";
string output_layer = "prob";
bool self_test = false;
string root_dir = "";

我也试过 freeze_graph.py 来获取模型和权重,但我永远无法让它正常工作。在追溯一切之后,我遇到了 protobuf 代码并且有点卡住了。任何帮助将不胜感激:)

最佳答案

对于以后看到这个的人来说,这个问题是由于使用了错误的输入层名称引起的。

关于python - Tensorflow 模型适用于 Python 但不适用于 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41497982/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com