public static Model ConvolutionalNeuralNetworkModel() { var images = Variable <float>(); var labels = Variable <float>(); ILayer <float> net = new Reshape <float>(images, PartialShape.Create(-1, 1, 28, 28)); net = new Convolution2D <float>(net.Output, 5, 5, 16); net = new ActivationReLU <float>(net.Output); net = new Pooling2D <float>(net.Output, PoolingMode.MAX, 2, 2, 2, 2); net = new Convolution2D <float>(net.Output, 5, 5, 32); net = new ActivationTanh <float>(net.Output); net = new Pooling2D <float>(net.Output, PoolingMode.MAX, 2, 2, 2, 2); net = new Reshape <float>(net.Output, PartialShape.Create(-1, net.Output.Shape.Skip(1).Aggregate(ScalarOps.Mul))); net = new FullyConnected <float>(net.Output, 50); net = new ActivationTanh <float>(net.Output); net = new FullyConnected <float>(net.Output, 10); return(new Model { Loss = new SoftmaxCrossEntropy <float>(net.Output, labels), Images = images, Labels = labels }); }
public IActivationFunction GetActivationFunction() { IActivationFunction activation; switch (ActivationFunction) { case ActivationFunctionType.Linear: activation = new ActivationLinear(); break; case ActivationFunctionType.Sigmoid: activation = new ActivationSigmoid(); break; case ActivationFunctionType.TanH: activation = new ActivationTANH(); break; case ActivationFunctionType.SoftMax: activation = new ActivationSoftMax(); break; case ActivationFunctionType.ReLU: activation = new ActivationReLU(); break; default: throw new ArgumentOutOfRangeException(); } return(activation); }
public static Model MultiLayerPerceptronModel() { var images = Variable <float>(PartialShape.Create(-1, 28 * 28)); ILayer <float> net = new FullyConnected <float>(images, 128); net = new ActivationReLU <float>(net.Output); net = new FullyConnected <float>(net.Output, 64); net = new ActivationReLU <float>(net.Output); net = new FullyConnected <float>(net.Output, 10); var labels = Variable <float>(PartialShape.Create(-1, 10)); return(new Model { Loss = new SoftmaxCrossEntropy <float>(net.Output, labels), Images = images, Labels = labels }); }