react-native-vision-camera-spoof-detector 1.0.7 → 1.0.8

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.
Files changed (66) hide show
  1. package/android/.cxx/Debug/2a1it684/arm64-v8a/.cmake/api/v1/reply/{codemodel-v2-390962e2784a6a84fa3e.json → codemodel-v2-501c3f4eb817726556cc.json} +2 -2
  2. package/android/.cxx/Debug/2a1it684/arm64-v8a/.cmake/api/v1/reply/{index-2025-11-25T14-48-56-0722.json → index-2025-11-25T16-55-22-0685.json} +2 -2
  3. package/android/.cxx/Debug/2a1it684/arm64-v8a/.cmake/api/v1/reply/{target-yuv-Debug-1e27b8a2bdcddd47b87d.json → target-yuv-Debug-63fdb78450b0b16b8484.json} +4 -4
  4. package/android/.cxx/Debug/2a1it684/arm64-v8a/.cmake/api/v1/reply/{target-yuv_shared-Debug-ac9194487d1fc1268a87.json → target-yuv_shared-Debug-5c8b5c6f50bc8769a5bd.json} +4 -4
  5. package/android/.cxx/Debug/2a1it684/arm64-v8a/.ninja_deps +0 -0
  6. package/android/.cxx/Debug/2a1it684/arm64-v8a/.ninja_log +124 -124
  7. package/android/.cxx/Debug/2a1it684/arm64-v8a/CMakeFiles/CMakeOutput.log +22 -22
  8. package/android/.cxx/Debug/2a1it684/arm64-v8a/configure_fingerprint.bin +15 -15
  9. package/android/.cxx/Debug/2a1it684/armeabi-v7a/.cmake/api/v1/reply/{codemodel-v2-52ac1d8b40b69596389b.json → codemodel-v2-053850119b681f93cecc.json} +2 -2
  10. package/android/.cxx/Debug/2a1it684/armeabi-v7a/.cmake/api/v1/reply/{index-2025-11-25T14-14-30-0191.json → index-2025-11-25T16-21-43-0410.json} +2 -2
  11. package/android/.cxx/Debug/2a1it684/armeabi-v7a/.cmake/api/v1/reply/{target-yuv-Debug-97f9e822dbd84a186d44.json → target-yuv-Debug-a12ad49ff79080871bce.json} +2 -2
  12. package/android/.cxx/Debug/2a1it684/armeabi-v7a/.cmake/api/v1/reply/{target-yuv_shared-Debug-3730d20e27c3481c06b2.json → target-yuv_shared-Debug-2b00e64621a56b8dd632.json} +2 -2
  13. package/android/.cxx/Debug/2a1it684/armeabi-v7a/.ninja_deps +0 -0
  14. package/android/.cxx/Debug/2a1it684/armeabi-v7a/.ninja_log +176 -117
  15. package/android/.cxx/Debug/2a1it684/armeabi-v7a/CMakeFiles/CMakeOutput.log +20 -20
  16. package/android/.cxx/Debug/2a1it684/armeabi-v7a/configure_fingerprint.bin +15 -15
  17. package/android/.cxx/Debug/2a1it684/x86/.ninja_deps +0 -0
  18. package/android/.cxx/Debug/2a1it684/x86/.ninja_log +164 -109
  19. package/android/.cxx/Debug/2a1it684/x86/CMakeFiles/CMakeOutput.log +20 -20
  20. package/android/.cxx/Debug/2a1it684/x86/configure_fingerprint.bin +15 -15
  21. package/android/.cxx/Debug/2a1it684/x86_64/.ninja_deps +0 -0
  22. package/android/.cxx/Debug/2a1it684/x86_64/.ninja_log +109 -109
  23. package/android/.cxx/Debug/2a1it684/x86_64/CMakeFiles/CMakeOutput.log +20 -20
  24. package/android/.cxx/Debug/2a1it684/x86_64/configure_fingerprint.bin +15 -15
  25. package/android/build/.transforms/4ebf3dd0dca4f83fe1776360e21ded81/transformed/classes/classes_dex/classes.dex +0 -0
  26. package/android/build/.transforms/c0a07cd9442d741ad3cef3760159211f/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/faceantispoof/AcceleratorConfig.dex +0 -0
  27. package/android/build/.transforms/c0a07cd9442d741ad3cef3760159211f/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/faceantispoof/AntiSpoofingResult.dex +0 -0
  28. package/android/build/.transforms/c0a07cd9442d741ad3cef3760159211f/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/faceantispoof/FaceAntiSpoofingAdvanced$SpoofDetectionResult.dex +0 -0
  29. package/android/build/.transforms/c0a07cd9442d741ad3cef3760159211f/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/faceantispoof/FaceAntiSpoofingAdvanced.dex +0 -0
  30. package/android/build/intermediates/compile_library_classes_jar/debug/bundleLibCompileToJarDebug/classes.jar +0 -0
  31. package/android/build/intermediates/cxx/Debug/2a1it684/logs/arm64-v8a/build_stdout_targets.txt +50 -50
  32. package/android/build/intermediates/cxx/Debug/2a1it684/logs/arm64-v8a/generate_cxx_metadata_1041_timing.txt +9 -0
  33. package/android/build/intermediates/cxx/Debug/2a1it684/logs/armeabi-v7a/build_stdout_targets.txt +44 -44
  34. package/android/build/intermediates/cxx/Debug/2a1it684/logs/armeabi-v7a/{generate_cxx_metadata_455_timing.txt → generate_cxx_metadata_1042_timing.txt} +1 -1
  35. package/android/build/intermediates/cxx/Debug/2a1it684/logs/x86/build_stdout_targets.txt +34 -34
  36. package/android/build/intermediates/cxx/Debug/2a1it684/logs/x86/{generate_cxx_metadata_455_timing.txt → generate_cxx_metadata_1042_timing.txt} +1 -1
  37. package/android/build/intermediates/cxx/Debug/2a1it684/logs/x86_64/build_stdout_targets.txt +38 -38
  38. package/android/build/intermediates/cxx/Debug/2a1it684/logs/x86_64/generate_cxx_metadata_1042_timing.txt +9 -0
  39. package/android/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties +1 -1
  40. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/faceantispoof/AcceleratorConfig.class +0 -0
  41. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/faceantispoof/AntiSpoofingResult.class +0 -0
  42. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/faceantispoof/FaceAntiSpoofingAdvanced$SpoofDetectionResult.class +0 -0
  43. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/faceantispoof/FaceAntiSpoofingAdvanced.class +0 -0
  44. package/android/build/intermediates/runtime_library_classes_jar/debug/bundleLibRuntimeToJarDebug/classes.jar +0 -0
  45. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab +0 -0
  46. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.values.at +0 -0
  47. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab +0 -0
  48. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.keystream +0 -0
  49. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.keystream.len +0 -0
  50. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.len +0 -0
  51. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.values.at +0 -0
  52. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab_i +0 -0
  53. package/android/build/kotlin/compileDebugKotlin/cacheable/last-build.bin +0 -0
  54. package/android/build/kotlin/compileDebugKotlin/classpath-snapshot/shrunk-classpath-snapshot.bin +0 -0
  55. package/android/build/kotlin/compileDebugKotlin/local-state/build-history.bin +0 -0
  56. package/android/build/tmp/kotlin-classes/debug/com/faceantispoof/AcceleratorConfig.class +0 -0
  57. package/android/build/tmp/kotlin-classes/debug/com/faceantispoof/AntiSpoofingResult.class +0 -0
  58. package/android/build/tmp/kotlin-classes/debug/com/faceantispoof/FaceAntiSpoofingAdvanced$SpoofDetectionResult.class +0 -0
  59. package/android/build/tmp/kotlin-classes/debug/com/faceantispoof/FaceAntiSpoofingAdvanced.class +0 -0
  60. package/android/src/main/java/com/faceantispoof/AcceleratorConfig.kt +57 -9
  61. package/android/src/main/java/com/faceantispoof/FaceAntiSpoofingAdvanced.kt +115 -22
  62. package/package.json +1 -1
  63. package/android/build/intermediates/cxx/Debug/2a1it684/logs/arm64-v8a/generate_cxx_metadata_456_timing.txt +0 -9
  64. package/android/build/intermediates/cxx/Debug/2a1it684/logs/x86_64/generate_cxx_metadata_455_timing.txt +0 -9
  65. /package/android/.cxx/Debug/2a1it684/x86/.cmake/api/v1/reply/{index-2025-11-25T14-14-37-0548.json → index-2025-11-25T16-21-51-0349.json} +0 -0
  66. /package/android/.cxx/Debug/2a1it684/x86_64/.cmake/api/v1/reply/{index-2025-11-25T14-49-17-0490.json → index-2025-11-25T16-55-39-0849.json} +0 -0
