Skip to content

Commit

Permalink
Fix object detection sample (webmachinelearning#169)
Browse files Browse the repository at this point in the history
* Fix concat issue of ssd_mobilenetv1_nhwc.js for XNNPACK

* Avoid using fused leakyRelu in tiny_yolov2_nhwc.js

* Fix detached output ArrayBufferView issue of object_detection sample

* Fix the lint errors
  • Loading branch information
huningxin authored Mar 30, 2023
1 parent f666c59 commit 781291f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion object_detection/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ async function main() {
for (let i = 0; i < numRuns; i++) {
start = performance.now();
results = await netInstance.compute(
results.inputs.input, outputs);
results.inputs.input, results.outputs);
computeTime = (performance.now() - start).toFixed(2);
console.log(` compute time ${i+1}: ${computeTime} ms`);
computeTimeArray.push(Number(computeTime));
Expand Down
10 changes: 8 additions & 2 deletions object_detection/ssd_mobilenetv1_nhwc.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,11 @@ ${nameArray[1]}_BatchNorm_batchnorm`;
const conv27 = await this.buildConv_(
conv21, ['BoxEncoding', '5', '', '167__cf__170'], false);
const reshape5 = this.builder_.reshape(conv27, [1, 6, 1, 4]);
// XNNPACK doesn't support concat inputs size > 4.
const concatReshape0123 = this.builder_.concat(
[reshape0, reshape1, reshape2, reshape3], 1);
const concat0 = this.builder_.concat(
[reshape0, reshape1, reshape2, reshape3, reshape4, reshape5], 1);
[concatReshape0123, reshape4, reshape5], 1);

// Second concatenation
const conv28 = await this.buildConv_(
Expand All @@ -214,8 +217,11 @@ ${nameArray[1]}_BatchNorm_batchnorm`;
const conv33 = await this.buildConv_(
conv21, ['Class', '5', '', '41__cf__44'], false);
const reshape11 = this.builder_.reshape(conv33, [1, 6, 91]);
// XNNPACK doesn't support concat inputs size > 4.
const concatReshape6789 = this.builder_.concat(
[reshape6, reshape7, reshape8, reshape9], 1);
const concat1 = this.builder_.concat(
[reshape6, reshape7, reshape8, reshape9, reshape10, reshape11], 1);
[concatReshape6789, reshape10, reshape11], 1);

return {'boxes': concat0, 'scores': concat1};
}
Expand Down
7 changes: 4 additions & 3 deletions object_detection/tiny_yolov2_nhwc.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ export class TinyYoloV2Nhwc {
autoPad: 'same-upper',
};
options.bias = bias;
let conv = this.builder_.conv2d(input, weights, options);
if (leakyRelu) {
options.activation =
this.builder_.leakyRelu({alpha: 0.10000000149011612});
// Fused leakyRelu is not supported by XNNPACK.
conv = this.builder_.leakyRelu(conv, {alpha: 0.10000000149011612});
}
return this.builder_.conv2d(input, weights, options);
return conv;
}

async load(contextOptions) {
Expand Down

0 comments on commit 781291f

Please sign in to comment.