Skip to content

Commit

Permalink
Replace devicePreference as deviceType (#185)
Browse files Browse the repository at this point in the history
As the implementation will soon support the MLDeviceType enum.
  • Loading branch information
Honry authored Nov 2, 2023
1 parent 0b4b3c3 commit b138e20
Show file tree
Hide file tree
Showing 17 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion face_recognition/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ async function main() {
// UI shows model loading progress
await ui.showProgressComponent('current', 'pending', 'pending');
console.log('- Loading weights... ');
const contextOptions = {'devicePreference': deviceType};
const contextOptions = {deviceType};
if (powerPreference) {
contextOptions['powerPreference'] = powerPreference;
}
Expand Down
2 changes: 1 addition & 1 deletion facial_landmark_detection/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ async function main() {
// UI shows model loading progress
await ui.showProgressComponent('current', 'pending', 'pending');
console.log('- Loading weights... ');
const contextOptions = {'devicePreference': deviceType};
const contextOptions = {deviceType};
if (powerPreference) {
contextOptions['powerPreference'] = powerPreference;
}
Expand Down
6 changes: 3 additions & 3 deletions facial_landmark_detection/ssd_mobilenetv2_face_nchw.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {buildConstantByNpy} from '../common/utils.js';
export class SsdMobilenetV2FaceNchw {
constructor() {
this.context_ = null;
this.devicePreference_ = null;
this.deviceType_ = null;
this.builder_ = null;
this.graph_ = null;
this.weightsUrl_ = '../test-data/models/ssd_mobilenetv2_face_nchw/weights/';
Expand Down Expand Up @@ -78,7 +78,7 @@ ${nameArray[1]}`;
// TODO: Set clamp activation to options once it's supported in
// WebNN DML backend.
// Implement `clip` by `clamp` of WebNN API
if (this.devicePreference_ == 'gpu') {
if (this.deviceType_ == 'gpu') {
return this.builder_.clamp(
this.builder_.conv2d(input, weights, options),
{minValue: 0, maxValue: 6});
Expand Down Expand Up @@ -119,7 +119,7 @@ ${nameArray[1]}`;

async load(contextOptions) {
this.context_ = await navigator.ml.createContext(contextOptions);
this.devicePreference_ = contextOptions.devicePreference;
this.deviceType_ = contextOptions.deviceType;
this.builder_ = new MLGraphBuilder(this.context_);
const input = this.builder_.input('input',
{type: 'float32', dimensions: this.inputOptions.inputDimensions});
Expand Down
6 changes: 3 additions & 3 deletions facial_landmark_detection/ssd_mobilenetv2_face_nhwc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {buildConstantByNpy} from '../common/utils.js';
export class SsdMobilenetV2FaceNhwc {
constructor() {
this.context_ = null;
this.devicePreference_ = null;
this.deviceType_ = null;
this.builder_ = null;
this.graph_ = null;
this.weightsUrl_ = '../test-data/models/ssd_mobilenetv2_face_nhwc/weights/';
Expand Down Expand Up @@ -85,7 +85,7 @@ ${nameArray[1]}`;
// TODO: Set clamp activation to options once it's supported in
// WebNN DML backend.
// Implement `clip` by `clamp` of WebNN API
if (this.devicePreference_ == 'gpu') {
if (this.deviceType_ == 'gpu') {
return this.builder_.clamp(
this.builder_.conv2d(input, weights, options),
{minValue: 0, maxValue: 6});
Expand Down Expand Up @@ -126,7 +126,7 @@ ${nameArray[1]}`;

async load(contextOptions) {
this.context_ = await navigator.ml.createContext(contextOptions);
this.devicePreference_ = contextOptions.devicePreference;
this.deviceType_ = contextOptions.deviceType;
this.builder_ = new MLGraphBuilder(this.context_);
const input = this.builder_.input('input',
{type: 'float32', dimensions: this.inputOptions.inputDimensions});
Expand Down
2 changes: 1 addition & 1 deletion image_classification/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ async function main() {
// UI shows model loading progress
await ui.showProgressComponent('current', 'pending', 'pending');
console.log('- Loading weights... ');
const contextOptions = {'devicePreference': deviceType};
const contextOptions = {deviceType};
if (powerPreference) {
contextOptions['powerPreference'] = powerPreference;
}
Expand Down
6 changes: 3 additions & 3 deletions image_classification/mobilenet_nchw.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {buildConstantByNpy} from '../common/utils.js';
export class MobileNetV2Nchw {
constructor() {
this.context_ = null;
this.devicePreference_ = null;
this.deviceType_ = null;
this.builder_ = null;
this.graph_ = null;
this.weightsUrl_ = '../test-data/models/mobilenetv2_nchw/weights/';
Expand Down Expand Up @@ -34,7 +34,7 @@ export class MobileNetV2Nchw {
// TODO: Set clamp activation to options once it's supported in
// WebNN DML backend.
// Implement `clip` by `clamp` of WebNN API
if (this.devicePreference_ == 'gpu') {
if (this.deviceType_ == 'gpu') {
return this.builder_.clamp(
this.builder_.conv2d(input, weights, options),
{minValue: 0, maxValue: 6});
Expand Down Expand Up @@ -76,7 +76,7 @@ export class MobileNetV2Nchw {

async load(contextOptions) {
this.context_ = await navigator.ml.createContext(contextOptions);
this.devicePreference_ = contextOptions.devicePreference;
this.deviceType_ = contextOptions.deviceType;
this.builder_ = new MLGraphBuilder(this.context_);
const data = this.builder_.input('input',
{type: 'float32', dimensions: this.inputOptions.inputDimensions});
Expand Down
6 changes: 3 additions & 3 deletions image_classification/mobilenet_nhwc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {buildConstantByNpy} from '../common/utils.js';
export class MobileNetV2Nhwc {
constructor() {
this.context_ = null;
this.devicePreference_ = null;
this.deviceType_ = null;
this.builder_ = null;
this.graph_ = null;
this.weightsUrl_ = '../test-data/models/mobilenetv2_nhwc/weights/';
Expand All @@ -33,7 +33,7 @@ export class MobileNetV2Nhwc {
// TODO: Set clamp activation to options once it's supported in
// WebNN DML backend.
// Implement `clip` by `clamp` of WebNN API
if (this.devicePreference_ == 'gpu') {
if (this.deviceType_ == 'gpu') {
return this.builder_.clamp(
this.builder_.conv2d(input, weights, options),
{minValue: 0, maxValue: 6});
Expand Down Expand Up @@ -66,7 +66,7 @@ export class MobileNetV2Nhwc {

async load(contextOptions) {
this.context_ = await navigator.ml.createContext(contextOptions);
this.devicePreference_ = contextOptions.devicePreference;
this.deviceType_ = contextOptions.deviceType;
this.builder_ = new MLGraphBuilder(this.context_);
const strides = [2, 2];
const autoPad = 'same-upper';
Expand Down
2 changes: 1 addition & 1 deletion lenet/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async function main() {
const lenet = new LeNet(weightUrl);
const [numRuns, powerPreference, numThreads] = utils.getUrlParams();
try {
const contextOptions = {'devicePreference': deviceType};
const contextOptions = {deviceType};
if (powerPreference) {
contextOptions['powerPreference'] = powerPreference;
}
Expand Down
2 changes: 1 addition & 1 deletion nsnet2/denoiser.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class Denoiser {
const start = performance.now();
const weightsUrl = '../test-data/models/nsnet2/weights/';
const powerPreference = getUrlParams()[1];
const contextOptions = {'devicePreference': deviceType};
const contextOptions = {deviceType};
if (powerPreference) {
contextOptions['powerPreference'] = powerPreference;
}
Expand Down
2 changes: 1 addition & 1 deletion object_detection/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ async function main() {
// UI shows model loading progress
await ui.showProgressComponent('current', 'pending', 'pending');
console.log('- Loading weights... ');
const contextOptions = {'devicePreference': deviceType};
const contextOptions = {deviceType};
if (powerPreference) {
contextOptions['powerPreference'] = powerPreference;
}
Expand Down
6 changes: 3 additions & 3 deletions object_detection/ssd_mobilenetv1_nchw.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {buildConstantByNpy} from '../common/utils.js';
export class SsdMobilenetV1Nchw {
constructor() {
this.context_ = null;
this.devicePreference_ = null;
this.deviceType_ = null;
this.model_ = null;
this.builder_ = null;
this.graph_ = null;
Expand Down Expand Up @@ -64,7 +64,7 @@ ${nameArray[1]}_BatchNorm_batchnorm`;
// TODO: Set clamp activation to options once it's supported in
// WebNN DML backend.
// Implement `clip` by `clamp` of WebNN API
if (this.devicePreference_ == 'gpu') {
if (this.deviceType_ == 'gpu') {
return this.builder_.clamp(
this.builder_.conv2d(input, weights, options),
{minValue: 0, maxValue: 6});
Expand All @@ -77,7 +77,7 @@ ${nameArray[1]}_BatchNorm_batchnorm`;

async load(contextOptions) {
this.context_ = await navigator.ml.createContext(contextOptions);
this.devicePreference_ = contextOptions.devicePreference;
this.deviceType_ = contextOptions.deviceType;
this.builder_ = new MLGraphBuilder(this.context_);
const input = this.builder_.input('input',
{type: 'float32', dimensions: this.inputOptions.inputDimensions});
Expand Down
6 changes: 3 additions & 3 deletions object_detection/ssd_mobilenetv1_nhwc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {buildConstantByNpy} from '../common/utils.js';
export class SsdMobilenetV1Nhwc {
constructor() {
this.context_ = null;
this.devicePreference_ = null;
this.deviceType_ = null;
this.model_ = null;
this.builder_ = null;
this.graph_ = null;
Expand Down Expand Up @@ -75,7 +75,7 @@ ${nameArray[1]}_BatchNorm_batchnorm`;
// TODO: Set clamp activation to options once it's supported in
// WebNN DML backend.
// Implement `clip` by `clamp` of WebNN API
if (this.devicePreference_ == 'gpu') {
if (this.deviceType_ == 'gpu') {
return this.builder_.clamp(
this.builder_.conv2d(input, weights, options),
{minValue: 0, maxValue: 6});
Expand All @@ -88,7 +88,7 @@ ${nameArray[1]}_BatchNorm_batchnorm`;

async load(contextOptions) {
this.context_ = await navigator.ml.createContext(contextOptions);
this.devicePreference_ = contextOptions.devicePreference;
this.deviceType_ = contextOptions.deviceType;
this.builder_ = new MLGraphBuilder(this.context_);
const input = this.builder_.input('input',
{type: 'float32', dimensions: this.inputOptions.inputDimensions});
Expand Down
2 changes: 1 addition & 1 deletion rnnoise/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export async function main() {
`[${batchSize} (batch_size) x 100 (frames) x 42].`, true);
await log(modelInfo, '- Loading model...');
const powerPreference = utils.getUrlParams()[1];
const contextOptions = {'devicePreference': deviceType};
const contextOptions = {deviceType};
if (powerPreference) {
contextOptions['powerPreference'] = powerPreference;
}
Expand Down
6 changes: 3 additions & 3 deletions semantic_segmentation/deeplabv3_mnv2_nchw.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {buildConstantByNpy} from '../common/utils.js';
export class DeepLabV3MNV2Nchw {
constructor() {
this.context_ = null;
this.devicePreference_ = null;
this.deviceType_ = null;
this.builder_ = null;
this.graph_ = null;
this.weightsUrl_ = '../test-data/models/deeplabv3_mnv2_nchw/weights/';
Expand Down Expand Up @@ -47,7 +47,7 @@ export class DeepLabV3MNV2Nchw {
// TODO: Set clamp activation to options once it's supported in
// WebNN DML backend.
// Implement `clip` by `clamp` of WebNN API
if (this.devicePreference_ == 'gpu') {
if (this.deviceType_ == 'gpu') {
return this.builder_.clamp(
this.builder_.conv2d(input, weights, options),
{minValue: 0, maxValue: 6});
Expand Down Expand Up @@ -91,7 +91,7 @@ export class DeepLabV3MNV2Nchw {

async load(contextOptions) {
this.context_ = await navigator.ml.createContext(contextOptions);
this.devicePreference_ = contextOptions.devicePreference;
this.deviceType_ = contextOptions.deviceType;
this.builder_ = new MLGraphBuilder(this.context_);
const strides = [2, 2];

Expand Down
6 changes: 3 additions & 3 deletions semantic_segmentation/deeplabv3_mnv2_nhwc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {buildConstantByNpy} from '../common/utils.js';
export class DeepLabV3MNV2Nhwc {
constructor() {
this.context_ = null;
this.devicePreference_ = null;
this.deviceType_ = null;
this.builder_ = null;
this.graph_ = null;
this.weightsUrl_ = '../test-data/models/deeplabv3_mnv2_nhwc/weights/';
Expand Down Expand Up @@ -47,7 +47,7 @@ export class DeepLabV3MNV2Nhwc {
// TODO: Set clamp activation to options once it's supported in
// WebNN DML backend.
// Implement `clip` by `clamp` of WebNN API
if (this.devicePreference_ == 'gpu') {
if (this.deviceType_ == 'gpu') {
return this.builder_.clamp(
this.builder_.conv2d(input, weights, options),
{minValue: 0, maxValue: 6});
Expand Down Expand Up @@ -80,7 +80,7 @@ export class DeepLabV3MNV2Nhwc {

async load(contextOptions) {
this.context_ = await navigator.ml.createContext(contextOptions);
this.devicePreference_ = contextOptions.devicePreference;
this.deviceType_ = contextOptions.deviceType;
this.builder_ = new MLGraphBuilder(this.context_);
const strides = [2, 2];
const input = this.builder_.input('input',
Expand Down
2 changes: 1 addition & 1 deletion semantic_segmentation/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ export async function main() {
// UI shows model loading progress
await ui.showProgressComponent('current', 'pending', 'pending');
console.log('- Loading weights... ');
const contextOptions = {'devicePreference': deviceType};
const contextOptions = {deviceType};
if (powerPreference) {
contextOptions['powerPreference'] = powerPreference;
}
Expand Down
2 changes: 1 addition & 1 deletion style_transfer/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export async function main() {
// UI shows model loading progress
await ui.showProgressComponent('current', 'pending', 'pending');
console.log('- Loading weights... ');
const contextOptions = {'devicePreference': deviceType};
const contextOptions = {deviceType};
if (powerPreference) {
contextOptions['powerPreference'] = powerPreference;
}
Expand Down

0 comments on commit b138e20

Please sign in to comment.