react-native-vision-camera-spoof-detector 1.1.19 → 1.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -55,31 +55,60 @@ class FaceAntiSpoofingAdvanced(private val assetManager: AssetManager) {
|
|
|
55
55
|
private fun initializeInterpreter() {
|
|
56
56
|
try {
|
|
57
57
|
val modelBuffer = loadModelFile(assetManager, MODEL_FILE)
|
|
58
|
-
val
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
58
|
+
val optimalThreads = 4
|
|
59
|
+
val compatibilityList = CompatibilityList()
|
|
60
|
+
var selectedAccelerator = ACCELERATOR_CPU
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
if (compatibilityList.isDelegateSupportedOnThisDevice) {
|
|
64
|
+
val delegate = GpuDelegate(compatibilityList.bestOptionsForThisDevice)
|
|
65
|
+
gpuDelegate = delegate
|
|
66
|
+
val options = Interpreter.Options().apply {
|
|
67
|
+
setNumThreads(optimalThreads)
|
|
68
|
+
addDelegate(delegate)
|
|
69
|
+
}
|
|
70
|
+
interpreter = Interpreter(modelBuffer, options)
|
|
71
|
+
selectedAccelerator = ACCELERATOR_GPU
|
|
72
|
+
Log.i(TAG, "Face Anti-Spoof initialized | GPU delegate enabled | Threads: $optimalThreads")
|
|
73
|
+
} else {
|
|
74
|
+
throw IllegalStateException("GPU delegate not supported")
|
|
75
|
+
}
|
|
76
|
+
} catch (e: Exception) {
|
|
77
|
+
Log.w(TAG, "GPU delegate unavailable or failed: ${e.message}", e)
|
|
78
|
+
try {
|
|
79
|
+
val nnapiOptions = org.tensorflow.lite.nnapi.NnApiDelegate()
|
|
80
|
+
val options = Interpreter.Options().apply {
|
|
81
|
+
setNumThreads(optimalThreads)
|
|
82
|
+
addDelegate(nnapiOptions)
|
|
83
|
+
}
|
|
84
|
+
interpreter = Interpreter(modelBuffer, options)
|
|
85
|
+
selectedAccelerator = ACCELERATOR_NNAPI
|
|
86
|
+
Log.i(TAG, "Face Anti-Spoof initialized | NNAPI delegate enabled | Threads: $optimalThreads")
|
|
87
|
+
} catch (nnapiError: Exception) {
|
|
88
|
+
Log.w(TAG, "NNAPI delegate unavailable or failed: ${nnapiError.message}", nnapiError)
|
|
89
|
+
val options = Interpreter.Options().apply {
|
|
90
|
+
setNumThreads(optimalThreads)
|
|
91
|
+
}
|
|
92
|
+
interpreter = Interpreter(modelBuffer, options)
|
|
93
|
+
selectedAccelerator = ACCELERATOR_CPU
|
|
94
|
+
Log.i(TAG, "Face Anti-Spoof initialized | CPU fallback enabled | Threads: $optimalThreads")
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
currentAccelerator = selectedAccelerator
|
|
99
|
+
|
|
69
100
|
try {
|
|
70
101
|
outputIndex0 = interpreter!!.getOutputIndex("Identity")
|
|
71
102
|
outputIndex1 = interpreter!!.getOutputIndex("Identity_1")
|
|
72
103
|
} catch (e: Exception) {
|
|
73
104
|
Log.w(TAG, "Could not resolve named output indices, using defaults: ${e.message}")
|
|
74
|
-
// Fallback to default indices
|
|
75
105
|
outputIndex0 = 0
|
|
76
106
|
outputIndex1 = 1
|
|
77
107
|
}
|
|
78
|
-
|
|
108
|
+
|
|
79
109
|
outputs[outputIndex0] = clssPred
|
|
80
110
|
outputs[outputIndex1] = leafNodeMask
|
|
81
111
|
isInitialized = true
|
|
82
|
-
Log.i(TAG, "Face Anti-Spoof initialized | CPU-ONLY MODE | Threads: $optimalThreads")
|
|
83
112
|
} catch (e: Exception) {
|
|
84
113
|
Log.e(TAG, "FAILED to load TFLite model: ${e.message}", e)
|
|
85
114
|
isInitialized = false
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-vision-camera-spoof-detector",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.20",
|
|
4
4
|
"description": "High-performance face anti-spoofing and liveness detection module for React Native Vision Camera. Uses TensorFlow Lite with GPU acceleration and optimized YUV processing.",
|
|
5
5
|
"homepage": "https://github.com/dpraful/react-native-vision-camera-spoof-detector",
|
|
6
6
|
"repository": {
|