ml5js / ml5-data-and-models-server

A repo to download and serve data and models locally allowing ml5 to run without a web connection
29 stars 13 forks source link

Directory stucture for models? #3

Open joeyklee opened 5 years ago

joeyklee commented 5 years ago

Question regarding how to best structure the directory structure for mobilenet.

Right now the mobilenet URL looks like this, for example:

// https://storage.googleapis.com/tfjs-models/tfjs/mobilenet_v1_0.25_224/model.json

https://storage.googleapis.com/tfhub-tfjs-modules/google/imagenet/mobilenet_v1_025_224/classification/1/group1-shard1of1

Should we strive to recplicate the directory structure that googleapis has done (e.g. /tfhub-tfjs-modules/.../.../? but rather replace storage.googleapis.com with localhost:<PORT> ? or just do our own thing?

snowyu commented 4 years ago

Replicate the directory and file structure: ${model}/${architecture}/${quant}/model-stride${stride}.json

like this:

bodypix/MobileNetV1/quant2/075/model-stride16.json

And write the local version of saved_models to get the url.

const config = {
  architecture: 'MobileNetV1',
  outputStride: 16,
  multiplier: 0.75,
  quantBytes: 2
}
const modelUrl = getModelUrl(config);

const net = await bodyPix.load({modelUrl});

ref: https://github.com/tensorflow/tfjs-models/blob/master/body-pix/src/saved_models.ts

const MOBILENET_BASE_URL =
    'https://storage.googleapis.com/tfjs-models/savedmodel/bodypix/mobilenet/';
// The BodyPix 2.0 MobileNetV1 models use the latest TensorFlow.js 1.0 model
// format.
export function mobileNetSavedModel(
    stride: number, multiplier: number, quantBytes: number): string {
  const toStr: {[key: number]: string} = {1.0: '100', 0.75: '075', 0.50: '050'};
  const graphJson = `model-stride${stride}.json`;
  // quantBytes=4 corresponding to the non-quantized full-precision SavedModel.
  if (quantBytes === 4) {
    return MOBILENET_BASE_URL + `float/${toStr[multiplier]}/` + graphJson;
  } else {
    return MOBILENET_BASE_URL + `quant${quantBytes}/${toStr[multiplier]}/` +
        graphJson;
  }
}