0
$\begingroup$

I don't think I'm understanding the association form for data to neural networks. I wrote the following network which takes arrays of size (2, 100) as input, and outputs a length 100 vector. I thought this would be fairly simple to do, but I can't seem to get the data format correctly to the neural network. Any help on this would be appreciated! Below is my code for the network, and the error message I receive is "Expected two inputs, but received one". As far as I can tell, I'm sending the network two inputs, what am I missing? Thanks!

Note: the network even "trains" but loss remains 0 the entire time, and then I get the error about not providing two inputs, which makes me think the data is not even getting loaded.

(*Import the Data*)

ax = Normal[Import["~/Desktop/Workspace/axPandova.csv", "Dataset"]];
ay = Normal[Import["~/Desktop/Workspace/ayPandova.csv", "Dataset"]];
az = Normal[Import["~/Desktop/Workspace/azPandova.csv", "Dataset"]];

bx = Normal[Import["~/Desktop/Workspace/bxPandova.csv", "Dataset"]];
by = Normal[Import["~/Desktop/Workspace/byPandova.csv", "Dataset"]];
bz = Normal[ Import["~/Desktop/Workspace/bzPandova.csv", "Dataset"]];

gx = Normal[Import["~/Desktop/Workspace/gxPandova.csv", "Dataset"]];
gy = Normal[Import["~/Desktop/Workspace/gyPandova.csv", "Dataset"]];
gz = Normal[ Import["~/Desktop/Workspace/gzPandova.csv", "Dataset"]];


(*Prepare dataset*)
amag = Sqrt[{ax^2 + ay^2 + az^2}];
bmag = Sqrt[{bx^2 + by^2 + bz^2}];
gmag  = Sqrt[{gx^2 + gy^2 + gz^2}];

input = Transpose[{amag[[1]], bmag[[1]]}]; (*size {19, 2, 100}*)
gyroscope = gmag[[1]]; (*size {19, 100}*)

A = Association[];
m = Dimensions[input][[1]]; (* 19, representing 19 training examples*)
f[x_] := input[[x, All]] (* A single {2, 100} instance*)
For[i = 1, i <= m, i++, AssociateTo[A, f[i] -> gyroscope[[i]]]]
trainingassoc = <|"Input" -> Keys[A], "Target" -> Values[A]|>;

network = 
 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}]

net = NetGraph[
  <|
   "autoencoder" -> autoencoder,
   "loss" -> MeanAbsoluteLossLayer[]
   |>,
  {
   NetPort["Input"] -> "autoencoder" -> "loss"
   }
  ]

results = NetTrain[net, trainingassoc]

trained = results["TrainedNet"]



enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.