TransWikia.com

Error Training FeedForward Neural Network With Various Type of Variables

Mathematica Asked by user34018 on January 27, 2021

I built the following FeedForward NN

net = NetGraph[{CatenateLayer[], 200, DropoutLayer[], Ramp, 100,  
DropoutLayer[], Ramp , 100, BatchNormalizationLayer[] , 
LogisticSigmoid, 50, DropoutLayer[],  Ramp,  2,  
SoftmaxLayer[]}, {NetPort["Input"] -> 
1, {NetPort["Ethnicity"], NetPort["Gender"], NetPort["Physical"], 
 NetPort["Mental"]} -> 
 1 -> 2 -> 
  3 -> 4 -> 
    5 -> 6 -> 
      7 -> 8 -> 
        9 -> 10 -> 
          11 -> 12 -> 13 -> 14 -> 15 -> NetPort["Output"]
 },
 "Gender" -> NetEncoder[{"Class", gender, "UnitVector"}],
 "Physical" -> NetEncoder[{"Class", {"0", "1"}, "UnitVector"}],
 "Mental" -> NetEncoder[{"Class", {"0", "1"}, "UnitVector"}],
 "Ethnicity" -> NetEncoder[{"Class", ethnicity, "UnitVector"}],
 "Input" -> 4,
"Output" -> NetDecoder[{"Class", {"non", "yes"}}]]

enter image description here

MY data are as follows:

 {<|"Ethnicity" -> "Caucasian", "Gender" -> "Female", 
   "Physical" -> "0", "Mental" -> "1", 
   "Input" -> {-4.2168, 0.285714, -0.364365, -1.41703}, 
   "Output" -> "yes"|>, 
  <|"Ethnicity" -> "Black", "Gender" -> "Female",
   "Physical" -> "1", "Mental" -> "0", 
   "Input" -> {-0.44976, 0.142857, 0.204846, 0.16707}, 
   "Output" -> "yes"|>}

I initialize the model, I tried my data:

  netDrop = NetInitialize[net]
  netDrop[tDate2[[100, 1 ;; 5]]]

  Out[180]= "yes"

But when I try to train it, I get the following error:
trainTmp = NetTrain[netDrop, tDate2]

NetTrain::encgenfail2: Could not encode one or more inputs for port “Ethnicity”: supplied data was a 10*7 matrix of real numbers, but expected a class. The invalid inputs had indices {1,8,3,6,7,2,9,4,5,10}.

But ethnicity is set with:

   DeleteDuplicates[tDate2[[All, "Ethnicity"]]]

and returns:

   {"Caucasian", "Black", "Hispanic", "Asian", "Native American", 
  "Other", "South East Asian"} 

I’m at loss. I’ve no idea what to do. I’m sure it is something extremely simple.

Any help will be most appreciated.

One Answer

I found the answer in another link:

 NeuralNetworks`Private`ReinitializeNeuralNetworks[]; 
 DeleteDirectory[#, DeleteContents -> True] & /@ 
 FileNames[
 FileNameJoin@{"*", #} & /@ {"NeuralNetworks*", "MXNetLink*"}, 
 FileNameJoin@{$CacheBaseDirectory, 
   "PacletCachedData"}];

(Then Quit and try again.This will delete internal definitions for the neural net framework that we cache locally to speed up loading times.Maybe those local files got corrupted. [Dash]Matteo Salvarezza)

Answered by user34018 on January 27, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP