🧹 Cleanup Neural Network task-dependent logic #95
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Reboot of the changes in this commit: ml5js/ml5-library@f8e4b8f
from ml5js/ml5-library#1410
I branched this on top of the previous 2 PRs, expecting them to be merged first. Changes are in 51846a3
The idea is essentially that all logic which depends on which task is selected (
classification
,regression
orimageClassification
) is all declared in one place in a newgetTask
file. This makes it a lot easier to see how we are handling each situation. And easier to potentially add more task presets in the future.The rest of the notes copied from the previous PR:
Introduces a level of abstraction for the "task" of the neural network:
getTask.ts
NNTask
which specifies what information a task needs to provide:neuroEvolution
is set.name
(not currently not used, possible 🪓)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.getTask
to convert astring
task name into aNNTask
object.NeuralNetwork/index.ts
this.task
with the task object based onoptions.task
. This defaults toregression
which seems to match what was in the default layers before.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
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.