NeuralNetworkClassifier

Time to make NeuralNetworkClassifier watcher classify fruits.

Let's create an initialization function for the NNC watcher.

const initializeNNC = () => {};

Retrieve the elements we'll be working with, along with the bounding rect of the element defining the watcher's contour.

const initializeNNC = () => {
  // Get the elements we'll be working with...
  const nncElement = document.getElementsByClassName('nnc')[0];
  const nncRecognizedClassElement = document.getElementsByClassName('nnc-recognized-class')[0];

  // ...along with the bounding rect that defines the watcher size
  const nncBounds = nncElement.getBoundingClientRect();
};

Define the watcher data structure.

  // ...

  const nncFruitsWatcher = {
    name: 'NeuralNetworkClassifier',
    shape: lampix.helpers.rectangle(
      nncBounds.left,
      nncBounds.top,
      nncBounds.width,
      nncBounds.height
    ),
    params: {
      neural_network_name: 'fruits'
    }
  };

In case you're wondering, the above lampix.helpers.rectangle could be replaced with:

The watcher data structure above is almost complete, but it's missing one key component: what to actually do when classification is triggered.

All that's left now is to inform Lampix of its existence, by adding the following to the end of the initializeNNC function.

Now, initializeNNC should look like this:

Last updated

Was this helpful?