Android上{TensorFlow重新训练的初始v3模型崩溃

时间:2016-08-12 05:21:23

标签: android machine-learning android-ndk tensorflow

我使用我自己的数据集重新训练了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)

P.S。我也尝试使用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

没有帮助。

1 个答案:

答案 0 :(得分:8)

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

aaptOptions { noCompress 'pb' }