【问题标题】:issue in invoking tflite model in Android在 Android 中调用 tflite 模型的问题
【发布时间】:2021-10-05 11:37:49
【问题描述】:

我正在尝试在 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
        }
    }

请任何人协助解决此问题。

【问题讨论】:

  • 那么,为什么要将尺寸调整为 1x1?我还没有看到模型的那种输入!

标签: android android-studio machine-learning tensorflow-lite


【解决方案1】:

要获取详细日志,可以使用 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 的输入。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-03
    • 2021-11-25
    • 1970-01-01
    相关资源
    最近更新 更多