无法从 10368 字节的 TensorFlowLite 张量 (StatefulPartitionedCall:0) 复制到 324 字节的 Java 缓冲区
我正在尝试在 android studio 上制作一个手写文本识别 android 应用程序。我将模型转换为 TensorFlow Lite,然后将该文件上传到我的应用程序中。下面我分享相同的代码...代码中有很多日志语句。检查直到它被执行的地方。
public void classifyImage(Bitmap image){
try {
Ocr mdl = Ocr.newInstance(getApplicationContext());
TensorBuffer inputFeature0 = TensorBuffer.createFixedSize(new int[]{1, 128, 32, 1}, DataType.FLOAT32);
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(4*128*32*1);
int[] intValues = new int[128 * imageSize];
image.getPixels(intValues, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight());
Log.d("TAG Model", " get pixels ");
int pixel = 0;
for (int i=0; i<4096; i++){
int val = intValues[pixel++];
byteBuffer.putFloat(val);
}
Log.d("TAG Model", " bytebuffer putfloat com ");
inputFeature0.loadBuffer(byteBuffer);
Ocr.Outputs outputs = mdl.process(inputFeature0);
Log.d("TAG Model", " Model process ");
TensorBuffer outputFeature0 = outputs.getOutputFeature0AsTensorBuffer();
Log.d("TAG Model", " Model output");
float[] confidences = outputFeature0.getFloatArray();
mdl.close();
} catch (Exception e) {
// TODO Handle the exception
Log.d("TAG Model", "classifyImage: "+e.getMessage());
}
}
在运行我的应用程序时,我收到错误:D/TAG模型:classifyImage:无法从 10368 字节的 TensorFlowLite 张量 (StatefulPartitionedCall:0) 复制到 324 字节的 Java 缓冲区。
您能帮助我们吗这是因为我对这个错误感到震惊,无法进一步进行。
I'm trying to make a handwritten text recognition android application on android studio. I converted my model into tensorflow lite and then uploaded that file in my application. Below Im sharing the code for the same... There are many log statements in the code. to check till where it is getting executed.
public void classifyImage(Bitmap image){
try {
Ocr mdl = Ocr.newInstance(getApplicationContext());
TensorBuffer inputFeature0 = TensorBuffer.createFixedSize(new int[]{1, 128, 32, 1}, DataType.FLOAT32);
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(4*128*32*1);
int[] intValues = new int[128 * imageSize];
image.getPixels(intValues, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight());
Log.d("TAG Model", " get pixels ");
int pixel = 0;
for (int i=0; i<4096; i++){
int val = intValues[pixel++];
byteBuffer.putFloat(val);
}
Log.d("TAG Model", " bytebuffer putfloat com ");
inputFeature0.loadBuffer(byteBuffer);
Ocr.Outputs outputs = mdl.process(inputFeature0);
Log.d("TAG Model", " Model process ");
TensorBuffer outputFeature0 = outputs.getOutputFeature0AsTensorBuffer();
Log.d("TAG Model", " Model output");
float[] confidences = outputFeature0.getFloatArray();
mdl.close();
} catch (Exception e) {
// TODO Handle the exception
Log.d("TAG Model", "classifyImage: "+e.getMessage());
}
}
On running my application Im getting an error : D/TAG Model: classifyImage: Cannot copy from a TensorFlowLite tensor (StatefulPartitionedCall:0) with 10368 bytes to a Java Buffer with 324 bytes.
Can you please help we with this, as i'm struck on this error and cannot proceed further.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论