File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,12 @@ export class MobileNetV2Uint8Nhwc {
2525 }
2626
2727 dequantizeLinear_ ( input , quantizateParams , dataType ) {
28+ // WebNN dequantizeLinear op requires the rank of scale and zeroPoint should be same as input.
29+ const missingDims = input . shape . length - quantizateParams . shape . length ;
30+ if ( missingDims > 0 ) {
31+ quantizateParams . shape . push ( ...Array ( missingDims ) . fill ( 1 ) ) ;
32+ }
33+
2834 const scale = this . builder_ . constant ( { dataType : 'float32' , shape : quantizateParams . shape } ,
2935 new Float32Array ( quantizateParams . scale ) ) ;
3036 let zeroPoint ;
@@ -41,6 +47,12 @@ export class MobileNetV2Uint8Nhwc {
4147 }
4248
4349 quantizeLinear_ ( input , quantizateParams ) {
50+ // WebNN quantizeLinear op requires the rank of scale and zeroPoint should be same as input.
51+ const missingDims = input . shape . length - quantizateParams . shape . length ;
52+ if ( missingDims > 0 ) {
53+ quantizateParams . shape . push ( ...Array ( missingDims ) . fill ( 1 ) ) ;
54+ }
55+
4456 const scale = this . builder_ . constant ( { dataType : 'float32' , shape : quantizateParams . shape } ,
4557 new Float32Array ( quantizateParams . scale ) ) ;
4658 const zeroPoint = this . builder_ . constant ( { dataType : 'uint8' , shape : quantizateParams . shape } ,
You can’t perform that action at this time.
0 commit comments