# [WSC17] Creating A Regular Polyhedron Classifier

Posted 1 year ago
1400 Views
|
|
7 Total Likes
|

# Introduction

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_] :=
ImageCrop[
ImageResize[
Image[With[{graphics = PolyhedronData[name, "Graphics3D"],
rotation = RandomReal[{-Pi, Pi}, 3]},
Graphics3D[
GraphicsComplex[rotate[rotation, #] & /@ graphics[[1, 1]],
graphics[[1, 2]]], Boxed -> False]
]], 75], {75, 75}];
randomPoly[] :=
randomPoly@
RandomChoice@{"Cube", "Dodecahedron", "Icosahedron", "Octahedron",
"Tetrahedron"};


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

createExample[name_] := randomPoly[name] -> name;
trainingData =
Table[createExample@
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.

## Training the Neural Network

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

## 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>" <>
ExportString[
Grid[{Keys[
Normal[Import["net.wlnet"][#image, "Probabilities"]]],
Values[Normal[
Import["net.wlnet"][#image, "Probabilities"]]]}],
"HTMLFragment"] &,
AppearanceRules -> <|"Title" -> "<b>Polyhedron</b> Classifier",
"Description" ->
"<style>.wolfram-branding>.wolfram-branding-cloud:after{\
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:

https://www.wolframcloud.com/objects/user-6de45e75-4ef4-4882-960c-ddb2c07bd5b5/test

## Conclusion

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.

Attachments: