8
8
import android .util .Log ;
9
9
10
10
import org .tensorflow .lite .Interpreter ;
11
- import org .tensorflow .lite .Tensor ;
12
11
import org .tensorflow .lite .gpu .CompatibilityList ;
13
12
import org .tensorflow .lite .gpu .GpuDelegate ;
14
- import org .tensorflow .lite .gpu .GpuDelegateFactory ;
15
13
16
14
import java .io .BufferedReader ;
17
15
import java .io .FileInputStream ;
@@ -59,12 +57,6 @@ public Yolo(Context context,
59
57
this .rotation = rotation ;
60
58
}
61
59
62
- public Tensor getInputTensor () {
63
- if (interpreter == null ) return null ;
64
- return this .interpreter .getInputTensor (0 );
65
- }
66
-
67
-
68
60
public void initialize_model () throws Exception {
69
61
AssetManager asset_manager = null ;
70
62
MappedByteBuffer buffer ;
@@ -89,17 +81,17 @@ public void initialize_model() throws Exception {
89
81
buffer = file_channel .map (FileChannel .MapMode .READ_ONLY , 0 , file_channel .size ());
90
82
}
91
83
84
+ // Initialize interpreter with GPU delegate
92
85
Interpreter .Options interpreterOptions = new Interpreter .Options ();
93
- CompatibilityList compatibilityList = new CompatibilityList ();
86
+ CompatibilityList compatList = new CompatibilityList ();
94
87
95
- if (use_gpu && compatibilityList .isDelegateSupportedOnThisDevice ()) {
88
+ if (use_gpu && compatList .isDelegateSupportedOnThisDevice ()) {
96
89
try {
97
- GpuDelegateFactory .Options delegateOptions = compatibilityList .getBestOptionsForThisDevice ();
98
- GpuDelegate gpuDelegate = new GpuDelegate (delegateOptions . setQuantizedModelsAllowed ( this . quantization ) );
90
+ GpuDelegate .Options delegateOptions = compatList .getBestOptionsForThisDevice ();
91
+ GpuDelegate gpuDelegate = new GpuDelegate (delegateOptions );
99
92
interpreterOptions .addDelegate (gpuDelegate );
100
93
} catch (Exception e ) {
101
94
Log .e ("Yolo" , "GPU delegate failed, falling back to CPU" , e );
102
- interpreterOptions = new Interpreter .Options ();
103
95
interpreterOptions .setNumThreads (num_threads );
104
96
}
105
97
} else {
@@ -266,9 +258,6 @@ protected static List<float[]> nms(List<float[]> boxes, float iou_threshold) {
266
258
}
267
259
}
268
260
269
- public boolean isInitialized () {
270
- return interpreter != null ;
271
- }
272
261
273
262
274
263
protected List <float []> restore_size (List <float []> nms ,
0 commit comments