Skip to content

Commit b138e20

Browse files
authored
Replace devicePreference as deviceType (#185)
As the implementation will soon support the MLDeviceType enum.
1 parent 0b4b3c3 commit b138e20

17 files changed

Lines changed: 33 additions & 33 deletions

File tree

face_recognition/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ async function main() {
317317
// UI shows model loading progress
318318
await ui.showProgressComponent('current', 'pending', 'pending');
319319
console.log('- Loading weights... ');
320-
const contextOptions = {'devicePreference': deviceType};
320+
const contextOptions = {deviceType};
321321
if (powerPreference) {
322322
contextOptions['powerPreference'] = powerPreference;
323323
}

facial_landmark_detection/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ async function main() {
252252
// UI shows model loading progress
253253
await ui.showProgressComponent('current', 'pending', 'pending');
254254
console.log('- Loading weights... ');
255-
const contextOptions = {'devicePreference': deviceType};
255+
const contextOptions = {deviceType};
256256
if (powerPreference) {
257257
contextOptions['powerPreference'] = powerPreference;
258258
}

facial_landmark_detection/ssd_mobilenetv2_face_nchw.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {buildConstantByNpy} from '../common/utils.js';
66
export class SsdMobilenetV2FaceNchw {
77
constructor() {
88
this.context_ = null;
9-
this.devicePreference_ = null;
9+
this.deviceType_ = null;
1010
this.builder_ = null;
1111
this.graph_ = null;
1212
this.weightsUrl_ = '../test-data/models/ssd_mobilenetv2_face_nchw/weights/';
@@ -78,7 +78,7 @@ ${nameArray[1]}`;
7878
// TODO: Set clamp activation to options once it's supported in
7979
// WebNN DML backend.
8080
// Implement `clip` by `clamp` of WebNN API
81-
if (this.devicePreference_ == 'gpu') {
81+
if (this.deviceType_ == 'gpu') {
8282
return this.builder_.clamp(
8383
this.builder_.conv2d(input, weights, options),
8484
{minValue: 0, maxValue: 6});
@@ -119,7 +119,7 @@ ${nameArray[1]}`;
119119

120120
async load(contextOptions) {
121121
this.context_ = await navigator.ml.createContext(contextOptions);
122-
this.devicePreference_ = contextOptions.devicePreference;
122+
this.deviceType_ = contextOptions.deviceType;
123123
this.builder_ = new MLGraphBuilder(this.context_);
124124
const input = this.builder_.input('input',
125125
{type: 'float32', dimensions: this.inputOptions.inputDimensions});

facial_landmark_detection/ssd_mobilenetv2_face_nhwc.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {buildConstantByNpy} from '../common/utils.js';
66
export class SsdMobilenetV2FaceNhwc {
77
constructor() {
88
this.context_ = null;
9-
this.devicePreference_ = null;
9+
this.deviceType_ = null;
1010
this.builder_ = null;
1111
this.graph_ = null;
1212
this.weightsUrl_ = '../test-data/models/ssd_mobilenetv2_face_nhwc/weights/';
@@ -85,7 +85,7 @@ ${nameArray[1]}`;
8585
// TODO: Set clamp activation to options once it's supported in
8686
// WebNN DML backend.
8787
// Implement `clip` by `clamp` of WebNN API
88-
if (this.devicePreference_ == 'gpu') {
88+
if (this.deviceType_ == 'gpu') {
8989
return this.builder_.clamp(
9090
this.builder_.conv2d(input, weights, options),
9191
{minValue: 0, maxValue: 6});
@@ -126,7 +126,7 @@ ${nameArray[1]}`;
126126

127127
async load(contextOptions) {
128128
this.context_ = await navigator.ml.createContext(contextOptions);
129-
this.devicePreference_ = contextOptions.devicePreference;
129+
this.deviceType_ = contextOptions.deviceType;
130130
this.builder_ = new MLGraphBuilder(this.context_);
131131
const input = this.builder_.input('input',
132132
{type: 'float32', dimensions: this.inputOptions.inputDimensions});

image_classification/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ async function main() {
238238
// UI shows model loading progress
239239
await ui.showProgressComponent('current', 'pending', 'pending');
240240
console.log('- Loading weights... ');
241-
const contextOptions = {'devicePreference': deviceType};
241+
const contextOptions = {deviceType};
242242
if (powerPreference) {
243243
contextOptions['powerPreference'] = powerPreference;
244244
}

image_classification/mobilenet_nchw.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {buildConstantByNpy} from '../common/utils.js';
66
export class MobileNetV2Nchw {
77
constructor() {
88
this.context_ = null;
9-
this.devicePreference_ = null;
9+
this.deviceType_ = null;
1010
this.builder_ = null;
1111
this.graph_ = null;
1212
this.weightsUrl_ = '../test-data/models/mobilenetv2_nchw/weights/';
@@ -34,7 +34,7 @@ export class MobileNetV2Nchw {
3434
// TODO: Set clamp activation to options once it's supported in
3535
// WebNN DML backend.
3636
// Implement `clip` by `clamp` of WebNN API
37-
if (this.devicePreference_ == 'gpu') {
37+
if (this.deviceType_ == 'gpu') {
3838
return this.builder_.clamp(
3939
this.builder_.conv2d(input, weights, options),
4040
{minValue: 0, maxValue: 6});
@@ -76,7 +76,7 @@ export class MobileNetV2Nchw {
7676

7777
async load(contextOptions) {
7878
this.context_ = await navigator.ml.createContext(contextOptions);
79-
this.devicePreference_ = contextOptions.devicePreference;
79+
this.deviceType_ = contextOptions.deviceType;
8080
this.builder_ = new MLGraphBuilder(this.context_);
8181
const data = this.builder_.input('input',
8282
{type: 'float32', dimensions: this.inputOptions.inputDimensions});

image_classification/mobilenet_nhwc.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {buildConstantByNpy} from '../common/utils.js';
88
export class MobileNetV2Nhwc {
99
constructor() {
1010
this.context_ = null;
11-
this.devicePreference_ = null;
11+
this.deviceType_ = null;
1212
this.builder_ = null;
1313
this.graph_ = null;
1414
this.weightsUrl_ = '../test-data/models/mobilenetv2_nhwc/weights/';
@@ -33,7 +33,7 @@ export class MobileNetV2Nhwc {
3333
// TODO: Set clamp activation to options once it's supported in
3434
// WebNN DML backend.
3535
// Implement `clip` by `clamp` of WebNN API
36-
if (this.devicePreference_ == 'gpu') {
36+
if (this.deviceType_ == 'gpu') {
3737
return this.builder_.clamp(
3838
this.builder_.conv2d(input, weights, options),
3939
{minValue: 0, maxValue: 6});
@@ -66,7 +66,7 @@ export class MobileNetV2Nhwc {
6666

6767
async load(contextOptions) {
6868
this.context_ = await navigator.ml.createContext(contextOptions);
69-
this.devicePreference_ = contextOptions.devicePreference;
69+
this.deviceType_ = contextOptions.deviceType;
7070
this.builder_ = new MLGraphBuilder(this.context_);
7171
const strides = [2, 2];
7272
const autoPad = 'same-upper';

lenet/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ async function main() {
6868
const lenet = new LeNet(weightUrl);
6969
const [numRuns, powerPreference, numThreads] = utils.getUrlParams();
7070
try {
71-
const contextOptions = {'devicePreference': deviceType};
71+
const contextOptions = {deviceType};
7272
if (powerPreference) {
7373
contextOptions['powerPreference'] = powerPreference;
7474
}

nsnet2/denoiser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class Denoiser {
3131
const start = performance.now();
3232
const weightsUrl = '../test-data/models/nsnet2/weights/';
3333
const powerPreference = getUrlParams()[1];
34-
const contextOptions = {'devicePreference': deviceType};
34+
const contextOptions = {deviceType};
3535
if (powerPreference) {
3636
contextOptions['powerPreference'] = powerPreference;
3737
}

object_detection/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ async function main() {
219219
// UI shows model loading progress
220220
await ui.showProgressComponent('current', 'pending', 'pending');
221221
console.log('- Loading weights... ');
222-
const contextOptions = {'devicePreference': deviceType};
222+
const contextOptions = {deviceType};
223223
if (powerPreference) {
224224
contextOptions['powerPreference'] = powerPreference;
225225
}

0 commit comments

Comments
 (0)