- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用以下仓库添加我的自定义tflite模型:https://github.com/amitshekhariitbhu/Android-TensorFlow-Lite-Example。我的.tflite模型参数是:
== Input details ==
name: x shape: [ 1 256 256 3]
type: <class 'numpy.float32'>
== Output details ==
name: Identity shape: [ 1 30]
type: <class 'numpy.float32'>
java.lang.IllegalArgumentException: Cannot convert between a TensorFlowLite buffer with 786432 bytes and a ByteBuffer with 196608 bytes.
at org.tensorflow.lite.Tensor.throwIfShapeIsIncompatible(Tensor.java:272)
at org.tensorflow.lite.Tensor.throwIfDataIsIncompatible(Tensor.java:249)
at org.tensorflow.lite.Tensor.setTo(Tensor.java:110)
at org.tensorflow.lite.NativeInterpreterWrapper.run(NativeInterpreterWrapper.java:145)
at org.tensorflow.lite.Interpreter.runForMultipleInputsOutputs(Interpreter.java:275)
at org.tensorflow.lite.Interpreter.run(Interpreter.java:249)
at com.amitshekhar.tflite.TensorFlowImageClassifier.recognizeImage(TensorFlowImageClassifier.java:66)
at com.amitshekhar.tflite.MainActivity$1.onImage(MainActivity.java:70)
at com.wonderkiln.camerakit.EventDispatcher$1.run(EventDispatcher.java:42)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6810)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
最佳答案
我在TensorFlowImageClassifier.java中更改了以下字符串:
private ByteBuffer convertBitmapToByteBuffer(Bitmap bitmap) {
ByteBuffer byteBuffer;
if(quant) {
byteBuffer = ByteBuffer.allocateDirect(BATCH_SIZE * inputSize * inputSize * PIXEL_SIZE);
} else {
byteBuffer = ByteBuffer.allocateDirect(4 * BATCH_SIZE * inputSize * inputSize * PIXEL_SIZE);
}
byteBuffer.order(ByteOrder.nativeOrder());
int[] intValues = new int[inputSize * inputSize];
bitmap.getPixels(intValues, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
int pixel = 0;
for (int i = 0; i < inputSize; ++i) {
for (int j = 0; j < inputSize; ++j) {
final int val = intValues[pixel++];
if(quant){
byteBuffer.put((byte) ((val >> 16) & 0xFF));
byteBuffer.put((byte) ((val >> 8) & 0xFF));
byteBuffer.put((byte) (val & 0xFF));
} else {
byteBuffer.put((byte) ((((val >> 16) & 0xFF)-IMAGE_MEAN)/IMAGE_STD));
byteBuffer.put((byte) ((((val >> 8) & 0xFF)-IMAGE_MEAN)/IMAGE_STD));
byteBuffer.put((byte) ((((val) & 0xFF)-IMAGE_MEAN)/IMAGE_STD));
}
}
}
return byteBuffer;
}
@Override
public List<Recognition> recognizeImage(Bitmap bitmap) {
ByteBuffer byteBuffer = convertBitmapToByteBuffer(bitmap);
if(quant){
byte[][] result = new byte[1][labelList.size()];
interpreter.run(byteBuffer, result);
return getSortedResultByte(result);
} else {
byte [][] result = new byte[1][labelList.size()];
interpreter.run(byteBuffer, result);
return getSortedResultByte(result);
private static final boolean QUANT = true;
private static final int INPUT_SIZE = 256;
private static final int MAX_RESULTS = 3;
private static final int BATCH_SIZE = 1;
private static final int PIXEL_SIZE = 3;
private static final float THRESHOLD = 0.1f;
private static final int IMAGE_MEAN = 128;
private static final float IMAGE_STD = 128;
关于java - 将自定义TensorFlowLite模型添加到就绪的Android应用程序时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57187298/
我创建了一个具有 4 个输入和一个输出的简单 MLP 回归 Keras 模型。我现在将这个模型转换为 TFlite,我只是想了解如何在 android studio 上测试它。如何输入多个 4D 对象
我需要从源代码构建 TensorFlowLite Swift Framework/cocoapod,然后在其中一个 Swift 项目中使用它而不是原始框架。 下载了代码并在少数情况下按照说明进行操作,
我在 android studio 上运行 Tensorflow 示例 ( https://github.com/tensorflow/examples/blob/master/lite/exampl
我从以下存储库中克隆了适用于 iOS 的 TensorFlowLite 示例应用程序 https://github.com/tensorflow/examples/tree/master/lite/e
我已经能够使用下面的代码实现无状态模型 import os os.environ['TF_ENABLE_CONTROL_FLOW_V2'] = '1' import tensorflow as tf
我正在使用 MLKiT 加载自定义 tensoflow 模型而读取模型时出现以下错误 java.lang.IllegalArgumentException:无法在类型为 UINT8 的 TensorF
我正在尝试在 Linux 机器上使用 C++ 运行和测试 Tensorflow Lite 推理。它不是嵌入式系统,也没有 ARM 处理器,这使得它变得困难。我已经按照位于主网站 (https://ww
最近几天我一直在尝试这个。我已经从 here 下载了一个示例.我已经替换了模型 Detect.tflite 和标签文件并使用了我自己的文件,但最终出现了几个错误,如下所示: java.lang.Ill
我正在尝试运行我自己的自定义模型来进行对象检测。我从 Google 云 - Vision (https://console.cloud.google.com/vision/) 创建了我的数据集(我对图
我是一名优秀的程序员,十分优秀!