npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

deepdetect-js

v1.8.12

Published

DeepDetect JS client

Downloads

56

Readme

deepdetect-js

All Contributors

DeepDetect JS client

Files

  • src/index.js - client source code

  • src/index.test.js - client methods tests

  • doc/web-example/server.js - simple webserver to serve web-example index.html and proxy api calls to a deepdetect server

  • doc/web-example/index.html - deepdetect-js web integration demo

Usage

Web integration

DeepDetect-JS can be used on a webpage, you probably should run deepdetect server behind a http-proxy to avoid same-origin policy issues.

A simple webserver demo is available on http://localhost:3000 when running the following command:

yarn run web-example

Here is the simple /info api call on a DeepDetect server. Note the {path: 'api'} parameter when initializing DD object.

...
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/deepdetect-browser.min.js"></script>
<script>
  async function fetchInfo() {
    const dd = new deepdetect.DD({path: 'api'});
    const info = await dd.info();
    document.getElementById('infoResult').innerHTML = JSON.stringify(info);
  }

  fetchInfo();
</script>
...

NodeJS integration

Following usage examples will use nodejs, install it with this command:

npm install --save deepdetect-js

Connect to DeepDetect server, and fetch informations

Here is the simplest way to get information about a DeepDetect server:

import DD from 'deepdetect-js';

async () => {

  const dd = new DD()

  // Get DeepDetect server info
  const info = await dd.info()
  console.log(info);

}

You can also specified the DeepDetect server host and port options:

import DD from 'deepdetect-js';

async () => {

  const dd = new DD('10.10.10.1', 8580)

  // Get DeepDetect server info
  const info = await dd.info()
  console.log(info);

}

Service API

Once connected to a DeepDetect server, the Service API allows to:

  • create a service
  • fetch informations about a service
  • delete a service
import DD from 'deepdetect-js';

async () => {

  const dd = new DD()

  // Create a service
  const serviceName = 'myserv';

  const serviceConfig = {
    description: 'example classification service',
    model: {
      repository: '/home/me/models/example',
      templates: '../templates/caffe'
    },
    mllib: 'caffe',
    parameters: {
      input: { connector: 'txt' },
      mllib: { nclasses: 20 },
      output: {},
    },
  };

  const createService = await dd.putService(serviceName, serviceConfig)

  // Fetch service information
  const service = await dd.getService(serviceName);
  console.log(service);

  // Delete service
  const deleteService = await dd.deleteService(serviceName, {clear: 'full'});
}

Train API

Once connected to a DeepDetect server, the Train API allows to:

  • Create a training job
  • Get information on a non-blocking training job
  • Kills a non-blocking training job
import DD from 'deepdetect-js';

async () => {

  const dd = new DD()
  const serviceName = 'myserv';

  // Create a training job
  const train = await dd.postTrain(
    serviceName,
    [ '/home/me/deepdetect/examples/all/n20/news20' ],
    {
      test_split: 0.2,
      shuffle: true,
      min_count: 10,
      min_word_length: 3,
      count: false,
    },
    {
      gpu: false,
      solver: {
        iterations: iterationsN20,
        test_interval: 200,
        base_lr: 0.05,
        snapshot: 2000,
        test_initialization: true,
      },
      net: {
        batch_size: 100,
      },
    },
    { measure: ['acc', 'mcll', 'f1'] },
    false
  );

  // Get information on a non-blocking training job
  const trainingJob = await dd.getTrain(serviceName);
  console.log(trainingJob);

  // Kills a non-blocking training job
  const deletedTrainingJob = await dd.deleteTrain(serviceName);
  console.log(deletedTrainingJob);

}

Predict API

Once connected to a DeepDetect server, the Predict API allows to makes prediction from data and model

import DD from 'deepdetect-js';

async () => {

  const dd = new DD()
  const serviceName = 'myserv';

  // Predict with measures
  const postData = {
    service: serviceName,
    data: [ '/home/me/deepdetect/examples/all/n20/news20' ],
    parameters: {
      input: {},
      mllib: {
        gpu: false,
        net: {
          test_batch_size: 10,
        },
      },
      output: {
        measure: ['f1']
      }
    }
  };

  const predict = await dd.postPredict(postData)
  console.log(predict);

}

Build and release

  1. Modify version number in package.json
  2. npm run build
  3. npm publish - documentation

Testing

In order to run the test, you first need to run a deepdetect server loccaly on port 8080. To do so, you can use the following docker command:

docker run -d -p 8080:8080 docker.jolibrain.com/deepdetect_cpu

Then you can run the test suite:

yarn test

If you find and issue with your tests, please check the header parameters available in src/index.test.js.

Changelog

  • 1.8.12 - 21/03/2024 - return !response.ok error from http requests
  • 1.8.11 - 19/10/2023 - Add missing process lib
  • 1.8.10 - 19/10/2023 - Review dependabot alerts
  • 1.8.9 - 17/10/2023 - Update dependencies
  • 1.8.8 - 19/10/2021 - Add option to enable/disable Accept-Encoding gzip request header
  • 1.8.7 - 05/01/2020 - Replace NaN values in returned json from deepdetect server
  • 1.8.4 - 16/10/2020 - Fix conditional check of options.sameOrigin by eh-dub

Contributors

Thanks goes to these people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

License

MIT © Jolibrain