简体   繁体   English

ConvNetSharp-使用Dropout

[英]ConvNetSharp - using Dropout

I would like to try adding a dropout layer in my model but I get this error on Train method: 我想尝试在模型中添加一个辍学层,但在Train方法上遇到此错误:

Volume should have a Shape [1] to be converter to a System.Double 卷应具有要转换为System.Double的Shape [1]。

What did I do wrong? 我做错了什么? I would also like to know how to "disable" the dropout layer when I'm not in training (testing). 我还想知道当我不在训练 (测试)中如何“禁用”辍学层。

SgdTrainer trainer;
int numFeatures = 3;
Net<double> net = new Net<double>();
Volume<double> inputVolume, outputVolume;

trainer = new SgdTrainer(net) { LearningRate = 0.0001, BatchSize = 128 };

// 4 test cases with 3 features each    
double[] inputData = new double[12]  { 0, 1, 2,   3, 4, 5,   6, 7, 8,   6, 7, 8 };

// binary classification: 0,1 = is class; 1,0 = not class    
double[] outputData = new double[8]  { 0, 1,      1, 0,      0, 1,      1, 0 };

net.AddLayer(new InputLayer(1, 1, numFeatures));

net.AddLayer(new FullyConnLayer(10));
net.AddLayer(new ReluLayer());

net.AddLayer(new DropoutLayer(0.5)); // (ಠ_ಠ)

net.AddLayer(new FullyConnLayer(2));
net.AddLayer(new SoftmaxLayer(2));

inputVolume = BuilderInstance.Volume.From(inputData, new Shape(1, 1, numFeatures, inputData.Length / numFeatures));
outputVolume = BuilderInstance.Volume.From(outputData, new Shape(1, 1, 2, outputData.Length / 2));  

trainer.Train(inputVolume, outputVolume); // get error if there is dropout above

Volume should have a Shape [1] to be converter to a System.Double 卷应具有要转换为System.Double的Shape [1]。

This error was due to a bug recently introduced in ConvNetSharp. 此错误是由于ConvNetSharp中最近引入的错误引起的。 It was fixed in PR #133 在PR #133中已修复

I would also like to know how to "disable" the dropout layer when I'm not in training 我还想知道当我不在训练中时如何“禁用”辍学层

Dropout layer knows when you are training or evaluating the model. 辍学层知道您何时训练或评估模型。 It will drop and scale inputs when necessary. 必要时它将删除并缩放输入。

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

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