Skip to content

Commit 6e99efc

Browse files
authored
dispose of processed image (#680)
1 parent 2d35106 commit 6e99efc

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/ImageClassifier/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,12 @@ class ImageClassifier {
130130
* @return {object} an object with {label, confidence}.
131131
*/
132132
async classifyInternal(imgToPredict, numberOfClasses) {
133+
133134
// Wait for the model to be ready
134135
await this.ready;
135136
await tf.nextFrame();
136137

138+
137139
if (imgToPredict instanceof HTMLVideoElement && imgToPredict.readyState === 0) {
138140
const video = imgToPredict;
139141
// Wait for the video to be ready
@@ -168,9 +170,13 @@ class ImageClassifier {
168170
return results;
169171
}
170172

171-
return this.model
173+
const result = this.model
172174
.classify(processedImg, numberOfClasses)
173175
.then(classes => classes.map(c => ({ label: c.className, confidence: c.probability })));
176+
177+
processedImg.dispose();
178+
179+
return result;
174180
}
175181

176182
/**

0 commit comments

Comments
 (0)