Skip to content

Commit

Permalink
Deploying to gh-pages from @ 570a55c 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
huningxin committed Nov 14, 2024
1 parent daf1064 commit c051e03
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
7 changes: 5 additions & 2 deletions common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion face_recognition/facenet_nchw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion nnotepad/js/nnotepad.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions nsnet2/nsnet2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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]});
Expand Down

0 comments on commit c051e03

Please sign in to comment.