File tree Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -130,10 +130,12 @@ class ImageClassifier {
130
130
* @return {object } an object with {label, confidence}.
131
131
*/
132
132
async classifyInternal ( imgToPredict , numberOfClasses ) {
133
+
133
134
// Wait for the model to be ready
134
135
await this . ready ;
135
136
await tf . nextFrame ( ) ;
136
137
138
+
137
139
if ( imgToPredict instanceof HTMLVideoElement && imgToPredict . readyState === 0 ) {
138
140
const video = imgToPredict ;
139
141
// Wait for the video to be ready
@@ -168,9 +170,13 @@ class ImageClassifier {
168
170
return results ;
169
171
}
170
172
171
- return this . model
173
+ const result = this . model
172
174
. classify ( processedImg , numberOfClasses )
173
175
. then ( classes => classes . map ( c => ( { label : c . className , confidence : c . probability } ) ) ) ;
176
+
177
+ processedImg . dispose ( ) ;
178
+
179
+ return result ;
174
180
}
175
181
176
182
/**
You can’t perform that action at this time.
0 commit comments