我已经使用 DNN 训练了一个自定义模型,并尝试使用 TF_Lite 在 Android 中使用它。我在演示应用程序中使用相同的方法来加载资产文件。
private MappedByteBuffer loadModelFile() throws IOException {
AssetFileDescriptor fileDescriptor = getAssets().openFd(getModelPath());
FileInputStream inputStream = new FileInputStream(fileDescriptor.getFileDescriptor());
FileChannel fileChannel = inputStream.getChannel();
long startOffset = fileDescriptor.getStartOffset();
long declaredLength = fileDescriptor.getDeclaredLength();
return fileChannel.map(FileChannel.MapMode.READ_ONLY, startOffset, declaredLength);
但我收到以下错误。
E/AndroidRuntime: FATAL EXCEPTION: main Process: revan.locationspeed,
PID: 12072 java.lang.RuntimeException: Unable to start activity
ComponentInfo{revan.locationspeed/thambu.locationspeed.MainActivity}:
java.lang.IllegalArgumentException: Contents of /dnn_frozen_graph.tflite
does not encode a valid TensorFlowLite model: Could not open '/dnn_frozen_graph.tflite'.The model is not a valid Flatbuffer file.
Caused by: java.lang.IllegalArgumentException: Contents of /dnn_frozen_graph.tflite does not encode a valid TensorFlowLite model:
Could not open '/dnn_frozen_graph.tflite'.The model is not a valid Flatbuffer file.
我使用 toco 进行转换... Android 中的单个 Activity 类。