Getting Started (v0.11.4)

To get started with Engine, first ensure you have the Engine daemon process running. If you do not have access to the daemon or client libraries, contact us.

This guide will cover how to use our JavaScript client library in a Node.js environment to perform the following tasks:

  1. Initialize client and ping for status
  2. Send a classification request
  3. Search for image results

Step 1. Initialize client and ping for status

To begin, create an instance of the client, passing it the host and port that the daemon has been configured to run on.

// client.js

import Engine from '@image-intelligence/ava-engine-sdk';

const config = {
  ENGINE_HOST: 'daemon',
  ENGINE_PORT: 50051,
};

const client = new Engine.Client(config.ENGINE_HOST, config.ENGINE_PORT);

export default client;

To check whether the Engine is currently running, simply call client.status() on the instance.

import client from './client.js';

client.status()
  .then(({ uptime, features }) => {
    console.log(`Engine has been running for ${uptime}`);
    console.log(`Classification is enabled: ${features.classification.isEnabled}`);
  });

This will return metrics about the Engine such as uptime and the features currently enabled.

{
  "uptime": 1589,
  "features": {
    "classification": {
      "classes": [
        "person",
        "car"
      ],
      "isEnabled": true
    },
    "detection": {
      "classes": [
        "person",
        "car"
      ],
      "isEnabled": true
    },
    "faceRecognition": {
      "isEnabled": true
    }
  }
}

Step 2. Send a classification request

To send a classification request, call client.classification.detect() including a list of images, as well as the classes you wish to use for detection.

import Engine from '@image-intelligence/ava-engine-sdk';
import fs from 'fs';

import client from './client.js';

const images = [
  {
    data: fs.readFileSync(`./example.jpg`).buffer,
    feedId: 'myFeed',
    customId: `id_${Math.round(Math.random() * 10000)}`,
  },
];

const classes = ['person'];

const shouldSave = Engine.Persistence.SAVE_NOTHING;

client.classification.detect(images, classes, shouldSave)
  .then(({ results }) => {
    console.log('Classification results', JSON.stringify(results));
  });

The Engine will respond with the classification results for each image.

{
  "results": [
    {
      "imageId": "08fdde750f6cd053cee285be3830f9b0bd4c8c0e",
      "feedId": "myFeed",
      "customId": "id_3760",
      "results": [
        {
          "class": "person",
          "confidence": 0.8187038898468018
        }
      ]
    }
  ]
}

Step 3. Search for image results

If you wish to retrieve image results, you can perform a search request using client.images.search(). In the request, you may specify criteria in which to filter the search results such feed ID or confidence.

import client from './client.js';

const query = {
  feedIds: ['myFeed'],
  query: {
    $classification: {
      person: {
        $confidence: {
          $gt: 0.8,
        },
      },
    },
  },
  isSummary: true,
};

client.images.search(query)
  .then(({ images }) => {
    console.log('Search results', JSON.stringify(images));
  });

The response will include any images which meet the search criteria.

{
  "images": [
    {
      "id": "08fdde750f6cd053cee285be3830f9b0bd4c8c0e",
      "feedId": "myFeed",
      "customId": "id_3760",
      "createdAt": 1536031961008,
      "data": "",
      "classification": [
        {
          "class": "person",
          "confidence": 0.8187038898468018
        }
      ],
      "detection": [],
      "faceRecognition": []
    }
  ]
}