From 692b9215587522c6ae12e1c71867b61b5c877157 Mon Sep 17 00:00:00 2001 From: Belem Zhang Date: Wed, 27 Mar 2024 14:25:26 +0800 Subject: [PATCH] Fix the netInstance.dispose is not a function issue (#209) --- image_classification/resnet50v2_nchw.js | 8 ++++++++ image_classification/resnet50v2_nhwc.js | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/image_classification/resnet50v2_nchw.js b/image_classification/resnet50v2_nchw.js index 706f943d..e683230c 100644 --- a/image_classification/resnet50v2_nchw.js +++ b/image_classification/resnet50v2_nchw.js @@ -163,6 +163,14 @@ export class ResNet50V2Nchw { this.graph_ = this.builder_.build({'output': outputOperand}); } + // Release the constant tensors of a model + dispose() { + // dispose() is only available in webnn-polyfill + if (this.graph_ !== null && 'dispose' in this.graph_) { + this.graph_.dispose(); + } + } + // Release the constant tensors of a model async compute(inputBuffer, outputBuffer) { const inputs = {'input': inputBuffer}; diff --git a/image_classification/resnet50v2_nhwc.js b/image_classification/resnet50v2_nhwc.js index 4fddf166..9e5bccc8 100644 --- a/image_classification/resnet50v2_nhwc.js +++ b/image_classification/resnet50v2_nhwc.js @@ -191,6 +191,14 @@ export class ResNet50V2Nhwc { this.graph_ = this.builder_.build({'output': outputOperand}); } + // Release the constant tensors of a model + dispose() { + // dispose() is only available in webnn-polyfill + if (this.graph_ !== null && 'dispose' in this.graph_) { + this.graph_.dispose(); + } + } + // Release the constant tensors of a model async compute(inputBuffer, outputBuffer) { const inputs = {'input': inputBuffer};