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

Ili*_*lov 4 android machine-learning android-ndk tensorflow

我已经使用我自己的数据集重新训练了TensorFlow Inception v3模型,如本教程所述.

现在我正在尝试使用我的再培训模型构建和运行TensorFlow Android示例.我按原样从示例中构建了本机代码,将模型(.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";
Run Code Online (Sandbox Code Playgroud)

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

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)
Run Code Online (Sandbox Code Playgroud)

PS我也尝试使用tensorflow/python/tools/strip_unused.py(如此处所示)这样:

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
Run Code Online (Sandbox Code Playgroud)

没有帮助.

Ili*_*lov 8

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

aaptOptions { noCompress 'pb' }
Run Code Online (Sandbox Code Playgroud)