我试图通过使用tfLite模型来检测符号识别。我已经导入了tfLite模型并传递了位图,但是当我运行这个应用程序时,什么都没有发生。为了得到哪里是问题,我增加了5个吐司,但只有第一个吐司成功运行。我不知道什么是错的,也不知道如何处理输出,至少在吐司中显示出来。守则如下:
private void processImage() {
imageConverter.run();
rgbFrameBitmap = Bitmap.createBitmap(previewWidth, previewHeight, Bitmap.Config.ARGB_8888);
rgbFrameBitmap.setPixels(rgbBytes, 0, previewWidth, 0, 0, previewWidth, previewHeight);
//Do your work here
try {
Model model = Model.newInstance(getApplicationContext());
Toast.makeText(this, "Toast-1", Toast.LENGTH_SHORT).show();
// Creates inputs for reference.
TensorBuffer inputFeature0 = TensorBuffer.createFixedSize(new int[]{1, 1, 1, 3}, DataType.UINT8);
TensorImage tensorImage = new TensorImage(DataType.UINT8);
tensorImage.load(rgbFrameBitmap);
ByteBuffer byteBuffer = tensorImage.getBuffer();
inputFeature0.loadBuffer(byteBuffer);
Toast.makeText(this, "Toast-2", Toast.LENGTH_SHORT).show();
// Runs model inference and gets result.
Model.Outputs outputs = model.process(inputFeature0);
TensorBuffer outputFeature0 = outputs.getOutputFeature0AsTensorBuffer();
TensorBuffer outputFeature1 = outputs.getOutputFeature1AsTensorBuffer();
TensorBuffer outputFeature2 = outputs.getOutputFeature2AsTensorBuffer();
TensorBuffer outputFeature3 = outputs.getOutputFeature3AsTensorBuffer();
TensorBuffer outputFeature4 = outputs.getOutputFeature4AsTensorBuffer();
TensorBuffer outputFeature5 = outputs.getOutputFeature5AsTensorBuffer();
TensorBuffer outputFeature6 = outputs.getOutputFeature6AsTensorBuffer();
TensorBuffer outputFeature7 = outputs.getOutputFeature7AsTensorBuffer();
Toast.makeText(this, outputFeature0.toString(), Toast.LENGTH_LONG).show();
Toast.makeText(this, "Toast-3 Model Run Successfully", Toast.LENGTH_SHORT).show();
// Releases model resources if no longer used.
model.close();
} catch (IOException e) {
// TODO Handle the exception
Toast.makeText(this, "Toast-4 Scan Failed,Again Trying..", Toast.LENGTH_SHORT).show();
}
Toast.makeText(this, "Toast-5 Again startinng", Toast.LENGTH_SHORT).show();
postInferenceCallback.run();
}发布于 2022-06-08 13:06:13
请检查这个线程How to pass image to tflite model in android上的答案。他在代码中使用了来自tensorflow-lite包的ImageProcessor对象。我觉得这对你会有帮助。如果它不起作用,或者你有任何问题,请回答。祝好运。
https://stackoverflow.com/questions/72543996
复制相似问题