【问题标题】:Error in converting model into Tensorflow-lite将模型转换为 Tensorflow-lite 时出错
【发布时间】:2018-04-18 09:57:10
【问题描述】:

我已经使用 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 类。

【问题讨论】:

    标签: android tensorflow tensorflow-lite


    【解决方案1】:

    我在 Gradle 文件中添加了这个

    aaptOptions {
            noCompress "tflite"
            noCompress "lite"
    }
    

    然后一切正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-16
      • 2019-12-22
      • 2019-05-14
      • 1970-01-01
      • 1970-01-01
      • 2020-12-03
      • 1970-01-01
      相关资源
      最近更新 更多