Skip to content
Merged
Show file tree
Hide file tree
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
31 changes: 31 additions & 0 deletions webnn/batch_normalization.https.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// META: title=test WebNN API batchNormalization operation
// META: global=window,dedicatedworker
// META: script=./resources/utils.js
// META: timeout=long

'use strict';

// https://webmachinelearning.github.io/webnn/#api-mlgraphbuilder-batchnorm

const buildBatchNorm = (operationName, builder, resources) => {
// MLOperand batchNormalization(MLOperand input, MLOperand mean, MLOperand variance,
// optional MLBatchNormalizationOptions options = {});
const namedOutputOperand = {};
const [inputOperand, meanOperand, varianceOperand] = createMultiInputOperands(builder, resources);
const batchNormOptions = {...resources.options};
if (batchNormOptions.scale) {
batchNormOptions.scale = createConstantOperand(builder, batchNormOptions.scale);
}
if (batchNormOptions.bias) {
batchNormOptions.bias = createConstantOperand(builder, batchNormOptions.bias);
}
if (batchNormOptions.activation) {
batchNormOptions.activation = builder[batchNormOptions.activation]();
}
// invoke builder.batchNormalization()
namedOutputOperand[resources.expected.name] =
builder[operationName](inputOperand, meanOperand, varianceOperand, batchNormOptions);
return namedOutputOperand;
};

testWebNNOperation('batchNormalization', '/webnn/resources/test_data/batch_normalization.json', buildBatchNorm);
Loading