From dbfab8f02b39046d566f8d7cf395827e09d97b79 Mon Sep 17 00:00:00 2001 From: Belem Zhang Date: Thu, 14 Mar 2024 14:48:23 +0800 Subject: [PATCH] Update CDN path with hostname check (#197) * Update README to add HTTPS support and change the weights file to CDN service * Update CDN path with hostname check --- face_recognition/facenet_nchw.js | 5 ++++- face_recognition/facenet_nhwc.js | 5 ++++- facial_landmark_detection/face_landmark_nchw.js | 5 ++++- facial_landmark_detection/face_landmark_nhwc.js | 5 ++++- facial_landmark_detection/ssd_mobilenetv2_face_nchw.js | 5 ++++- facial_landmark_detection/ssd_mobilenetv2_face_nhwc.js | 5 ++++- image_classification/mobilenet_nchw.js | 5 ++++- image_classification/mobilenet_nhwc.js | 5 ++++- image_classification/resnet50v2_nchw.js | 5 ++++- image_classification/resnet50v2_nhwc.js | 5 ++++- image_classification/squeezenet_nchw.js | 5 ++++- image_classification/squeezenet_nhwc.js | 5 ++++- lenet/main.js | 5 ++++- nsnet2/denoiser.js | 5 ++++- object_detection/ssd_mobilenetv1_nchw.js | 10 ++++++++-- object_detection/ssd_mobilenetv1_nhwc.js | 5 ++++- object_detection/tiny_yolov2_nchw.js | 5 ++++- object_detection/tiny_yolov2_nhwc.js | 5 ++++- rnnoise/main.js | 5 ++++- semantic_segmentation/deeplabv3_mnv2_nchw.js | 10 ++++++++-- semantic_segmentation/deeplabv3_mnv2_nhwc.js | 5 ++++- style_transfer/fast_style_transfer_net.js | 5 ++++- 22 files changed, 96 insertions(+), 24 deletions(-) diff --git a/face_recognition/facenet_nchw.js b/face_recognition/facenet_nchw.js index a9946432..726648d5 100644 --- a/face_recognition/facenet_nchw.js +++ b/face_recognition/facenet_nchw.js @@ -12,7 +12,10 @@ export class FaceNetNchw { this.context_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/facenet_nchw/weights'; + this.weightsUrl_ = '../test-data/models/facenet_nchw/weights'; + if (location.hostname.toLowerCase().indexOf('github.io') > -1) { + 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 0ca056f2..8e420f15 100644 --- a/face_recognition/facenet_nhwc.js +++ b/face_recognition/facenet_nhwc.js @@ -12,7 +12,10 @@ export class FaceNetNhwc { this.context_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/facenet_nhwc/weights'; + this.weightsUrl_ = '../test-data/models/facenet_nhwc/weights'; + if (location.hostname.toLowerCase().indexOf('github.io') > -1) { + 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 8f3415a4..5c71acd7 100644 --- a/facial_landmark_detection/face_landmark_nchw.js +++ b/facial_landmark_detection/face_landmark_nchw.js @@ -8,7 +8,10 @@ export class FaceLandmarkNchw { this.context_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/face_landmark_nchw/weights'; + this.weightsUrl_ = '../test-data/models/face_landmark_nchw/weights'; + if (location.hostname.toLowerCase().indexOf('github.io') > -1) { + 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 630c68bc..2b076b61 100644 --- a/facial_landmark_detection/face_landmark_nhwc.js +++ b/facial_landmark_detection/face_landmark_nhwc.js @@ -8,7 +8,10 @@ export class FaceLandmarkNhwc { this.context_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/face_landmark_nhwc/weights'; + this.weightsUrl_ = '../test-data/models/face_landmark_nhwc/weights'; + if (location.hostname.toLowerCase().indexOf('github.io') > -1) { + 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 c8f59573..ed59a43d 100644 --- a/facial_landmark_detection/ssd_mobilenetv2_face_nchw.js +++ b/facial_landmark_detection/ssd_mobilenetv2_face_nchw.js @@ -9,7 +9,10 @@ export class SsdMobilenetV2FaceNchw { this.deviceType_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/ssd_mobilenetv2_face_nchw/weights/'; + this.weightsUrl_ = '../test-data/models/ssd_mobilenetv2_face_nchw/weights/'; + if (location.hostname.toLowerCase().indexOf('github.io') > -1) { + 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 a69528cc..e3f4c990 100644 --- a/facial_landmark_detection/ssd_mobilenetv2_face_nhwc.js +++ b/facial_landmark_detection/ssd_mobilenetv2_face_nhwc.js @@ -9,7 +9,10 @@ export class SsdMobilenetV2FaceNhwc { this.deviceType_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/ssd_mobilenetv2_face_nhwc/weights/'; + this.weightsUrl_ = '../test-data/models/ssd_mobilenetv2_face_nhwc/weights/'; + if (location.hostname.toLowerCase().indexOf('github.io') > -1) { + 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 999c9467..0194c195 100644 --- a/image_classification/mobilenet_nchw.js +++ b/image_classification/mobilenet_nchw.js @@ -9,7 +9,10 @@ export class MobileNetV2Nchw { this.deviceType_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/mobilenetv2_nchw/weights/'; + this.weightsUrl_ = '../test-data/models/mobilenetv2_nchw/weights/'; + if (location.hostname.toLowerCase().indexOf('github.io') > -1) { + 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 bca7e86e..55344c1a 100644 --- a/image_classification/mobilenet_nhwc.js +++ b/image_classification/mobilenet_nhwc.js @@ -11,7 +11,10 @@ export class MobileNetV2Nhwc { this.deviceType_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/mobilenetv2_nhwc/weights/'; + this.weightsUrl_ = '../test-data/models/mobilenetv2_nhwc/weights/'; + if (location.hostname.toLowerCase().indexOf('github.io') > -1) { + 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 28d3e64a..64573be9 100644 --- a/image_classification/resnet50v2_nchw.js +++ b/image_classification/resnet50v2_nchw.js @@ -8,7 +8,10 @@ export class ResNet50V2Nchw { this.context_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/resnet50v2_nchw/weights/'; + this.weightsUrl_ = '../test-data/models/resnet50v2_nchw/weights/'; + if (location.hostname.toLowerCase().indexOf('github.io') > -1) { + 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 a6630283..2072981b 100644 --- a/image_classification/resnet50v2_nhwc.js +++ b/image_classification/resnet50v2_nhwc.js @@ -12,7 +12,10 @@ export class ResNet50V2Nhwc { this.context_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/resnet50v2_nhwc/weights/'; + this.weightsUrl_ = '../test-data/models/resnet50v2_nhwc/weights/'; + if (location.hostname.toLowerCase().indexOf('github.io') > -1) { + 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 2274efd8..4a7c0545 100644 --- a/image_classification/squeezenet_nchw.js +++ b/image_classification/squeezenet_nchw.js @@ -8,7 +8,10 @@ export class SqueezeNetNchw { this.context_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/squeezenet1.1_nchw/weights/'; + this.weightsUrl_ = '../test-data/models/squeezenet1.1_nchw/weights/'; + if (location.hostname.toLowerCase().indexOf('github.io') > -1) { + 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 857f74d5..4f748ad1 100644 --- a/image_classification/squeezenet_nhwc.js +++ b/image_classification/squeezenet_nhwc.js @@ -8,7 +8,10 @@ export class SqueezeNetNhwc { this.context_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/squeezenet1.0_nhwc/weights/'; + this.weightsUrl_ = '../test-data/models/squeezenet1.0_nhwc/weights/'; + if (location.hostname.toLowerCase().indexOf('github.io') > -1) { + 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 7b27a130..c020ef17 100644 --- a/lenet/main.js +++ b/lenet/main.js @@ -64,7 +64,10 @@ async function main() { await utils.setBackend(backend, deviceType); drawNextDigitFromMnist(); const pen = new Pen(visualCanvas); - const weightUrl = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/lenet_nchw/weights/lenet.bin'; + let weightUrl = '../test-data/models/lenet_nchw/weights/lenet.bin'; + if (location.hostname.toLowerCase().indexOf('github.io') > -1) { + 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 c0137765..f3ffcedc 100644 --- a/nsnet2/denoiser.js +++ b/nsnet2/denoiser.js @@ -29,7 +29,10 @@ export class Denoiser { return new Promise((resolve, reject) => { this.log(' - Loading weights... '); const start = performance.now(); - const weightsUrl = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/nsnet2/weights/'; + let weightsUrl = '../test-data/models/nsnet2/weights/'; + if (location.hostname.toLowerCase().indexOf('github.io') > -1) { + 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 1af75476..35f9bd0c 100644 --- a/object_detection/ssd_mobilenetv1_nchw.js +++ b/object_detection/ssd_mobilenetv1_nchw.js @@ -10,9 +10,15 @@ export class SsdMobilenetV1Nchw { this.model_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/ssd_mobilenetv1_nchw/weights/'; + this.weightsUrl_ = '../test-data/models/ssd_mobilenetv1_nchw/weights/'; + if (location.hostname.toLowerCase().indexOf('github.io') > -1) { + this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/ssd_mobilenetv1_nchw/weights/'; + } // Shares the same bias files with 'nhwc' layout - this.biasUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/ssd_mobilenetv1_nhwc/weights/'; + this.biasUrl_ = '../test-data/models/ssd_mobilenetv1_nhwc/weights/'; + if (location.hostname.toLowerCase().indexOf('github.io') > -1) { + 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 1496a332..d872bf8f 100644 --- a/object_detection/ssd_mobilenetv1_nhwc.js +++ b/object_detection/ssd_mobilenetv1_nhwc.js @@ -10,7 +10,10 @@ export class SsdMobilenetV1Nhwc { this.model_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/ssd_mobilenetv1_nhwc/weights/'; + this.weightsUrl_ = '../test-data/models/ssd_mobilenetv1_nhwc/weights/'; + if (location.hostname.toLowerCase().indexOf('github.io') > -1) { + 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 2881eb10..ac190227 100644 --- a/object_detection/tiny_yolov2_nchw.js +++ b/object_detection/tiny_yolov2_nchw.js @@ -8,7 +8,10 @@ export class TinyYoloV2Nchw { this.context_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/tiny_yolov2_nchw/weights/'; + this.weightsUrl_ = '../test-data/models/tiny_yolov2_nchw/weights/'; + if (location.hostname.toLowerCase().indexOf('github.io') > -1) { + 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 61e2c6cc..4509d921 100644 --- a/object_detection/tiny_yolov2_nhwc.js +++ b/object_detection/tiny_yolov2_nhwc.js @@ -8,7 +8,10 @@ export class TinyYoloV2Nhwc { this.context_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/tiny_yolov2_nhwc/weights/'; + this.weightsUrl_ = '../test-data/models/tiny_yolov2_nhwc/weights/'; + if (location.hostname.toLowerCase().indexOf('github.io') > -1) { + 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/rnnoise/main.js b/rnnoise/main.js index 1d4075f4..e04cd458 100644 --- a/rnnoise/main.js +++ b/rnnoise/main.js @@ -7,7 +7,10 @@ const batchSize = 1; const frames = 100; // Frames is fixed at 100 const frameSize = 480; const gainsSize = 22; -const weightsUrl = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/rnnoise/weights/'; +let weightsUrl = '../test-data/models/rnnoise/weights/'; +if (location.hostname.toLowerCase().indexOf('github.io') > -1) { + 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 3898b409..4053c803 100644 --- a/semantic_segmentation/deeplabv3_mnv2_nchw.js +++ b/semantic_segmentation/deeplabv3_mnv2_nchw.js @@ -11,9 +11,15 @@ export class DeepLabV3MNV2Nchw { this.deviceType_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/deeplabv3_mnv2_nchw/weights/'; + this.weightsUrl_ = '../test-data/models/deeplabv3_mnv2_nchw/weights/'; + if (location.hostname.toLowerCase().indexOf('github.io') > -1) { + this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/deeplabv3_mnv2_nchw/weights/'; + } // Shares the same bias files with 'nhwc' layout - this.biasUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/deeplabv3_mnv2_nhwc/weights/'; + this.biasUrl_ = '../test-data/models/deeplabv3_mnv2_nhwc/weights/'; + if (location.hostname.toLowerCase().indexOf('github.io') > -1) { + 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 e0241eb7..ee7f6c3d 100644 --- a/semantic_segmentation/deeplabv3_mnv2_nhwc.js +++ b/semantic_segmentation/deeplabv3_mnv2_nhwc.js @@ -9,7 +9,10 @@ export class DeepLabV3MNV2Nhwc { this.deviceType_ = null; this.builder_ = null; this.graph_ = null; - this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/deeplabv3_mnv2_nhwc/weights/'; + this.weightsUrl_ = '../test-data/models/deeplabv3_mnv2_nhwc/weights/'; + if (location.hostname.toLowerCase().indexOf('github.io') > -1) { + 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 6dfa763f..532442f7 100644 --- a/style_transfer/fast_style_transfer_net.js +++ b/style_transfer/fast_style_transfer_net.js @@ -12,7 +12,10 @@ export class FastStyleTransferNet { this.graph_ = null; this.constPow_ = null; this.constAdd_ = null; - this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/fast_style_transfer_nchw/weights/'; + this.weightsUrl_ = '../test-data/models/fast_style_transfer_nchw/weights/'; + if (location.hostname.toLowerCase().indexOf('github.io') > -1) { + this.weightsUrl_ = 'https://d3i5xkfad89fac.cloudfront.net/test-data/models/fast_style_transfer_nchw/weights/'; + } this.inputOptions = { inputDimensions: [1, 3, 540, 540], inputLayout: 'nchw',