Browse Source

fix(face-landmarks): human helper tensor disposal and async functions (#11596)

* fix(face-landmarks): human helper tensor disposal and async functions

* fix(face-landmarks): rename functions in interface
master
Gabriel Borlea 3 years ago
parent
commit
11d61d6d7d
No account linked to committer's email address
1 changed files with 8 additions and 6 deletions
  1. 8
    6
      react/features/face-landmarks/FaceLandmarksHelper.ts

+ 8
- 6
react/features/face-landmarks/FaceLandmarksHelper.ts View File

30
 };
30
 };
31
 
31
 
32
 export interface FaceLandmarksHelper {
32
 export interface FaceLandmarksHelper {
33
-    detectFaceBox({ detections, threshold }: Detection): Promise<FaceBox | undefined>;
34
-    detectFaceExpression({ detections }: Detection): Promise<string | undefined>;
33
+    getFaceBox({ detections, threshold }: Detection): FaceBox | undefined;
34
+    getFaceExpression({ detections }: Detection): string | undefined;
35
     init(): Promise<void>;
35
     init(): Promise<void>;
36
     detect({ image, threshold } : DetectInput): Promise<DetectOutput | undefined>;
36
     detect({ image, threshold } : DetectInput): Promise<DetectOutput | undefined>;
37
     getDetectionInProgress(): boolean;
37
     getDetectionInProgress(): boolean;
118
         }
118
         }
119
     }
119
     }
120
 
120
 
121
-    async detectFaceBox({ detections, threshold }: Detection): Promise<FaceBox | undefined> {
121
+    getFaceBox({ detections, threshold }: Detection): FaceBox | undefined {
122
         if (!detections.length) {
122
         if (!detections.length) {
123
             return;
123
             return;
124
         }
124
         }
140
         return faceBox;
140
         return faceBox;
141
     }
141
     }
142
 
142
 
143
-    async detectFaceExpression({ detections }: Detection): Promise<string | undefined> {
143
+    getFaceExpression({ detections }: Detection): string | undefined {
144
         if (detections[0]?.emotion) {
144
         if (detections[0]?.emotion) {
145
             return  FACE_EXPRESSIONS_NAMING_MAPPING[detections[0]?.emotion[0].emotion];
145
             return  FACE_EXPRESSIONS_NAMING_MAPPING[detections[0]?.emotion[0].emotion];
146
         }
146
         }
156
         }
156
         }
157
 
157
 
158
         this.detectionInProgress = true;
158
         this.detectionInProgress = true;
159
+        this.human.tf.engine().startScope();
159
 
160
 
160
         const imageTensor = this.human.tf.browser.fromPixels(image);
161
         const imageTensor = this.human.tf.browser.fromPixels(image);
161
 
162
 
163
             const { face } = await this.human.detect(imageTensor, this.config);
164
             const { face } = await this.human.detect(imageTensor, this.config);
164
 
165
 
165
             detections = face;
166
             detections = face;
166
-            faceExpression = await this.detectFaceExpression({ detections });
167
+            faceExpression = this.getFaceExpression({ detections });
167
         }
168
         }
168
 
169
 
169
         if (this.faceDetectionTypes.includes(DETECTION_TYPES.FACE_BOX)) {
170
         if (this.faceDetectionTypes.includes(DETECTION_TYPES.FACE_BOX)) {
173
                 detections = face;
174
                 detections = face;
174
             }
175
             }
175
 
176
 
176
-            faceBox = await this.detectFaceBox({
177
+            faceBox = this.getFaceBox({
177
                 detections,
178
                 detections,
178
                 threshold
179
                 threshold
179
             });
180
             });
180
         }
181
         }
181
 
182
 
183
+        this.human.tf.engine().endScope();
182
         this.detectionInProgress = false;
184
         this.detectionInProgress = false;
183
 
185
 
184
         return { 
186
         return { 

Loading…
Cancel
Save