gpt4 book ai didi

android - TensorFlowInferenceInterface : Mobilenet for imagenet : java. io.IOException:不是有效的 TensorFlow Graph 序列化

转载 作者:行者123 更新时间:2023-11-29 15:37:30 25 4
gpt4 key购买 nike

我正在尝试在 Android Tensorflow 上运行通过 imagenet 训练的 mobilenet 模型以进行对象识别并面临如下所述的问题。

 TensorFlowInferenceInterface: Failed to load model 
from 'file:///android_asset/mobilenet_imagenet.pb': java.io.IOException:
Not a valid TensorFlow Graph serialization:
NodeDef mentions attr 'data_format' not in Op<name=DepthwiseConv2dNative;
signature=input:T, filter:T -> output:T;
attr=T:type,allowed=[DT_FLOAT, DT_DOUBLE]; attr=strides:list(int);
attr=padding:string,allowed=["SAME", "VALID"]>;
NodeDef: conv_dw_1/depthwise =
DepthwiseConv2dNative[T=DT_FLOAT, data_format="NHWC", padding="SAME", strides=[1, 1, 1, 1]]
(conv1_relu/clip_by_value, conv_dw_1/depthwise_kernel/read)

我遵循了 link 中给出的教程在 Android 上集成 Tensorflow。我可以运行经过自定义训练的基本 CNN 分类器(在 Ubuntu 16.04 上使用 python 2.7.12、Tensorflow 1.2)并且运行良好。

我可以使用 Tensorflow 1.2 和 1.3 在 Ubuntu 16.04 上的 python 2.7.12 上成功运行通过 imagenet 训练的 Mobilenet。现在,当我尝试在 Android 上运行相同的“.pb”模型时,出现了上述错误。

初始化模型的代码如下:

TensorFlowImageClassifier c = new TensorFlowImageClassifier();
c.inferenceInterface = new TensorFlowInferenceInterface();
if (c.inferenceInterface.initializeTensorFlow(assetManager, modelFilename) != 0) {
throw new RuntimeException("TF initialization failed");
}

请给我一个解决方案或解决方法

最佳答案

上述问题已通过将“libandroid_tensorflow_inference_java.jar”和“libtensorflow_inference.so”更新到最新版本即 Tensorflow - 1.4 得到解决。可以找到最新的“.jar”和“.so”文件here .

问题是由于 Tensorflow 版本不匹配造成的。在 ImageNet 上训练的 Mobilenet 分类器建立在 Tensorflow - 1.3 上,并用于使用 Tensorflow - 1.1 在 Android 上进行推理。

关于android - TensorFlowInferenceInterface : Mobilenet for imagenet : java. io.IOException:不是有效的 TensorFlow Graph 序列化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46889203/

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