2
$\begingroup$

I am using data samples from a multispectral color sensor for color classification as an exercise in beginning to learn about neural networks.

I have succeeded with Classify for two data formats, {list of 10 integers} -> "color-name"} and {list of 10 integers} -> integer}.

I also succeeded with NetChain for the second, all integer, format. However, I can't seem to get NetChain set up with NetEncode properly so that the color name gets changed to an integer. Classify does this. I would like to know how it is done.

$\endgroup$
5
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign $\endgroup$
    – Dunlop
    Nov 27, 2020 at 6:50
  • 2
    $\begingroup$ Can you add some sample data to help others solve your problem? $\endgroup$
    – Dunlop
    Nov 27, 2020 at 6:51
  • $\begingroup$ Here is a sample: In[97]:= {spd2[[6000 ;; 6010, 1 ;; 2]]} Out[97]= {{{146, 734, 659, 457, 5356, 770, 537, 973, 1321, 1956} -> "Violet", {194, 418, 598, 722, 7470, 964, 1074, 2572, 3542, 2833} -> "Orange", {195, 900, 1238, 1374, 7551, 938, 1558, 1557, 1820, 1875} -> "Gray", {240, 321, 711, 1710, 9970, 1287, 2938, 3723, 4032, 2896} -> "Yellow",..., {287, 604, 639, 581, 12897, 1109, 737, 2233, 7648, 6920} -> "Red"}} $\endgroup$
    – John Davis
    Nov 27, 2020 at 15:12
  • $\begingroup$ Sorry about the formatting; I just copied and pasted from the notebook. What format should I select from the Copy As menu to make it look nice in this forum? $\endgroup$
    – John Davis
    Nov 27, 2020 at 15:17
  • 1
    $\begingroup$ Just FYI, the first eight numbers are from the visible spectrum, the ninth is a full intensity value, and the tenth is the near infrared. $\endgroup$
    – John Davis
    Nov 27, 2020 at 15:20

1 Answer 1

1
$\begingroup$
data={{146,734,659,457,5356,770,537,973,1321,1956}->"Violet",{194,418,598,722,7470,964,1074,2572,3542,2833}->"Orange",{195,900,1238,1374,7551,938,1558,1557,1820,1875}->"Gray",{240,321,711,1710,9970,1287,2938,3723,4032,2896}->"Yellow",{287,604,639,581,12897,1109,737,2233,7648,6920}->"Red"};
net = NetChain[
  {
   LinearLayer[20],
   LinearLayer[],
   SoftmaxLayer[]
   },
  "Input" -> Length@data[[1, 1]],
  "Output" -> NetDecoder[{"Class", DeleteDuplicates@data[[;; , 2]]}]
  ]

enter image description here

netT = NetTrain[net, data[[;; , 1]] -> data[[;; , 2]]]

enter image description here

netT@data[[;; , 1]]

{"Violet", "Orange", "Gray", "Yellow", "Red"}

$\endgroup$
2
  • 1
    $\begingroup$ Many thanks! It works perfectly on the full data set. I will now study your working example. I have a lot to learn, but this has put me back on track. $\endgroup$
    – John Davis
    Dec 2, 2020 at 23:09
  • $\begingroup$ @JohnDavis I was glad to help you. $\endgroup$ Dec 3, 2020 at 7:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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