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};