I'm trying to write my first neural network in Mathematica: a simple autoencoder. The network takes as input an array of size (2, 100) and reconstructs a vector of length 100 (see below). I'm trying to replicate the code on Wolfram's site, but am having trouble setting up the loss. I don't think I'm understanding the error message below. At In[856] it seems to me that I generate a network whose output is a vector of 100, so why is it upset at the dimension for layer loss (which I don't even specify?). Any help getting this fixed would be much appreciated.
Edit: Thanks to the great answer below I've made some progress on this, and think I'm understanding the NetGraph component a bit better. I've changed the configuration so that the mean loss layer takes my target output as an input (which I've named gyroscope).
Overall, the training data is "input", a (19, 2, 100) array, and "gyroscope" a (19, 100) array. However, when I try to train the network, using:
results = NetTrain[net, <|
"Input" -> input,
"Gyroscope" -> gyroscope
|>]
trained = results["TrainedNet"]
I'm told that I was supposed to supply the network with two inputs, but only gave it one. As far as I can tell, I'm giving it two. What am I missing?
For reference, here's my new NetGraph specification and general network specification below that.
net = NetGraph[
<|
"autoencoder" -> autoencoder,
"loss" -> MeanAbsoluteLossLayer[]
|>,
{
NetPort["Input"] -> "autoencoder" -> "loss",
NetPort["Gyroscope"] -> NetPort["loss", "Target"]
}
]
autoencoder =
NetChain[{FlattenLayer[], LinearLayer[64], BatchNormalizationLayer[],
ElementwiseLayer["ReLU"], 32, ElementwiseLayer["ReLU"], 16,
BatchNormalizationLayer[], ElementwiseLayer["ReLU"], 32,
BatchNormalizationLayer[], ElementwiseLayer["ReLU"], 64,
BatchNormalizationLayer[], ElementwiseLayer["ReLU"], 100},
"Input" -> {2, 100}]
```
LinearLayer[{2, 100}]
. $\endgroup$