How to use @tensorflow-models/mobilenet - 8 common examples

To help you get started, we’ve selected a few @tensorflow-models/mobilenet examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github googlecreativelab / teachable-machine-v1 / src / ai / WebcamClassifier.js View on Github external
async init() {
    this.useFloatTextures = !GLOBALS.browserUtils.isMobile && !GLOBALS.browserUtils.isSafari;
    tf.ENV.set('WEBGL_DOWNLOAD_FLOAT_ENABLED', false);
    this.classifier = knnClassifier.create();

    // Load mobilenet.
    this.mobilenetModule = await mobilenet.load();
  }
github microsoft / 0xDeCA10B / demo / client / src / components / model.js View on Github external
if (this.state.featureIndices !== undefined && this.state.featureIndices.length > 0) {
              return emb.gather(this.state.featureIndices).arraySync();
            }
            return emb.arraySync();
          });
          embeddings.dispose();
          return this.normalize(embedding).then(normalizedEmbedding => {
            return normalizedEmbedding.map(v => this.web3.utils.toHex(v));
          });
        };
        this.transformInput = this.transformInput.bind(this);
      });
    } else if (this.state.contractInfo.encoder === 'MobileNetv2') {
      this.setState({ inputType: INPUT_TYPE_IMAGE });
      // https://github.com/tensorflow/tfjs-models/tree/master/mobilenet
      mobilenet.load({
        version: 2,
        alpha: 1,
      }).then(model => {
        this.transformInput = async (imgElement) => {
          if (Array.isArray(imgElement)) {
            // Assume this is from given data and this method is being called from data already in the database.
            return imgElement;
          }
          const imgEmbedding = await model.infer(imgElement, { embedding: true });
          let embedding = tf.tidy(_ => {
            const embedding = imgEmbedding.gather(0);
            if (this.state.featureIndices !== undefined && this.state.featureIndices.length > 0) {
              return embedding.gather(this.state.featureIndices).arraySync();
            }
            return embedding.arraySync();
          });
github tensorflow / tfjs / tfjs-react-native / integration_rn59 / components / mobilenet_demo.tsx View on Github external
async componentDidMount() {
    // Load mobilenet
    const model = await mobilenet.load();

    //warmup mobilenet
    await model.classify(tf.zeros([1, 224, 224, 3]));

    // Read the image into a tensor
    const imageAssetPath = Image.resolveAssetSource(this.props.image);
    const response = await fetch(imageAssetPath.uri, {}, { isBinary: true });
    const rawImageData = await response.arrayBuffer();
    const imageTensor = this.imageToTensor(rawImageData);

    // Compute a checksum for the image. Useful for debugging.
    const imageTensorSum = imageTensor.sum();
    const imageChecksum = (await imageTensorSum.data())[0];

    // Classify the image.
    const start = Date.now();
github mgechev / mk-tfjs / model.ts View on Github external
tf.loadModel('http://localhost:5000/model.json').then(model => {
  mobileNet
    .load()
    .then((mn: any) => {
      mobilenet = mobilenetInfer(mn);
      document.getElementById('playground').style.display = 'table';
      document.getElementById('loading-page').style.display = 'none';
      console.log('MobileNet created');
    })
    .then(() => {
      setInterval(() => {
        canvas.getContext('2d').drawImage(video, 0, 0);
        crop.getContext('2d').drawImage(canvas, 0, 0, ImageSize.Width, ImageSize.Height);

        crop
          .getContext('2d')
          .drawImage(
            canvas,
github amandeepmittal / mobilenet-tfjs-expo / App.js View on Github external
async componentDidMount() {
    await tf.ready()
    this.setState({
      isTfReady: true
    })
    this.model = await mobilenet.load()
    this.setState({ isModelReady: true })
    this.getPermissionAsync()
  }
github overflowjs-com / image_object_detection_tensor_api / src / api / object_detectors / ObjectDetectors.js View on Github external
async loadMobileNetModal() {
        const modal = await mobilenet.load({
            version: 1,
            alpha: 0.25 | .50 | .75 | 1.0,
        })
        return modal;
    }
github charliegerard / teachable-keyboard / main.js View on Github external
async bindPage() {
    this.knn = knnClassifier.create();
    this.mobilenet = await mobilenetModule.load();

    this.start();
  }
github microsoft / 0xDeCA10B / demo / client / src / ml-models / hot_dog-not / train-classifier.js View on Github external
async function main() {
    global.encoder = await mobilenet.load(
        {
            version: 2,
            alpha: 1,
        }
    );

    let model;
    switch (CLASSIFIER_TYPE) {
        case 'ncc':
            model = await getNearestCentroidModel();
            break;
        case 'perceptron':
            model = await getPerceptronModel();
            break;
        default:
            throw new Error(`Unrecognized classifierType: "${CLASSIFIER_TYPE}"`);

@tensorflow-models/mobilenet

Pretrained MobileNet in TensorFlow.js

Apache-2.0
Latest version published 9 months ago

Package Health Score

80 / 100
Full package analysis

Popular @tensorflow-models/mobilenet functions

Similar packages