ml5js/ml5-next-gen

Discussion: `NeuralNetwork`

Opened this issue · 0 comments

I've been working a lot on refactoring the NeuralNetwork code so I wanted to have a place to ask questions as they come up.

First up:

classifyMultiple and predictMultiple are a bit odd because they are actually identical to the classify and predict functions. They call the same classifyInternal/predictInternal function with the same _input argument.

We determine whether it's single or multiple by looking at the input. This could be potentially buggy. For example if you pass an array of inputs which has length 1 to the classifyMultiple method then you get back the same results as you would from a single classification. Not an array of results (array of arrays) with length 1. That's because we're determining whether to return a nested array by looking at the length with no knowledge of which method was used.

We have a few options here:

  1. Leave things as-is.
  2. Have one classify method which can handle single or multiple classification (This is how the TFJS model.predict() works, but I don't like this because it is confusing to explain in the docs).
  3. Ensure that classify always returns a single classification and classifyMultiple always returns an array. We would validate the inputs and log warnings or throw errors if the user provides the wrong type of input.
  4. Remove batched multiple classification entirely, and have one classify method which can only accept a single input.