示例#1
0
    private void CreateDNet()
    {
        ConvolutionLayer  conv0       = new ConvolutionLayer(inputDimension, filterSize: 3, filterCount: 32, zeroPadding: true);
        ActivationLayer   activation0 = new ActivationLayer(new Relu(leaky: true));
        MaxPooling2DLayer pool0       = new MaxPooling2DLayer();
        ConvolutionLayer  conv1       = new ConvolutionLayer(inputDimension, filterSize: 3, filterCount: 32, zeroPadding: true);
        ActivationLayer   activation1 = new ActivationLayer(new Relu(leaky: true));
        MaxPooling2DLayer pool1       = new MaxPooling2DLayer();
        FlattenLayer      flatten     = new FlattenLayer();
        LinearLayer       linear0     = new LinearLayer(numNeurons: 128);
        ActivationLayer   activation2 = new ActivationLayer(new Relu(leaky: true));
        LinearLayer       linear1     = new LinearLayer(numNeurons: 1);
        ActivationLayer   activation3 = new ActivationLayer(new Sigmoid());

        dNet.Add(conv0);
        dNet.Add(activation0);
        dNet.Add(pool0);
        dNet.Add(conv1);
        dNet.Add(activation1);
        dNet.Add(pool1);
        dNet.Add(flatten);
        dNet.Add(linear0);
        dNet.Add(activation2);
        dNet.Add(linear1);
        dNet.Add(activation3);
        dNet.Compile(new BinaryCrossEntropy(), new Adam(0.001d));
    }
示例#2
0
        public ReaderKerasModel(string fname)
        {
            JObject model     = JObject.Parse(File.ReadAllText(fname));
            String  modelType = (String)model.SelectToken("model_type");

            if (!modelType.Equals("Sequential"))
            {
                throw new Exception("This reader only supports Sequential type models!");
            }

            SequentialModel seq = new SequentialModel();

            List <IKernelDescriptor> descriptors = ReadDescriptors(model);

            foreach (var d in descriptors)
            {
                seq.Add(d);
            }

            seq.Compile(new DefaultExecutor());

            List <IData> weights = ReadWeights(model, descriptors);

            seq.SetWeights(weights);

            sequential = seq;
        }
示例#3
0
    private void CreateGNet()
    {
        ConvolutionLayer conv1          = new ConvolutionLayer(inputDimension, filterSize: 3, filterCount: 4, zeroPadding: true);
        ActivationLayer  act            = new ActivationLayer(new Relu(leaky: true));
        ConvolutionLayer conv           = new ConvolutionLayer(inputDimension, filterSize: 3, filterCount: 4, zeroPadding: true);
        ActivationLayer  act1           = new ActivationLayer(new Relu(leaky: true));
        ConvolutionLayer convolutionOut = new ConvolutionLayer(inputDimension, filterSize: 3, filterCount: 4, zeroPadding: true);
        ActivationLayer  actOut         = new ActivationLayer(new Relu(leaky: true));

        gNet.Add(conv1);
        gNet.Add(act);
        gNet.Add(conv);
        gNet.Add(act1);
        gNet.Add(convolutionOut);
        gNet.Compile(new BinaryCrossEntropy(), new Adam(0.001d));
    }