Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions image_classification/mobilenet_uint8_nhwc.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ export class MobileNetV2Uint8Nhwc {
}

dequantizeLinear_(input, quantizateParams, dataType) {
// WebNN dequantizeLinear op requires the rank of scale and zeroPoint should be same as input.
const missingDims = input.shape.length - quantizateParams.shape.length;
if (missingDims > 0) {
quantizateParams.shape.push(...Array(missingDims).fill(1));
}

const scale = this.builder_.constant( {dataType: 'float32', shape: quantizateParams.shape},
new Float32Array(quantizateParams.scale));
let zeroPoint;
Expand All @@ -41,6 +47,12 @@ export class MobileNetV2Uint8Nhwc {
}

quantizeLinear_(input, quantizateParams) {
// WebNN quantizeLinear op requires the rank of scale and zeroPoint should be same as input.
const missingDims = input.shape.length - quantizateParams.shape.length;
if (missingDims > 0) {
quantizateParams.shape.push(...Array(missingDims).fill(1));
}

const scale = this.builder_.constant( {dataType: 'float32', shape: quantizateParams.shape},
new Float32Array(quantizateParams.scale));
const zeroPoint = this.builder_.constant( {dataType: 'uint8', shape: quantizateParams.shape},
Expand Down