@@ -3,12 +3,14 @@ package com.faceantispoof
3
3
  /**
4
4
  * Configuration class for TensorFlow Lite accelerators
5
5
  * Allows developers to control GPU/NNAPI delegate behavior
6
+ * and optimize for different device tiers (low-end, mid-range, high-end)
6
7
  */
7
8
  object AcceleratorConfig {
8
9
 
9
10
  /**
10
11
  * Enable GPU acceleration (recommended for modern devices)
11
12
  * Accelerates model 3-10x compared to CPU
13
+ * GPU is automatically skipped on low-end devices even if enabled
12
14
  */
13
15
  var enableGpu: Boolean = true
14
16
 
@@ -16,34 +18,80 @@ object AcceleratorConfig {
16
18
  * Enable NNAPI acceleration (recommended for Pixel/Samsung devices)
17
19
  * Accelerates model 3-10x compared to CPU
18
20
  * Fallback if GPU is not available
21
+ * Works better on mid-range and high-end devices
19
22
  */
20
23
  var enableNnapi: Boolean = true
21
24
 
22
25
  /**
23
26
  * Enable CPU fallback if GPU/NNAPI are not available
24
- * Default: true
27
+ * Default: true (always fallback to CPU)
25
28
  */
26
29
  var enableCpuFallback: Boolean = true
27
30
 
28
31
  /**
29
32
  * Number of threads for CPU inference
30
- * Default: 4 threads
33
+ * Default: 4 threads (optimal for most devices)
34
+ * Low-end devices will use 1-2 threads regardless
31
35
  */
32
36
  var cpuThreadCount: Int = 4
33
37
 
34
38
  /**
35
- * Print debug logs for accelerator selection
39
+ * Force CPU-only mode for all devices
40
+ * Useful for debugging or if GPU/NNAPI causes issues
41
+ * Default: false
42
+ */
43
+ var forceCpuOnly: Boolean = false
44
+
45
+ /**
46
+ * Disable GPU delegate specifically
47
+ * Keeps NNAPI enabled if available
48
+ * Default: false
49
+ */
50
+ var disableGpuDelegate: Boolean = false
51
+
52
+ /**
53
+ * Disable NNAPI delegate specifically
54
+ * GPU will still be attempted if enabled
55
+ * Default: false
56
+ */
57
+ var disableNnapiDelegate: Boolean = false
58
+
59
+ /**
60
+ * Print debug logs for accelerator selection and performance
61
+ * Default: true
36
62
  */
37
63
  var debugLogging: Boolean = true
38
64
 
65
+ /**
66
+ * Enable aggressive optimization for low-end devices
67
+ * Reduces memory usage and processes fewer frames
68
+ * Default: true
69
+ */
70
+ var optimizeForLowEndDevices: Boolean = true
71
+
72
+ /**
73
+ * Maximum memory (in MB) to allocate for the interpreter
74
+ * Low-end devices will use less aggressive settings
75
+ * Default: 0 (use system defaults)
76
+ */
77
+ var maxMemoryAllocation: Int = 0
78
+
39
79
  override fun toString(): String {
40
80
  return """
41
- AcceleratorConfig:
42
- - GPU Enabled: $enableGpu
43
- - NNAPI Enabled: $enableNnapi
44
- - CPU Fallback: $enableCpuFallback
45
- - CPU Threads: $cpuThreadCount
46
- - Debug Logging: $debugLogging
81
+ ╔════════════════════════════════════════════════╗
82
+ ║ TFLite Accelerator Configuration ║
83
+ ╠════════════════════════════════════════════════╣
84
+ GPU Acceleration: $enableGpu
85
+ NNAPI Acceleration: $enableNnapi
86
+ CPU Fallback: $enableCpuFallback
87
+ ║ CPU Threads: $cpuThreadCount
88
+ ║ Force CPU Only: $forceCpuOnly
89
+ ║ Disable GPU Delegate: $disableGpuDelegate
90
+ ║ Disable NNAPI Delegate: $disableNnapiDelegate
91
+ ║ Debug Logging: $debugLogging
92
+ ║ Optimize Low-End: $optimizeForLowEndDevices
93
+ ║ Max Memory (MB): $maxMemoryAllocation
94
+ ╚════════════════════════════════════════════════╝
47
95
  """.trimIndent()
48
96
  }
49
97
  }
@@ -96,22 +96,15 @@ class FaceAntiSpoofingAdvanced(private val assetManager: AssetManager) {
96
96
  try {
97
97
  val modelBuffer = loadModelFile(assetManager, MODEL_FILE)
98
98
  val options = Interpreter.Options()
99
- options.setNumThreads(4)
100
99
 
101
- if (tryAddGpuDelegate(options)) {
102
- currentAccelerator = ACCELERATOR_GPU
103
- Log.i(TAG, "GPU delegate enabled successfully")
104
- }
105
- else {
106
- try {
107
- options.setUseNNAPI(true)
108
- currentAccelerator = ACCELERATOR_NNAPI
109
- Log.i(TAG, "NNAPI enabled successfully")
110
- } catch (e: Exception) {
111
- currentAccelerator = ACCELERATOR_CPU
112
- Log.i(TAG, "Running on CPU (GPU/NNAPI not available): ${e.message}")
113
- }
114
- }
100
+ // FORCE CPU-ONLY MODE FOR LOW-END DEVICE COMPATIBILITY
101
+ // This bypasses all GPU/NNAPI issues and uses stable CPU inference
102
+ val optimalThreads = getOptimalThreadCount()
103
+ options.setNumThreads(optimalThreads)
104
+
105
+ currentAccelerator = ACCELERATOR_CPU
106
+ Log.i(TAG, "✓ FORCED CPU-ONLY MODE - Bypassing GPU/NNAPI")
107
+ Log.i(TAG, "Using $optimalThreads threads for CPU inference")
115
108
 
116
109
  interpreter = Interpreter(modelBuffer, options)
117
110
 
@@ -126,28 +119,46 @@ class FaceAntiSpoofingAdvanced(private val assetManager: AssetManager) {
126
119
  outputs[outputIndex0] = clssPred
127
120
  outputs[outputIndex1] = leafNodeMask
128
121
  isInitialized = true
129
- Log.i(TAG, "Interpreter initialized with accelerator: $currentAccelerator")
122
+ Log.i(TAG, " Face Anti-Spoof initialized | CPU-ONLY MODE | Threads: $optimalThreads")
130
123
  } catch (e: Exception) {
131
- Log.e(TAG, "Failed to load TFLite model", e)
124
+ Log.e(TAG, "Failed to load TFLite model: ${e.message}", e)
132
125
  isInitialized = false
126
+ currentAccelerator = ACCELERATOR_CPU
133
127
  }
134
128
  }
135
129
 
136
130
  private fun tryAddGpuDelegate(options: Interpreter.Options): Boolean {
137
131
  return try {
132
+ // Additional check: verify device has minimum Android version for GPU delegate
133
+ if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
134
+ Log.w(TAG, "GPU delegate requires Android 5.0+, device running: ${android.os.Build.VERSION.SDK_INT}")
135
+ return false
136
+ }
137
+
138
138
  val compatibilityList = CompatibilityList()
139
139
  if (compatibilityList.isDelegateSupportedOnThisDevice) {
140
- gpuDelegate = GpuDelegate(compatibilityList.bestOptionsForThisDevice)
141
- options.addDelegate(gpuDelegate)
142
- Log.d(TAG, "GPU delegate added successfully")
143
- true
140
+ try {
141
+ gpuDelegate = GpuDelegate(compatibilityList.bestOptionsForThisDevice)
142
+ options.addDelegate(gpuDelegate)
143
+ Log.d(TAG, "GPU delegate added successfully")
144
+ true
145
+ } catch (e: Exception) {
146
+ Log.w(TAG, "Failed to initialize GPU delegate after compatibility check: ${e.message}")
147
+ gpuDelegate?.close()
148
+ gpuDelegate = null
149
+ false
150
+ }
144
151
  } else {
145
152
  Log.d(TAG, "GPU delegate not supported on this device")
146
153
  false
147
154
  }
148
155
  } catch (e: Exception) {
149
156
  Log.w(TAG, "Failed to add GPU delegate: ${e.message}")
150
- gpuDelegate?.close()
157
+ try {
158
+ gpuDelegate?.close()
159
+ } catch (e2: Exception) {
160
+ Log.w(TAG, "Error closing GPU delegate: ${e2.message}")
161
+ }
151
162
  gpuDelegate = null
152
163
  false
153
164
  }
@@ -772,6 +783,88 @@ class FaceAntiSpoofingAdvanced(private val assetManager: AssetManager) {
772
783
  Log.e(TAG, "Error closing interpreter", e)
773
784
  }
774
785
  }
786
+
787
+ /**
788
+ * Detects if the device is high-end based on RAM, processor, and Android version.
789
+ * High-end devices can use GPU/NNAPI delegates.
790
+ * Low-end devices default to optimized CPU inference.
791
+ */
792
+ private fun isHighEndDevice(): Boolean {
793
+ try {
794
+ // Check Android version
795
+ if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
796
+ Log.d(TAG, "Device running Android ${android.os.Build.VERSION.SDK_INT} (< 5.0) - low-end")
797
+ return false
798
+ }
799
+
800
+ // Check available RAM
801
+ val runtime = Runtime.getRuntime()
802
+ val maxMemory = runtime.maxMemory() / (1024 * 1024) // Convert to MB
803
+ if (maxMemory < 256) { // Less than 256MB allocated
804
+ Log.d(TAG, "Low available RAM: ${maxMemory}MB - treating as low-end device")
805
+ return false
806
+ }
807
+
808
+ // Check processor cores (devices with 2 cores or less are typically low-end)
809
+ val processorCount = Runtime.getRuntime().availableProcessors()
810
+ if (processorCount <= 2) {
811
+ Log.d(TAG, "Limited CPU cores: $processorCount - low-end device")
812
+ return false
813
+ }
814
+
815
+ // Check device name for known low-end models
816
+ val model = android.os.Build.MODEL.lowercase()
817
+ val lowEndMarkers = listOf(
818
+ "moto g", "samsung a", "samsung j", "redmi 6", "redmi 7",
819
+ "honor 8a", "galaxy a01", "galaxy j2"
820
+ )
821
+
822
+ for (marker in lowEndMarkers) {
823
+ if (model.contains(marker)) {
824
+ Log.d(TAG, "Known low-end device model: ${android.os.Build.MODEL}")
825
+ return false
826
+ }
827
+ }
828
+
829
+ Log.d(TAG, "Device appears to be high-end (Android ${android.os.Build.VERSION.SDK_INT}, $processorCount cores, ${maxMemory}MB RAM)")
830
+ return true
831
+ } catch (e: Exception) {
832
+ Log.w(TAG, "Error detecting device tier: ${e.message}, defaulting to CPU-only")
833
+ return false
834
+ }
835
+ }
836
+
837
+ /**
838
+ * Calculates optimal thread count based on available processors and device resources.
839
+ * Low-end devices use 1-2 threads to avoid memory issues.
840
+ */
841
+ private fun getOptimalThreadCount(): Int {
842
+ return try {
843
+ val availableProcessors = Runtime.getRuntime().availableProcessors()
844
+
845
+ // For low-end devices, limit thread count
846
+ if (!isHighEndDevice()) {
847
+ Log.d(TAG, "Low-end device: limiting threads to 1-2")
848
+ return maxOf(1, minOf(2, availableProcessors - 1))
849
+ }
850
+
851
+ // For high-end devices, use configured count or optimal calculation
852
+ val configured = AcceleratorConfig.cpuThreadCount
853
+ val optimal = maxOf(1, availableProcessors - 1)
854
+
855
+ val threadCount = if (configured > 0) {
856
+ minOf(configured, availableProcessors)
857
+ } else {
858
+ optimal
859
+ }
860
+
861
+ Log.d(TAG, "Optimal thread count: $threadCount (available processors: $availableProcessors)")
862
+ threadCount
863
+ } catch (e: Exception) {
864
+ Log.w(TAG, "Error calculating optimal threads: ${e.message}, using default")
865
+ AcceleratorConfig.cpuThreadCount
866
+ }
867
+ }
775
868
  }
776
869
 
777
870
  data class AntiSpoofingResult(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-vision-camera-spoof-detector",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
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/jescon-tech/react-native-vision-camera-spoof-detector",
6
6
  "repository": {
@@ -1,9 +0,0 @@
1
- # C/C++ build system timings
2
- generate_cxx_metadata
3
- execute-generate-process
4
- exec-configure 718ms
5
- [gap of 21ms]
6
- execute-generate-process completed in 741ms
7
- [gap of 17ms]
8
- generate_cxx_metadata completed in 767ms
9
-
@@ -1,9 +0,0 @@
1
- # C/C++ build system timings
2
- generate_cxx_metadata
3
- execute-generate-process
4
- exec-configure 486ms
5
- [gap of 23ms]
6
- execute-generate-process completed in 511ms
7
- [gap of 20ms]
8
- generate_cxx_metadata completed in 541ms
9
-