android - Tensorflow 自定义 TFLite java.lang.NullPointerException : Cannot allocate memory for the interpreter

标签 android python tensorflow

我使用 https://github.com/tensorflow/hub/blob/master/examples/image_retraining/retrain.py 中的 retrain.py 创建了一个自定义 tensorflow lite 模型使用以下命令

python retrain.py --image_dir newImageDirectory --tfhub_module https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/1
然后我使用 toco 进行转换output_graph.pb文件转换为 lite 文件。使用以下命令:
bazel run tensorflow/contrib/lite/toco:toco -- --input_file=/tmp/output_graph.pb --output_file=/tmp/optimized.lite --input_format=TENSORFLOW_GRAPHDEF --output_format=TFLITE --inpute_shape=1,224,224,3 --input_array=input --output_array=final_result --inference_type=FLOAT --input_data_type=FLOAT
然后我将新的 lite 文件和 labels.txt 文件放入 tensorflow 中,供诗人 2 https://github.com/googlecodelabs/tensorflow-for-poets-2 使用。看看我是否可以让它开始对新类别进行分类。当应用程序启动时,我收到以下错误:
Caused by: java.lang.NullPointerException: Can not allocate memory for the interpreter                                                                                            at org.tensorflow.lite.NativeInterpreterWrapper.createInterpreter(Native Method)
                                                                      at org.tensorflow.lite.NativeInterpreterWrapper.<init>(NativeInterpreterWrapper.java:63)
                                                                                        at org.tensorflow.lite.NativeInterpreterWrapper.<init>(NativeInterpreterWrapper.java:51)
                                                                                        at org.tensorflow.lite.Interpreter.<init>(Interpreter.java:90)
                                                                                        at com.example.android.tflitecamerademo.ImageClassifier.<init>(ImageClassifier.java:97)

最佳答案

这是由于您正在使用的计算机,请确保您有足够的内存来为程序分配,或者尝试增加您的交换文件大小?

关于android - Tensorflow 自定义 TFLite java.lang.NullPointerException : Cannot allocate memory for the interpreter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50399547/

相关文章:

Android RuntimeException 资源$NotFoundException

java - 我的应用程序按钮不起作用,handler.java 错误

python - 为什么 os.rename() 在 Python 2.7 中引发异常?

python - 在每个示例上使用 tensorflow 获得相同的预测

tensorflow - 我可以使用 tensorflow keras 模型优化工具包对 keras 预训练模型进行修剪吗?

android - AlertDialog 和 SherlockActivity

安卓的东西 :Use Speech to text in Raspberry Pi 3 using android things

python - 使用 Python 日志记录出现两次的日志消息

python - 在 Sphinx reST 中包含 secret 信息

python - 如何在 tensorflow 中将图像张量转换为numpy数组?