3
$\begingroup$

I have some training data of the form {{x, y}, bool}, e.g.

trainingdata = {{{0.655577, -0.11215}, 0}, {{0.091856, -0.784234}, 0}, {{0.988837, 0.703962}, 1},  ... etc }

Now I build a simple neural network.

layer1 = LinearLayer[3, "Input" -> 2];
layer2 = LinearLayer[4, "Input" -> 3];
layer3 = LinearLayer[1, "Input" -> 4];
chain = NetChain[{layer1, layer2, layer3}]

and then

trained = NetTrain[chain, #[[1]] -> #[[2]] & /@ trainingData]

but this results in $Failed.

On the other hand, the following works fine:

otherchain = NetChain[{2, 3, 4, 1}];
trained = NetTrain[otherchain, #[[1]] -> #[[2]] & /@ trainingData]

The difference between the objects seems to be that chain takes as input a vector of size 2 and otherchain takes as an input a tensor, which is then fed to a LinearLayer of size 2. I can't find anything in the NetTrain or NetChain documentation which addresses this difference.

I've tried building a training net for chain from scratch like is described on this page but it also fails, which I anticipate is for the same reason as above.

$\endgroup$
  • $\begingroup$ You're correct that the issue is the Input to the network. If you remove the "Input" specifiers in the layers the net works correctly... $\endgroup$ – Carl Lange Nov 4 '18 at 18:16
3
$\begingroup$

It appears you need to specify the "Output" type of the NetChain.

layer1 = LinearLayer[3, "Input" -> 2];
layer2 = LinearLayer[4, "Input" -> 3];
layer3 = LinearLayer[1, "Input" -> 4];
chain = NetChain[{layer1, layer2, layer3}, "Output" -> "Scalar"]

Appears to work correctly. Unfortunately I don't know why that is in this case.

Just a note - often, you can get away without specifying Input/Output between layers.

$\endgroup$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.