ml5-library
ml5-library copied to clipboard
🧹 NeuralNetwork cleanup pt. 3 -- tasks
Introduces a level of abstraction for the "task" of the neural network:
getTask.ts
- Define an interface
NNTask
which specifies what information a task needs to provide:- Its default layers.
- Its compile options.
- Any overrides to the NN default options.
- How to create sample data to use when option
noTraining
is set. - Its
name
(not currently not used, possible 🪓)
- Create three concrete implementations of that interface for the three tasks:
classification
,regression
, andimageClassification
.-
imageClassification
uses some of the same functions asclassification
. -
getSampleData
is only possible in a limited set of circumstances (see issue #1409), so I'm throwing a lot of specific errors when those circumstances aren't met.
-
- Export a function
getTask
to convert astring
task name into aNNTask
object.
NeuralNetwork/index.ts
- Constructor sets an instance property
this.task
with the task object based onoptions.task
. This defaults toregression
which seems to match what was in the default layers before. - Remove large blocks of code in
addDefaultLayers()
andcompile()
which was moved into the task objects. Now we call a function onthis.task
:-
const layers = this.task.createLayers(inputUnits, hiddenUnits, outputUnits);
-
const options = this.task.getCompileOptions(this.options.learningRate);
-
NeuralNetwork/NeuralNetwork.ts
- I'm like 99% sure that using
optimizer.call(this, learningRate)
to set thethisArg
on the optimizer doesn't actually make a difference? (Please correct me if I am wrong). I removedsetOptimizerFunction()
, which, despite the name, just creates an optimizer and doesn't set anything. The instantiation of the optimizer is handled in thegetCompileOptions()
function of the task, which gets thelearningRate
as an argument.