ml5js / ml5-library

Friendly machine learning for the web! 🤖
https://ml5js.org
Other
6.47k stars 900 forks source link

When specifying layers options to ml5 neural network, the network doesn't train #862

Open KokoDoko opened 4 years ago

KokoDoko commented 4 years ago

I'm trying out the example at https://github.com/ml5js/ml5-examples/blob/development/p5js/NeuralNetwork/NeuralNetwork_multiple_layers/sketch.js

But if the options object contain layers as in the example I mentioned, then model.train()returns immediately without actually training. No model is created.

let optionsHiddenLayers = {
        inputs: ["x", "y"],
        outputs: ["label"],
        task: "classification",
        debug: "true",
        learningRate: 0.1,
        layers: [
            {
                type: 'dense',
                units: 4,
                activation: 'relu',
            },
            {
                type: 'dense',
                units: 2,
                activation: 'relu',
            },
            {
                type: 'dense',
                activation: 'softmax',
            }
        ]
    }

UPDATE

The P5 version of this same example actually works, it seems that the layers options in the plain JS version is outdated. The layers options should look like this

const nn_options = {
    inputs: 1,
    outputs: 1,
    layers: [
        ml5.tf.layers.dense({
            units: 16,
            inputShape: [1],
            activation: 'relu',
        }),
        ml5.tf.layers.dense({
            units: 16,
            activation: 'sigmoid',
        }),
        ml5.tf.layers.dense({
            units: 1,
            activation: 'sigmoid',
        })
    ],
    debug: true
}
AlexandruMares commented 3 years ago

the problem still exists, and is frustrating, no solution online