我使用 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/