Skip to content

Commit

Permalink
Update CDN path with hostname check (#197)
Browse files Browse the repository at this point in the history
* Update README to add HTTPS support and change the weights file to CDN service

* Update CDN path with hostname check
  • Loading branch information
ibelem authored Mar 14, 2024
1 parent 1592198 commit dbfab8f
Show file tree
Hide file tree
Showing 22 changed files with 96 additions and 24 deletions.
5 changes: 4 additions & 1 deletion face_recognition/facenet_nchw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
5 changes: 4 additions & 1 deletion face_recognition/facenet_nhwc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
5 changes: 4 additions & 1 deletion facial_landmark_detection/face_landmark_nchw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
5 changes: 4 additions & 1 deletion facial_landmark_detection/face_landmark_nhwc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
5 changes: 4 additions & 1 deletion facial_landmark_detection/ssd_mobilenetv2_face_nchw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
5 changes: 4 additions & 1 deletion facial_landmark_detection/ssd_mobilenetv2_face_nhwc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
5 changes: 4 additions & 1 deletion image_classification/mobilenet_nchw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
5 changes: 4 additions & 1 deletion image_classification/mobilenet_nhwc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
5 changes: 4 additions & 1 deletion image_classification/resnet50v2_nchw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
5 changes: 4 additions & 1 deletion image_classification/resnet50v2_nhwc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
5 changes: 4 additions & 1 deletion image_classification/squeezenet_nchw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
5 changes: 4 additions & 1 deletion image_classification/squeezenet_nhwc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
5 changes: 4 additions & 1 deletion lenet/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion nsnet2/denoiser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 8 additions & 2 deletions object_detection/ssd_mobilenetv1_nchw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
5 changes: 4 additions & 1 deletion object_detection/ssd_mobilenetv1_nhwc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
5 changes: 4 additions & 1 deletion object_detection/tiny_yolov2_nchw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
5 changes: 4 additions & 1 deletion object_detection/tiny_yolov2_nhwc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
5 changes: 4 additions & 1 deletion rnnoise/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
10 changes: 8 additions & 2 deletions semantic_segmentation/deeplabv3_mnv2_nchw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
5 changes: 4 additions & 1 deletion semantic_segmentation/deeplabv3_mnv2_nhwc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
5 changes: 4 additions & 1 deletion style_transfer/fast_style_transfer_net.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit dbfab8f

Please sign in to comment.