普通获取:
interpreter.run(input,output);
tflite Interpreter的源码
public void run(Object input, Object output) {
Object[] inputs = new Object[]{input};
Map<Integer, Object> outputs = new HashMap();
outputs.put(0, output);
this.runForMultipleInputsOutputs(inputs, outputs);
}
public void runForMultipleInputsOutputs(Object[] inputs, @NonNull Map<Integer, Object> outputs) {
this.checkNotClosed();
this.wrapper.run(inputs, outputs);
}
可以看到,多个input、output可采用runForMultipleInputsOutputs,并且run最后也是要跑runForMultipleInputsOutputs这个函数,把run中的操作移到自己的代码中就可以了
#以下修改基于官方给的cat_va_dog的demo
Bitmap scaledBitmap =Bitmap.createScaledBitmap(bitmap,INPUT_SIZE,INPUT_SIZE,false);
ByteBuffer bytebuffer = convertBitmapToByteBuffer(scaledBitmap);
Object[] btmp = new Object[]{bytebuffer};
float[][][] result = new float[1][2944][18];#第一个output的维度
float[][][] result1 = new float[1][2944][1];#第二个output的维度
Map<Integer, Object> outputs = new HashMap();
outputs.put(0, result);
outputs.put(1, result1);
interpreter.runForMultipleInputsOutputs(btmp,outputs);
result = (float[][][])outputs.get(1);#获取第二个output