The SlimMPSCnnFullyConnected is a wrapper class around MPSCnnFullyConnected used to encapsulate: - making an MPSCnnConvolutionDescriptor, - adding network parameters (weights and bias binaries by memory mapping the binaries) - getting our fullyConnected layer
Inheritance: MPSCnnFullyConnected
Ejemplo n.º 1
0
        public MnistFullLayerNeuralNetwork(IMTLCommandQueue commandQueueIn)
        {
            // CommandQueue to be kept around
            commandQueue = commandQueueIn;
            device       = commandQueueIn.Device;

            // Initialize MPSImage from descriptors
            SrcImage = new MPSImage(device, SID);
            dstImage = new MPSImage(device, DID);

            // setup convolution layer (which is a fully-connected layer)
            // cliprect, offset is automatically set
            layer = SlimMPSCnnFullyConnected.Create(kernelWidth: 28, kernelHeight: 28,
                                                    inputFeatureChannels: 1, outputFeatureChannels: 10,
                                                    neuronFilter: null, device: device,
                                                    kernelParamsBinaryName: "NN");

            // prepare softmax layer to be applied at the end to get a clear label
            softmax = new MPSCnnSoftMax(device);
        }
Ejemplo n.º 2
0
        public MnistDeepConvNeuralNetwork(IMTLCommandQueue commandQueueIn)
            : base(commandQueueIn)
        {
            // use device for a little while to initialize
            var device = commandQueueIn.Device;

            pool = new MPSCnnPoolingMax(device, 2, 2, 2, 2)
            {
                Offset = new MPSOffset {
                    X = 1, Y = 1, Z = 0
                },
                EdgeMode = MPSImageEdgeMode.Clamp
            };
            relu = new MPSCnnNeuronReLU(device, 0);

            // Initialize MPSImage from descriptors
            c1Image  = new MPSImage(device, c1id);
            p1Image  = new MPSImage(device, p1id);
            c2Image  = new MPSImage(device, c2id);
            p2Image  = new MPSImage(device, p2id);
            fc1Image = new MPSImage(device, fc1id);

            // setup convolution layers
            conv1 = SlimMPSCnnConvolution.Create(kernelWidth: 5,
                                                 kernelHeight: 5,
                                                 inputFeatureChannels: 1,
                                                 outputFeatureChannels: 32,
                                                 neuronFilter: relu,
                                                 device: device,
                                                 kernelParamsBinaryName: "conv1",
                                                 padding: true,
                                                 strideX: 1,
                                                 strideY: 1,
                                                 destinationFeatureChannelOffset: 0,
                                                 groupNum: 1);

            conv2 = SlimMPSCnnConvolution.Create(kernelWidth: 5,
                                                 kernelHeight: 5,
                                                 inputFeatureChannels: 32,
                                                 outputFeatureChannels: 64,
                                                 neuronFilter: relu,
                                                 device: device,
                                                 kernelParamsBinaryName: "conv2",
                                                 padding: true,
                                                 strideX: 1,
                                                 strideY: 1,
                                                 destinationFeatureChannelOffset: 0,
                                                 groupNum: 1);

            // same as a 1x1 convolution filter to produce 1x1x10 from 1x1x1024
            fc1 = SlimMPSCnnFullyConnected.Create(kernelWidth: 7,
                                                  kernelHeight: 7,
                                                  inputFeatureChannels: 64,
                                                  outputFeatureChannels: 1024,
                                                  neuronFilter: null,
                                                  device: device,
                                                  kernelParamsBinaryName: "fc1",
                                                  destinationFeatureChannelOffset: 0);

            fc2 = SlimMPSCnnFullyConnected.Create(kernelWidth: 1,
                                                  kernelHeight: 1,
                                                  inputFeatureChannels: 1024,
                                                  outputFeatureChannels: 10,
                                                  neuronFilter: null,
                                                  device: device,
                                                  kernelParamsBinaryName: "fc2");
        }