Main Problem
I'm exploring the neural network in v11 and I would like to monitor the training progress in my own way instead of Mathematica's default way. So my question is, how to do this conveniently?
Example to try
So now I want to train a classifier on a set of points:
trainset = #1 -> {#2} & @@@
Flatten[Thread[
Rest[AnglePath[# Pi, Table[1./t^(2/3), {t, 1, 200}]]] ->
2 # - 1] & /@ {0, 1}, 1];
and I would like to get a result like:
Where the small points are data points and color represents classification.
It's easy to write the code implementing basic form of neural network training to accomplish this:
net = NetInitialize@
NetChain[{DotPlusLayer[20, 2], Tanh, 20, Tanh, 20, Tanh, 20, Tanh,
1, Tanh}];
net = NetTrain[net, trainset, MaxTrainingRounds -> 2500];
Show[ContourPlot[net[{x, y}][[1]], {x, -40, 40}, {y, -40, 40},
ColorFunction -> (ColorData["RedGreenSplit"][(#/2 + 1)/2] &),
ColorFunctionScaling -> False],
ListPlot[Style[#[[1]],
ColorData["RedGreenSplit"][(#[[2, 1]] + 1)/2]] & /@ trainset,
PlotStyle -> PointSize[Large]]]
However, I would like to monitor the whole learning process, so this is what I've tried: splitting the whole learning process into pieces, then use Dynamic to track them.
Dynamic[Show[
ContourPlot[net[{x, y}][[1]], {x, -40, 40}, {y, -40, 40},
ColorFunction -> (ColorData["RedGreenSplit"][(#/2 + 1)/2] &),
ColorFunctionScaling -> False],
ListPlot[Style[#[[1]],
ColorData["RedGreenSplit"][(#[[2, 1]] + 1)/2]] & /@ trainset]], TrackedSymbols :> {net}]
Do[net = NetTrain[net, trainset, MaxTrainingRounds -> 100], {30}];
This piece of code will produce a pretty good dynamic result, but there's two main problems inside it. Solving any of them will be quite helpful:
The default tracker keeps bumping out and is quite annoying. How to close the default tracker and stop it from showing up? are there any options that can do this job?
As you can see, keep re-initializing the
NetTrain
process can slow down the whole calculation a lot. So are there any way to do this job withoutNetTrain
for multiple times?(Note that it will be a much better answer if anyone solved this!)
Thanks!
"ShowTrainingProgress" -> False
as an option toNetTrain
$\endgroup$