简体   繁体   English

卷积神经网络训练返回不合逻辑的价值观

[英]Convolutional Neural Network training returns illogical values

I am using https://github.com/cbovar/ConvNetSharp to use convolutional neural networks in my application. 我正在使用https://github.com/cbovar/ConvNetSharp在我的应用程序中使用卷积神经网络。

Unfortunately the libary is not well documented at all. 不幸的是,图书馆根本没有完整的文件记录。 But anyway I have a question about the training process: 但无论如何,我对培训过程有疑问:

I declared a dictionary of types string and List of Bitmaps. 我声明了一个字典类型字符串和列表的位图。

I then added some letters ( exempli gratia a, b, c et cetera) with its corresponding names to the dictionary. 然后我在字典中添加了一些字母(例如a,b,c等等)及其相应的名称。

After this, I create the neural network as follows: 在此之后,我创建神经网络如下:

            Network.AddLayer(new InputLayer(Width, Height, 1));

        Network.AddLayer(new ConvLayer(5, 5, NumberFilters) { Stride = 1, Pad = 2 });
        Network.AddLayer(new ReluLayer());

        Network.AddLayer(new PoolLayer(2, 2) { Stride = 2 });

        Network.AddLayer(new ConvLayer(5, 5, NumberFilters * 2) { Stride = 1, Pad = 2 });
        Network.AddLayer(new ReluLayer());

        Network.AddLayer(new PoolLayer(3, 3) { Stride = 3 });

        Network.AddLayer(new FullyConnLayer(TrainingSet.Count));
        Network.AddLayer(new SoftmaxLayer(TrainingSet.Count));

If I now start the training process by this method: 如果我现在通过这种方法开始训练过程:

        public void StartTraining()
    {
        _initializeLayers();
        _locked = true;
        int _increment = 0;

        Console.WriteLine("Training...");

        foreach (var data in TrainingSet)
        {     
            for (int i = 0; i < data.Value.Count; i++)
            {
                var map = MapBmpToDouble(data.Value[i]);
                var input = new Volume(map, new Shape(map.Length));
                var output = Network.Forward(input, true);
                for (int j = 0; j < Iterations; j++)
                {
                    var trainer = new SgdTrainer(Network) { LearningRate = Epsilon, L2Decay = Decay, Momentum = 0.9, BatchSize = TrainingSet.Count };
                    trainer.Train(input, new Volume(GetTrainingValues(_increment), new Shape(TrainingSet.Count)));
                }
            }
            _increment++;
        }



        Console.WriteLine("Done.");
    }

and test the result for example the letter a, I got values that are very illogical. 并测试结果例如字母a,我得到了非常不合逻辑的值。

The probabilty of the last item/class of the network is ALWAYS the highest one. 网络的最后一个项目/类别的概率总是最高的。 For the training part I just use the method 对于训练部分,我只使用该方法

    public double[] GetTrainingValues(int index)
    {
        double[] values = new double[TrainingSet.Count];
        values[index] = 1.0;
        return values;
    }

to define which class-position has to be the highest for image X with corresponding label Y. 定义哪个类位置必须是具有相应标签Y的图像X的最高位置。

Also if I use the same image for every label I get the same result! 此外,如果我为每个标签使用相同的图像,我得到相同的结果! Why? 为什么?

Do You know how to train best, or can You recommend me a better library? 你知道如何训练最好的,或者你能推荐我一个更好的图书馆吗?

Thank you very much ! 非常感谢你 !

You should instantiate the trainer only once, outside the training loop. 您应该在训练循环之外仅对训练器进行一次实例化。

var trainer = new SgdTrainer(Network) { 
                            LearningRate = Epsilon, 
                            L2Decay = Decay, 
                            Momentum = 0.9, 
                            BatchSize = TrainingSet.Count };

for (int j = 0; j < Iterations; j++)
{
    trainer.Train(input, 
                  new Volume(GetTrainingValues(_increment), 
                  new Shape(TrainingSet.Count)));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM