OnStart

Our OnStart method is much more complex than previous microservices, but again this is for education purposes only. As you can see, the OnStart method actually sends all the messages required to build and train the network. In production-level code you may or may not do this, but just in case, I have highlighted the sections of code that pertain to building and training the neural network:

public new bool OnStart([CanBeNull] HostControl host)
{
Host = host;
base.Start(host);
CreateNetwork();
Subscribe("MachineLearning", "", (msg) => { ProcessMLMessage(msg, null); });
Console.WriteLine(string.Intern("Machine Learning MicroService Started."));
  1. Declare the first layer as an input layer. Since we are using two-dimensional data, we do not care about the three-dimensional volume (tensor) that we maintain (width, height, depth). We will therefore set the width and height to a size of one:
PublishMessage("EvolvedAI", "", MLMessageType.AddLayer, LayerType.InputLayer, 1,1,2,"test1","test2", string.Empty);
  1. Declare a layer with 20 neurons:
PublishMessage("EvolvedAI", "", MLMessageType.AddLayer, LayerType.FullyConnLayer, 20, 0, 0, string.Empty, string.Empty, string.Empty);
  1. Declare a Rectified Linear Unit (ReLU):
PublishMessage("EvolvedAI", "", MLMessageType.AddLayer, LayerType.ReluLayer, 0, 0, 0, string.Empty, string.Empty, string.Empty);
  1. Declare a fully-connected layer that will be used by the SoftmaxLayer:
PublishMessage("EvolvedAI", "", MLMessageType.AddLayer, LayerType.FullyConnLayer, 10, 0, 0, string.Empty, string.Empty, string.Empty);
  1. Declare the linear classifier on top of the previously hidden layer:
PublishMessage("EvolvedAI", "", MLMessageType.AddLayer, LayerType.SoftmaxLayer, 10, 0, 0, string.Empty, string.Empty, string.Empty);
  1. Forward a random data point through the network:
PublishMessage("EvolvedAI", "", MLMessageType.Forward, LayerType.None, 0.3, -0.5, 2, string.Empty, string.Empty, string.Empty);
  1. Our result is a volume (tensor). They have weight properties that store the raw data, and weight gradients that store gradients:
PublishMessage("EvolvedAI", "", MLMessageType.GetResult, LayerType.None, 0.3, -0.5, 2, string.Empty, string.Empty, string.Empty);
return (true);
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset