ConvNetSharp-使用Dropout

时间:2018-09-15 07:52:30

标签: c# neural-network deep-learning conv-neural-network convnetsharp

我想尝试在模型中添加一个辍学层,但是在 Train 方法上出现此错误:

卷的形状应为[1],才能转换为System.Double

我做错了什么?我还想知道如何在不参加培训时“禁用”辍学层(测试)。

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

1 个答案:

答案 0 :(得分:0)

  

体积应具有形状[1]才能转换为System.Double

此错误是由于ConvNetSharp中最近引入的错误引起的。它已在PR #133

中修复
  

我还想知道当我不在训练中时如何“禁用”辍学层

退出层知道何时训练或评估模型。必要时它将删除并缩放输入。