Example of a Mushroom Classifier

Train your own neural networks (NNs) to identify species using images

In[]:=
earthstar=
,
,
,
,
,
,
,
,
;
In[]:=
gyromitra=
,
,
,
,
,
,
,
,
,
;
In[]:=
grifolafrondosa=
,
,
,
,
,
,
,
,
,
;
In[]:=
all=Join[Thread[earthstar"earthstar"],Thread[gyromitra"gyromitra"],Thread[grifolafrondosa"grifolafrondosa"]];
In[]:=
{train,test}=TakeDrop[RandomSample[all],25];
In[]:=
net=NetModel["ResNet-50 Trained on ImageNet Competition Data"];​​netFeature=NetDrop[net,-2];​​netNew=NetChain[​​<|"feature"netFeature,"classifier"LinearLayer[],"probabilities"SoftmaxLayer[]|>,"Output"NetDecoder[{"Class",{"earthstar","gyromitra","grifolafrondosa"}}]]
Out[]=
NetChain
uniniti
aliz
ed
Input port:
image
Output port:
class
Number of layers:
3

In[]:=
trained=NetTrain[netNew,train,All,LearningRateMultipliers{"classifier"1,_0},ValidationSetScaled[0.1],​​MaxTrainingRounds10,​​Method"SGD"​​]
Out[]=
NetTrain Results
summary
batches:80,rounds:10,time:18s,examples/s:14.
data
training examples:24,validation examples:3,processed examples:240,skipped examples:0
method
SGDoptimizer,batch size3,CPU
round
loss:
3.47×
-3
10
,
error:
0%
validation
loss:
7.5×
-11
10
,
error:
0%
‹
loss
›
​
rounds
loss
training set
validation set
In[]:=
ClassifierMeasurements[trained["TrainedNet"],test,"Accuracy"]
Out[]=
1.
In[]:=
ClassifierMeasurements[trained["TrainedNet"],test,"ConfusionMatrixPlot"]
Out[]=