159 lines
5.1 KiB
Java
159 lines
5.1 KiB
Java
package org.tensorflow.lite;
|
|
|
|
import java.nio.ByteBuffer;
|
|
import java.nio.ByteOrder;
|
|
import java.nio.MappedByteBuffer;
|
|
import java.util.Map;
|
|
import o.C15516gsl;
|
|
|
|
/* loaded from: classes6.dex */
|
|
public final class NativeInterpreterWrapper implements AutoCloseable {
|
|
public boolean a;
|
|
public long b = -1;
|
|
public long c;
|
|
public Map<String, Integer> d;
|
|
public long e;
|
|
private ByteBuffer f;
|
|
private final Tensor[] g;
|
|
public Map<String, Integer> h;
|
|
private long i;
|
|
public final Tensor[] j;
|
|
|
|
public static native long allocateTensors(long j, long j2);
|
|
|
|
public static native long createErrorReporter(int i);
|
|
|
|
public static native long createInterpreter(long j, long j2, int i);
|
|
|
|
public static native long createModel(String str, long j);
|
|
|
|
public static native long createModelWithBuffer(ByteBuffer byteBuffer, long j);
|
|
|
|
public static native void delete(long j, long j2, long j3);
|
|
|
|
public static native int getInputCount(long j);
|
|
|
|
public static native String[] getInputNames(long j);
|
|
|
|
public static native int getInputTensorIndex(long j, int i);
|
|
|
|
public static native int getOutputCount(long j);
|
|
|
|
public static native String[] getOutputNames(long j);
|
|
|
|
public static native int getOutputTensorIndex(long j, int i);
|
|
|
|
public static native boolean resizeInput(long j, long j2, int i, int[] iArr);
|
|
|
|
public static native boolean run(long j, long j2);
|
|
|
|
public static native void useNNAPI(long j, boolean z);
|
|
|
|
public NativeInterpreterWrapper(String str) {
|
|
this.a = false;
|
|
C15516gsl.HBt hBt = new C15516gsl.HBt();
|
|
long createErrorReporter = createErrorReporter(512);
|
|
this.e = createErrorReporter;
|
|
long createModel = createModel(str, createErrorReporter);
|
|
this.i = createModel;
|
|
long createInterpreter = createInterpreter(createModel, this.e, hBt.c);
|
|
this.c = createInterpreter;
|
|
this.a = true;
|
|
this.g = new Tensor[getInputCount(createInterpreter)];
|
|
this.j = new Tensor[getOutputCount(this.c)];
|
|
boolean z = hBt.b;
|
|
}
|
|
|
|
public NativeInterpreterWrapper(ByteBuffer byteBuffer) {
|
|
this.a = false;
|
|
C15516gsl.HBt hBt = new C15516gsl.HBt();
|
|
if (byteBuffer == null || (!(byteBuffer instanceof MappedByteBuffer) && (!byteBuffer.isDirect() || byteBuffer.order() != ByteOrder.nativeOrder()))) {
|
|
throw new IllegalArgumentException("Model ByteBuffer should be either a MappedByteBuffer of the model file, or a direct ByteBuffer using ByteOrder.nativeOrder() which contains bytes of model content.");
|
|
}
|
|
this.f = byteBuffer;
|
|
long createErrorReporter = createErrorReporter(512);
|
|
this.e = createErrorReporter;
|
|
long createModelWithBuffer = createModelWithBuffer(this.f, createErrorReporter);
|
|
this.i = createModelWithBuffer;
|
|
long createInterpreter = createInterpreter(createModelWithBuffer, this.e, hBt.c);
|
|
this.c = createInterpreter;
|
|
this.a = true;
|
|
this.g = new Tensor[getInputCount(createInterpreter)];
|
|
this.j = new Tensor[getOutputCount(this.c)];
|
|
boolean z = hBt.d;
|
|
boolean z2 = hBt.b;
|
|
}
|
|
|
|
@Override // java.lang.AutoCloseable
|
|
public final void close() {
|
|
int i = 0;
|
|
while (true) {
|
|
Tensor[] tensorArr = this.g;
|
|
if (i >= tensorArr.length) {
|
|
break;
|
|
}
|
|
Tensor tensor = tensorArr[i];
|
|
if (tensor != null) {
|
|
Tensor.delete(tensor.d);
|
|
tensor.d = 0L;
|
|
this.g[i] = null;
|
|
}
|
|
i++;
|
|
}
|
|
int i2 = 0;
|
|
while (true) {
|
|
Tensor[] tensorArr2 = this.j;
|
|
if (i2 < tensorArr2.length) {
|
|
Tensor tensor2 = tensorArr2[i2];
|
|
if (tensor2 != null) {
|
|
Tensor.delete(tensor2.d);
|
|
tensor2.d = 0L;
|
|
this.j[i2] = null;
|
|
}
|
|
i2++;
|
|
} else {
|
|
delete(this.e, this.i, this.c);
|
|
this.e = 0L;
|
|
this.i = 0L;
|
|
this.c = 0L;
|
|
this.f = null;
|
|
this.d = null;
|
|
this.h = null;
|
|
this.a = false;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
public final void b(int i, int[] iArr) {
|
|
if (resizeInput(this.c, this.e, i, iArr)) {
|
|
this.a = false;
|
|
Tensor tensor = this.g[i];
|
|
if (tensor != null) {
|
|
tensor.b = Tensor.shape(tensor.d);
|
|
}
|
|
}
|
|
}
|
|
|
|
public final Tensor a(int i) {
|
|
if (i >= 0) {
|
|
Tensor[] tensorArr = this.g;
|
|
if (i < tensorArr.length) {
|
|
Tensor tensor = tensorArr[i];
|
|
if (tensor != null) {
|
|
return tensor;
|
|
}
|
|
long j = this.c;
|
|
Tensor b = Tensor.b(j, getInputTensorIndex(j, i));
|
|
tensorArr[i] = b;
|
|
return b;
|
|
}
|
|
}
|
|
throw new IllegalArgumentException("Invalid input Tensor index: ".concat(String.valueOf(i)));
|
|
}
|
|
|
|
static {
|
|
TensorFlowLite.a();
|
|
}
|
|
}
|