android - 在 Android 中调用 tflite 模型的问题
问题描述
我正在尝试在 android 中使用已经训练好的模型作为 tflite 模型,但是在执行输出的 tflite 模型时出现以下错误:
**A/libc: Fatal signal 8 (SIGFPE), code 1 (FPE_INTDIV), fault addr 0xb7bd4543 in tid 12009 (ing.tensorflow3), pid 12009 (ing.tensorflow3)**
下面是代码:
//calling
bitmap = getBitmapFromAsset("aval1.png");
imageViewInput.setImageBitmap(bitmap);
testFunctionInference(bitmap);
//method body
public void testFunctionInference(Bitmap strName){
try {
//____________________________________
ImageProcessor imageProcessor =
new ImageProcessor.Builder()
.add(new ResizeOp(1, 1, ResizeOp.ResizeMethod.BILINEAR))
.build();
Log.w("testFunc:","after image processor");
// Create a TensorImage object. This creates the tensor of the corresponding
// tensor type (uint8 in this case) that the TensorFlow Lite interpreter needs.
TensorImage tensorImage = new TensorImage(DataType.FLOAT32);
// Analysis code for every frame
// Preprocess the image
tensorImage.load(strName);
Log.w("testFunc:","265 L no.");
tensorImage = imageProcessor.process(tensorImage);
Log.w("testFunc:","before inputBuffer0");
// Creates inputs for reference.
TensorBuffer inputFeature0 = TensorBuffer.createFixedSize(new int[]{1, 640*480*3}, DataType.FLOAT32);
MappedByteBuffer tfliteModel
= FileUtil.loadMappedFile(this,"converted_model.tflite");
Interpreter tflite = new Interpreter(tfliteModel);
Object a=tensorImage.getBuffer();
Log.w("testFunc:","278");
tflite.run(tensorImage.getBuffer(), inputFeature0.getBuffer());
} catch (IOException e) {
// TODO Handle the exception
}
}
请任何人协助解决此问题。
解决方案
要获取详细日志,您可以使用 nightly-SNAPSHOT 的调试版本。
https://www.tensorflow.org/lite/guide/android#use_the_tensorflow_lite_aar_from_mavencentral
dependencies {
implementation 'org.tensorflow:tensorflow-lite:0.0.0-nightly-debug-SNAPSHOT'
}
但也许最好检查一下你是否正确提供了输入,因为你使用了 DataType.FLOAT32,你的模型应该有 float32 的输入。
推荐阅读
- symfony - 无法使用 Loader 或 Fileloader 从捆绑包中加载 routes.yaml 配置
- python - Plotly 破折号服务器端缓存
- javascript - 摩纳哥编辑器加载主题没有实例
- xml - 在 XSLT 中使用 position() 检索多个同名节点
- drupal - 限制 Drupal 8 中顶级菜单项的数量
- c# - Asp.Net-Core 在点击时读取 js 模型值
- javascript - 如何访问 refs 数组元素
- laravel - 是否可以在不安装 Laravel 的情况下将已经运行的本地 Laravel 应用程序上传到云端?
- excel - 从 10 个列表框中选择。运行时错误“390”
- javascript - 在 Web javascript 中获取云 Firestore 集合的快照大小