I'm trying to train the following structure of neural networknet
with customized loss functionlossnet
each code and structure is below.
net = NetChain[{LinearLayer[10], BatchNormalizationLayer[],
ElementwiseLayer[Tanh], LinearLayer[10]}, "Input" -> 10,
"Output" -> 10]
lossnet = NetGraph[<|
"rest" -> SequenceRestLayer[],
"reverse" -> SequenceReverseLayer[],
"firstelement" -> SequenceLastLayer[],
"elementwise" -> ElementwiseLayer[Power[# - 1]^2 &],
"most" -> SequenceMostLayer[],
"last" -> ThreadingLayer[(#1 - #2 - 1)^2 &],
"out" -> SummationLayer[],
"summary" -> ThreadingLayer[Plus]
|>,
{
NetPort["Input"] -> "rest",
NetPort["Input"] -> "reverse",
"reverse" -> "firstelement",
"firstelement" -> "elementwise",
NetPort["Input"] -> "most",
"rest" -> "last",
"most" -> "last",
"last" -> "out",
{"out", "elementwise"} -> "summary"}]
but when start training,I encountered this error.
NetTrain[net, <|NetPort["Input"] -> {Range[1, 10]}|>,
LossFunction -> lossnet]
NetTrain::missinslot: Training data specification should include values for the port Input, but only contains values for the port NetPort[Input]. You may need to explicitly specify the loss port(s) of the net using LossFunction.
it seems that something related to my input is wrong,but I don't know where it is.
perhaps,this is a rudimentary mistake,though.
what is wrong?
NetTrain[net, <|"Input" -> {Range[1, 10]}, "Output" -> {ConstantArray[0, {10}]}|>, LossFunction -> lossnet]
works ! thank you!. would you re-post it as answer for accept ? $\endgroup$