diff --git a/common/utils.js b/common/utils.js index a9c089e2..f7c61cec 100644 --- a/common/utils.js +++ b/common/utils.js @@ -306,8 +306,11 @@ export function getUrlParams() { export async function isWebNN() { if (typeof MLGraphBuilder !== 'undefined') { - const context = await navigator.ml.createContext(); - return !context.tf; + // Polyfill MLTensorUsage to make it compatible with old version of Chrome. + if (typeof MLTensorUsage == 'undefined') { + window.MLTensorUsage = {WEBGPU_INTEROP: 1, READ: 2, WRITE: 4}; + } + return true; } else { return false; } diff --git a/face_recognition/facenet_nchw.js b/face_recognition/facenet_nchw.js index 1fdbea1a..e5791c4c 100644 --- a/face_recognition/facenet_nchw.js +++ b/face_recognition/facenet_nchw.js @@ -269,7 +269,7 @@ export class FaceNetNchw { const averagePool = this.builder_.averagePool2d(await block8_6); // Use reshape to implement squeeze(averagePool, {axes: [2, 3]}); const squeezed_shape = typeof averagePool.shape === 'function' ? - averagePool.shape() : averagePool.shape; + averagePool.shape() : [...averagePool.shape]; squeezed_shape.splice(2, 2); const squeeze = this.builder_.reshape(averagePool, squeezed_shape); const gemm = await this.buildGemm_(squeeze); diff --git a/nnotepad/js/nnotepad.js b/nnotepad/js/nnotepad.js index 315b9f5a..21906a63 100644 --- a/nnotepad/js/nnotepad.js +++ b/nnotepad/js/nnotepad.js @@ -52,7 +52,8 @@ class WebNNUtil { dataType: isShapeMethod ? operand.dataType() : operand.dataType, dimensions: isShapeMethod ? operand.shape() : operand.shape, shape: isShapeMethod ? operand.shape() : operand.shape, - usage: MLTensorUsage.READ, + usage: typeof MLTensorUsage == 'undefined' ? + undefined : MLTensorUsage.READ, readable: true, }; const tensor = await context.createTensor(desc); diff --git a/nsnet2/nsnet2.js b/nsnet2/nsnet2.js index 401f9dd6..f467ffe0 100644 --- a/nsnet2/nsnet2.js +++ b/nsnet2/nsnet2.js @@ -59,7 +59,7 @@ export class NSNet2 { {bias: bias194, recurrentBias: recurrentBias194, initialHiddenState: initialState92, returnSequence: true}); // Use reshape to implement squeeze(gru93, {axes: [1]}); const isShapeMethod = typeof gru93.shape === 'function'; - const squeeze95Shape = isShapeMethod ? gru93.shape() : gru93.shape; + const squeeze95Shape = isShapeMethod ? gru93.shape() : [...gru93.shape]; squeeze95Shape.splice(1, 1); const squeeze95 = this.builder_.reshape(gru93, squeeze95Shape); const initialState155 = this.builder_.input('initialState155', initialStateDesc); @@ -90,7 +90,7 @@ export class NSNet2 { const [gru157, gru156] = this.builder_.gru(squeeze95, weight212, recurrentWeight213, frames, this.hiddenSize, {bias: bias214, recurrentBias: recurrentBias214, initialHiddenState: initialState155, returnSequence: true}); // Use reshape to implement squeeze(gru156, {axes: [1]}); - const squeeze158Shape = isShapeMethod ? gru156.shape() : gru156.shape; + const squeeze158Shape = isShapeMethod ? gru156.shape() : [...gru156.shape]; squeeze158Shape.splice(1, 1); const squeeze158 = this.builder_.reshape(gru156, squeeze158Shape); const transpose159 = this.builder_.transpose(squeeze158, {permutation: [1, 0, 2]});