From 1592198c7ef0536f2bc4516b0191b4b67e6ec0ef Mon Sep 17 00:00:00 2001 From: Belem Zhang Date: Thu, 14 Mar 2024 13:54:53 +0800 Subject: [PATCH] Update README to add HTTPS support and change the weights file to CDN service (#196) --- .gitignore | 2 ++ README.md | 4 +++- face_recognition/facenet_nchw.js | 2 +- face_recognition/facenet_nhwc.js | 2 +- facial_landmark_detection/face_landmark_nchw.js | 2 +- facial_landmark_detection/face_landmark_nhwc.js | 2 +- facial_landmark_detection/ssd_mobilenetv2_face_nchw.js | 2 +- facial_landmark_detection/ssd_mobilenetv2_face_nhwc.js | 2 +- image_classification/mobilenet_nchw.js | 2 +- image_classification/mobilenet_nhwc.js | 2 +- image_classification/resnet50v2_nchw.js | 2 +- image_classification/resnet50v2_nhwc.js | 2 +- image_classification/squeezenet_nchw.js | 2 +- image_classification/squeezenet_nhwc.js | 2 +- lenet/main.js | 2 +- nsnet2/denoiser.js | 2 +- object_detection/ssd_mobilenetv1_nchw.js | 4 ++-- object_detection/ssd_mobilenetv1_nhwc.js | 2 +- object_detection/tiny_yolov2_nchw.js | 2 +- object_detection/tiny_yolov2_nhwc.js | 2 +- package.json | 2 +- rnnoise/main.js | 2 +- semantic_segmentation/deeplabv3_mnv2_nchw.js | 4 ++-- semantic_segmentation/deeplabv3_mnv2_nhwc.js | 2 +- style_transfer/fast_style_transfer_net.js | 2 +- 25 files changed, 30 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index b5274872..c6acad15 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ node_modules/ **/*.ark .DS_Store package-lock.json +cert.pem +key.pem diff --git a/README.md b/README.md index 86c01150..76ab08c1 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,9 @@ To get started, follow these steps: 1. Clone the repository to your local machine and navigate to it: ```bash > git clone --recurse-submodules https://github.com/webmachinelearning/webnn-samples -> cd webnn-samples & npm install +> cd webnn-samples +> openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout key.pem -out cert.pem +> npm install > npm start ``` 2. Navigate to the desired sample directory that you want to explore. diff --git a/face_recognition/facenet_nchw.js b/face_recognition/facenet_nchw.js index 7025c01c..a9946432 100644 --- a/face_recognition/facenet_nchw.js +++ b/face_recognition/facenet_nchw.js @@ -12,7 +12,7 @@ export class FaceNetNchw { this.context_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = '../test-data/models/facenet_nchw/weights'; + this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/facenet_nchw/weights'; this.inputOptions = { mean: [127.5, 127.5, 127.5, 127.5], std: [127.5, 127.5, 127.5, 127.5], diff --git a/face_recognition/facenet_nhwc.js b/face_recognition/facenet_nhwc.js index d03a0dd5..0ca056f2 100644 --- a/face_recognition/facenet_nhwc.js +++ b/face_recognition/facenet_nhwc.js @@ -12,7 +12,7 @@ export class FaceNetNhwc { this.context_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = '../test-data/models/facenet_nhwc/weights'; + this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/facenet_nhwc/weights'; this.inputOptions = { mean: [127.5, 127.5, 127.5, 127.5], std: [127.5, 127.5, 127.5, 127.5], diff --git a/facial_landmark_detection/face_landmark_nchw.js b/facial_landmark_detection/face_landmark_nchw.js index 16c1aba8..8f3415a4 100644 --- a/facial_landmark_detection/face_landmark_nchw.js +++ b/facial_landmark_detection/face_landmark_nchw.js @@ -8,7 +8,7 @@ export class FaceLandmarkNchw { this.context_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = '../test-data/models/face_landmark_nchw/weights'; + this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/face_landmark_nchw/weights'; this.inputOptions = { inputLayout: 'nchw', inputDimensions: [1, 3, 128, 128], diff --git a/facial_landmark_detection/face_landmark_nhwc.js b/facial_landmark_detection/face_landmark_nhwc.js index 3c9d6ba1..630c68bc 100644 --- a/facial_landmark_detection/face_landmark_nhwc.js +++ b/facial_landmark_detection/face_landmark_nhwc.js @@ -8,7 +8,7 @@ export class FaceLandmarkNhwc { this.context_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = '../test-data/models/face_landmark_nhwc/weights'; + this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/face_landmark_nhwc/weights'; this.inputOptions = { inputLayout: 'nhwc', inputDimensions: [1, 128, 128, 3], diff --git a/facial_landmark_detection/ssd_mobilenetv2_face_nchw.js b/facial_landmark_detection/ssd_mobilenetv2_face_nchw.js index 2391867c..c8f59573 100644 --- a/facial_landmark_detection/ssd_mobilenetv2_face_nchw.js +++ b/facial_landmark_detection/ssd_mobilenetv2_face_nchw.js @@ -9,7 +9,7 @@ export class SsdMobilenetV2FaceNchw { this.deviceType_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = '../test-data/models/ssd_mobilenetv2_face_nchw/weights/'; + this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/ssd_mobilenetv2_face_nchw/weights/'; this.inputOptions = { inputLayout: 'nchw', margin: [1.2, 1.2, 0.8, 1.1], diff --git a/facial_landmark_detection/ssd_mobilenetv2_face_nhwc.js b/facial_landmark_detection/ssd_mobilenetv2_face_nhwc.js index 0962a6f3..a69528cc 100644 --- a/facial_landmark_detection/ssd_mobilenetv2_face_nhwc.js +++ b/facial_landmark_detection/ssd_mobilenetv2_face_nhwc.js @@ -9,7 +9,7 @@ export class SsdMobilenetV2FaceNhwc { this.deviceType_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = '../test-data/models/ssd_mobilenetv2_face_nhwc/weights/'; + this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/ssd_mobilenetv2_face_nhwc/weights/'; this.inputOptions = { inputLayout: 'nhwc', margin: [1.2, 1.2, 0.8, 1.1], diff --git a/image_classification/mobilenet_nchw.js b/image_classification/mobilenet_nchw.js index efbbcba9..999c9467 100644 --- a/image_classification/mobilenet_nchw.js +++ b/image_classification/mobilenet_nchw.js @@ -9,7 +9,7 @@ export class MobileNetV2Nchw { this.deviceType_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = '../test-data/models/mobilenetv2_nchw/weights/'; + this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/mobilenetv2_nchw/weights/'; this.inputOptions = { mean: [0.485, 0.456, 0.406], std: [0.229, 0.224, 0.225], diff --git a/image_classification/mobilenet_nhwc.js b/image_classification/mobilenet_nhwc.js index 4db2c3f6..bca7e86e 100644 --- a/image_classification/mobilenet_nhwc.js +++ b/image_classification/mobilenet_nhwc.js @@ -11,7 +11,7 @@ export class MobileNetV2Nhwc { this.deviceType_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = '../test-data/models/mobilenetv2_nhwc/weights/'; + this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/mobilenetv2_nhwc/weights/'; this.inputOptions = { mean: [127.5, 127.5, 127.5], std: [127.5, 127.5, 127.5], diff --git a/image_classification/resnet50v2_nchw.js b/image_classification/resnet50v2_nchw.js index ceba8bb9..28d3e64a 100644 --- a/image_classification/resnet50v2_nchw.js +++ b/image_classification/resnet50v2_nchw.js @@ -8,7 +8,7 @@ export class ResNet50V2Nchw { this.context_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = '../test-data/models/resnet50v2_nchw/weights/'; + this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/resnet50v2_nchw/weights/'; this.inputOptions = { mean: [0.485, 0.456, 0.406], std: [0.229, 0.224, 0.225], diff --git a/image_classification/resnet50v2_nhwc.js b/image_classification/resnet50v2_nhwc.js index f54a1376..a6630283 100644 --- a/image_classification/resnet50v2_nhwc.js +++ b/image_classification/resnet50v2_nhwc.js @@ -12,7 +12,7 @@ export class ResNet50V2Nhwc { this.context_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = '../test-data/models/resnet50v2_nhwc/weights/'; + this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/resnet50v2_nhwc/weights/'; this.inputOptions = { mean: [127.5, 127.5, 127.5], std: [127.5, 127.5, 127.5], diff --git a/image_classification/squeezenet_nchw.js b/image_classification/squeezenet_nchw.js index 5373f53c..2274efd8 100644 --- a/image_classification/squeezenet_nchw.js +++ b/image_classification/squeezenet_nchw.js @@ -8,7 +8,7 @@ export class SqueezeNetNchw { this.context_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = '../test-data/models/squeezenet1.1_nchw/weights/'; + this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/squeezenet1.1_nchw/weights/'; this.inputOptions = { mean: [0.485, 0.456, 0.406], std: [0.229, 0.224, 0.225], diff --git a/image_classification/squeezenet_nhwc.js b/image_classification/squeezenet_nhwc.js index eb56104c..857f74d5 100644 --- a/image_classification/squeezenet_nhwc.js +++ b/image_classification/squeezenet_nhwc.js @@ -8,7 +8,7 @@ export class SqueezeNetNhwc { this.context_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = '../test-data/models/squeezenet1.0_nhwc/weights/'; + this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/squeezenet1.0_nhwc/weights/'; this.inputOptions = { mean: [127.5, 127.5, 127.5], std: [127.5, 127.5, 127.5], diff --git a/lenet/main.js b/lenet/main.js index 8d9658de..7b27a130 100644 --- a/lenet/main.js +++ b/lenet/main.js @@ -64,7 +64,7 @@ async function main() { await utils.setBackend(backend, deviceType); drawNextDigitFromMnist(); const pen = new Pen(visualCanvas); - const weightUrl = '../test-data/models/lenet_nchw/weights/lenet.bin'; + const weightUrl = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/lenet_nchw/weights/lenet.bin'; const lenet = new LeNet(weightUrl); const [numRuns, powerPreference, numThreads] = utils.getUrlParams(); try { diff --git a/nsnet2/denoiser.js b/nsnet2/denoiser.js index 6d89650e..c0137765 100644 --- a/nsnet2/denoiser.js +++ b/nsnet2/denoiser.js @@ -29,7 +29,7 @@ export class Denoiser { return new Promise((resolve, reject) => { this.log(' - Loading weights... '); const start = performance.now(); - const weightsUrl = '../test-data/models/nsnet2/weights/'; + const weightsUrl = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/nsnet2/weights/'; const powerPreference = getUrlParams()[1]; const contextOptions = {deviceType}; if (powerPreference) { diff --git a/object_detection/ssd_mobilenetv1_nchw.js b/object_detection/ssd_mobilenetv1_nchw.js index abe6d584..1af75476 100644 --- a/object_detection/ssd_mobilenetv1_nchw.js +++ b/object_detection/ssd_mobilenetv1_nchw.js @@ -10,9 +10,9 @@ export class SsdMobilenetV1Nchw { this.model_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = '../test-data/models/ssd_mobilenetv1_nchw/weights/'; + this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/ssd_mobilenetv1_nchw/weights/'; // Shares the same bias files with 'nhwc' layout - this.biasUrl_ = '../test-data/models/ssd_mobilenetv1_nhwc/weights/'; + this.biasUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/ssd_mobilenetv1_nhwc/weights/'; this.inputOptions = { inputLayout: 'nchw', labelUrl: './labels/coco_classes.txt', diff --git a/object_detection/ssd_mobilenetv1_nhwc.js b/object_detection/ssd_mobilenetv1_nhwc.js index ed03da96..1496a332 100644 --- a/object_detection/ssd_mobilenetv1_nhwc.js +++ b/object_detection/ssd_mobilenetv1_nhwc.js @@ -10,7 +10,7 @@ export class SsdMobilenetV1Nhwc { this.model_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = '../test-data/models/ssd_mobilenetv1_nhwc/weights/'; + this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/ssd_mobilenetv1_nhwc/weights/'; this.inputOptions = { inputLayout: 'nhwc', labelUrl: './labels/coco_classes.txt', diff --git a/object_detection/tiny_yolov2_nchw.js b/object_detection/tiny_yolov2_nchw.js index d86d200d..2881eb10 100644 --- a/object_detection/tiny_yolov2_nchw.js +++ b/object_detection/tiny_yolov2_nchw.js @@ -8,7 +8,7 @@ export class TinyYoloV2Nchw { this.context_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = '../test-data/models/tiny_yolov2_nchw/weights/'; + this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/tiny_yolov2_nchw/weights/'; this.inputOptions = { inputLayout: 'nchw', labelUrl: './labels/pascal_classes.txt', diff --git a/object_detection/tiny_yolov2_nhwc.js b/object_detection/tiny_yolov2_nhwc.js index 9144813c..61e2c6cc 100644 --- a/object_detection/tiny_yolov2_nhwc.js +++ b/object_detection/tiny_yolov2_nhwc.js @@ -8,7 +8,7 @@ export class TinyYoloV2Nhwc { this.context_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = '../test-data/models/tiny_yolov2_nhwc/weights/'; + this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/tiny_yolov2_nhwc/weights/'; this.inputOptions = { inputLayout: 'nhwc', labelUrl: './labels/pascal_classes.txt', diff --git a/package.json b/package.json index 85df811c..3a5ead7b 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ }, "scripts": { "lint": "eslint . --ext .js", - "start": "http-server" + "start": "http-server -S cert.pem -o" }, "dependencies": { "babel-eslint": "^8.0.3" diff --git a/rnnoise/main.js b/rnnoise/main.js index c805fe50..1d4075f4 100644 --- a/rnnoise/main.js +++ b/rnnoise/main.js @@ -7,7 +7,7 @@ const batchSize = 1; const frames = 100; // Frames is fixed at 100 const frameSize = 480; const gainsSize = 22; -const weightsUrl = '../test-data/models/rnnoise/weights/'; +const weightsUrl = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/rnnoise/weights/'; const rnnoise = new RNNoise(weightsUrl, batchSize, frames); $('#backendBtns .btn').on('change', async () => { diff --git a/semantic_segmentation/deeplabv3_mnv2_nchw.js b/semantic_segmentation/deeplabv3_mnv2_nchw.js index 70c0d5f5..3898b409 100644 --- a/semantic_segmentation/deeplabv3_mnv2_nchw.js +++ b/semantic_segmentation/deeplabv3_mnv2_nchw.js @@ -11,9 +11,9 @@ export class DeepLabV3MNV2Nchw { this.deviceType_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = '../test-data/models/deeplabv3_mnv2_nchw/weights/'; + this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/deeplabv3_mnv2_nchw/weights/'; // Shares the same bias files with 'nhwc' layout - this.biasUrl_ = '../test-data/models/deeplabv3_mnv2_nhwc/weights/'; + this.biasUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/deeplabv3_mnv2_nhwc/weights/'; this.inputOptions = { mean: [127.5, 127.5, 127.5], std: [127.5, 127.5, 127.5], diff --git a/semantic_segmentation/deeplabv3_mnv2_nhwc.js b/semantic_segmentation/deeplabv3_mnv2_nhwc.js index 07190bd0..e0241eb7 100644 --- a/semantic_segmentation/deeplabv3_mnv2_nhwc.js +++ b/semantic_segmentation/deeplabv3_mnv2_nhwc.js @@ -9,7 +9,7 @@ export class DeepLabV3MNV2Nhwc { this.deviceType_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = '../test-data/models/deeplabv3_mnv2_nhwc/weights/'; + this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/deeplabv3_mnv2_nhwc/weights/'; this.inputOptions = { mean: [127.5, 127.5, 127.5], std: [127.5, 127.5, 127.5], diff --git a/style_transfer/fast_style_transfer_net.js b/style_transfer/fast_style_transfer_net.js index 94f0e76d..6dfa763f 100644 --- a/style_transfer/fast_style_transfer_net.js +++ b/style_transfer/fast_style_transfer_net.js @@ -12,7 +12,7 @@ export class FastStyleTransferNet { this.graph_ = null; this.constPow_ = null; this.constAdd_ = null; - this.weightsUrl_ = '../test-data/models/fast_style_transfer_nchw/weights/'; + this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/fast_style_transfer_nchw/weights/'; this.inputOptions = { inputDimensions: [1, 3, 540, 540], inputLayout: 'nchw',