Message Boards Message Boards

[WSC17] Creating A Regular Polyhedron Classifier


enter image description here


The aim of this project is to train a neural network to classify and identify different types of polyhedra. The neural network trained on MNIST handwriting data to identify handwritten numbers was retrained on new data to identify polyhedra. The user can upload any regular polyhedron, preferably one from Mathematica, and the classifier will identify the regular polyhedron, and display the probability of the polyhedron being one of the other regular polyhedra.

Creating the Data Set

I made the dataset by using the graph function of Mathematica. A function was created to graph the polyhedron given the name, and rotate it about all three axes randomly.

rotate[{rx_, ry_, rz_}, {x_, y_, z_}] :=
 {x Cos[ry] Cos[rz] + z Sin[ry] - 
   y Cos[ry] Sin[rz], -z Cos[ry] Sin[rx] + 
   x (Cos[rz] Sin[rx] Sin[ry] + Cos[rx] Sin[rz]) + 
   y (Cos[rx] Cos[rz] - Sin[rx] Sin[ry] Sin[rz]), 
  z Cos[rx] Cos[ry] + x (-Cos[rx] Cos[rz] Sin[ry] + Sin[rx] Sin[rz]) +
    y (Cos[rz] Sin[rx] + Cos[rx] Sin[ry] Sin[rz])}

This function defines the rotate function that rotates the graphed poylehdron.

  randomPoly[name_] :=
        Image[With[{graphics = PolyhedronData[name, "Graphics3D"], 
           rotation = RandomReal[{-Pi, Pi}, 3]},
           GraphicsComplex[rotate[rotation, #] & /@ graphics[[1, 1]], 
            graphics[[1, 2]]], Boxed -> False]
          ]], 75], {75, 75}];
randomPoly[] :=
   RandomChoice@{"Cube", "Dodecahedron", "Icosahedron", "Octahedron", 

This function graphs the poyhedra and randomly rotates it about all three axes. This is an example of the polyhedron graphed. enter image description here

createExample[name_] := randomPoly[name] -> name;
trainingData = 
    RandomChoice@{"Cube", "Dodecahedron", "Icosahedron", "Octahedron",
       "Tetrahedron"}, 1000];

This function was then used to create the rules for the training set. As shown in the code, 1000 of each polyhedron was actually generated to create the training data. This is what the rule looked like.

enter image description here

Training the Neural Network

The polyhedron classifier used the MNIST neural network and retrained the neural network using the training set generated previously.

enter image description here

Creating the Microsite

After the training of the neural network was finished, the final step was to create a microsite. The microsite allowed users to input an image of a polyhedron, and the program would identify the polyhedra.

Export["net.wlnet", trained]
CopyFile["net.wlnet", CloudObject["net.wlnet"]]
form = FormPage[{"image" -> "Image"},
   "<h2 style='margin-bottom:40px' class='section form-title'>" <> 
     ToString[Import["net.wlnet"][#image]] <> "</h2>" <> 
         Normal[Import["net.wlnet"][#image, "Probabilities"]]], 
          Import["net.wlnet"][#image, "Probabilities"]]]}], 
      "HTMLFragment"] &, 
   AppearanceRules -> <|"Title" -> "<b>Polyhedron</b> Classifier", 
     "Description" -> 
background-image: url(}</style>Upload \
a regular polyhedra to have it classified", 
     "SubmitLabel" -> "Classify"|>
   , PageTheme -> "Red"];
CloudDeploy[form, "test",
 Permissions -> "Public"

This is the link to the microsite you can see at the top:


Although the classifier is currently very accurate in correctly identifying the polyhedra generated by Wolfram and Mathematica, its success rate when using Google images or outside images is a lot lower. I hope to keep training the neural network in order to allow for higher accuracy with outside images as well.

POSTED BY: Andre Wang
1 month ago

Group Abstract Group Abstract