【问题标题】:TensorFlow retrained inception v3 model crashes on AndroidTensorFlow 重新训练的 inception v3 模型在 Android 上崩溃
【发布时间】:2016-08-12 05:21:23
【问题描述】:

我已经使用我自己的数据集重新训练了 TensorFlow Inception v3 模型,如 tutorial 中所述。

现在我正在尝试使用我重新训练的模型构建和运行 TensorFlow Android example。我按原样从示例中构建了本机代码,将模型 (.pb) 和标签 (.txt) 文件复制到资产目录并更改了 TensorFlowImageListener.java 中的模型参数:

private static final int NUM_CLASSES = 5; // number of categories
private static final int INPUT_SIZE = 299;
private static final int IMAGE_MEAN = 128;
private static final float IMAGE_STD = 128;
private static final String INPUT_NAME = "Mul:0";
private static final String OUTPUT_NAME = "final_result:0";

但应用在解析从资产加载的模型文件时崩溃:

08-12 16:02:08.258 25253-25253/com.iliakplv.tensorflow I/native: tensorflow_jni.cc:115 Loading TensorFlow.
08-12 16:02:08.258 25253-25253/com.iliakplv.tensorflow I/native: tensorflow_jni.cc:117 Making new SessionOptions.
08-12 16:02:08.259 25253-25253/com.iliakplv.tensorflow I/native: tensorflow_jni.cc:120 Got config, 0 devices
08-12 16:02:08.264 25253-25253/com.iliakplv.tensorflow I/native: tensorflow_jni.cc:123 Session created.
08-12 16:02:08.264 25253-25253/com.iliakplv.tensorflow I/native: tensorflow_jni.cc:126 Graph created.
08-12 16:02:08.265 25253-25253/com.iliakplv.tensorflow I/native: tensorflow_jni.cc:130 Acquired AssetManager.
08-12 16:02:08.265 25253-25253/com.iliakplv.tensorflow I/native: tensorflow_jni.cc:132 Reading file to proto: file:///android_asset/tensorflow_inception_graph.pb
08-12 16:02:08.265 25253-25253/com.iliakplv.tensorflow I/native: jni_utils.cc:120 Opening asset tensorflow_inception_graph.pb from disk with copy.
08-12 16:02:09.382 25253-25253/com.iliakplv.tensorflow A/native: jni_utils.cc:123 Check failed: message->ParseFromArray(memory, data_size) 
08-12 16:02:09.382 25253-25253/com.iliakplv.tensorflow A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 25253 (tech.tensorflow)

附:我也尝试过像这样使用tensorflow/python/tools/strip_unused.py(正如它所建议的here):

bazel build tensorflow/python/tools:strip_unused && \
bazel-bin/tensorflow/python/tools/strip_unused \
--input_graph=some_graph_def.pb \
--output_graph=/tmp/stripped_graph.pb \
--input_node_names=Mul
--output_node_names=final_result

没有帮助。

【问题讨论】:

    标签: android machine-learning android-ndk tensorflow


    【解决方案1】:

    问题在于 gradle 压缩资产文件导致模型解析失败。我禁用了 .pb 文件的压缩:

    aaptOptions { noCompress 'pb' }
    

    【讨论】:

    • 我已将此添加到我的 gradle 文件中,但问题没有解决。
    • @MuhammadHannan 当我在 TensorFlow 和 Android 应用程序的一个特定版本上使用重新训练的模型以及在另一个版本上构建的本机库时,我遇到了类似的模型解析问题。由于 TensorFlow 处于密集开发阶段,最好检查特定的发布分支并在其上进行所有实验。
    猜你喜欢
    • 2017-03-28
    • 1970-01-01
    • 2018-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多