【问题标题】:How to set Validation set when training CNN on MATLAB(trainNetwork())在 MATLAB 上训练 CNN 时如何设置验证集(trainNetwork())
【发布时间】:2020-07-09 05:58:36
【问题描述】:

我正在尝试在 MATLAB 上训练 CNN。 matlab 文档说,加载数据,设置图层和选项。最后使用 trainNetwork() 进行训练。

    layers = [imageInputLayer([28 28 1])
          convolution2dLayer(5,10,...
                                'Stride',1,...
                                'Padding',[0,0])
          reluLayer
          maxPooling2dLayer(2,'Stride',2)
          fullyConnectedLayer(10)
          softmaxLayer
          classificationLayer];


 options = trainingOptions('sgdm',...Environment
                            'CheckpointPath','',...
                            'ExecutionEnvironment','gpu',...                'auto'  | 'cpu' | 'gpu' | 'multi-gpu' | 'parallel'
                            'InitialLearnRate',0.0001,...   Learning Rate
                            'LearnRateSchedule','none',...                  none    |piecewise
                            'LearnRateDropPeriod',10,...
                            'LearnRateDropFactor',0.1,...
                            'L2Regularization',0.0001,...   Regularization
                            'MaxEpochs',15,...              Epochs
                            'MiniBatchSize',128,...         Batch           128     |
                            'Momentum',0.9,...                              0.9     |
                            'Shuffle','once',...                            once    |never
                            'Verbose',1,...                                 1       | 0             — Indicator to display the information on the training progress
                            'VerboseFrequency',100,...                      50      | 0 
                            'OutputFcn',@plotTrainingAccuracy);

convnet = trainNetwork(trainDigitData,layers,options);

下面是我训练 CNN 的程序,但问题是我找不到设置验证集的选项。我设置的“纪元”数字越大,训练的时间就越长。它会在过度拟合之前停止吗?

不喜欢 nnstart 工具箱,在训练 NN 时,会显示交叉熵和验证,训练错误率。

那么,在 matlab 上训练 CNN 时,您通常使用什么?使用像 caffe 这样的 3rd 方 lib 接口?还是自己写程序?

【问题讨论】:

  • 您的问题找到解决方案了吗?
  • 还没有。我在用MATLAB官方提供的解决方案放弃考虑是否有e Validation Set
  • 还有其他培训选项,例如 ValidationData ValidationPatience 可以帮助您解决问题。

标签: matlab machine-learning neural-network deep-learning virtual-machine


【解决方案1】:

您可以将数据拆分为训练和测试数据

idx = floor(0.8 * height(data));
trainingData = data(1:idx,:);
testData = data(idx:end,:);

然后在trainNetwork之后,就可以运行测试部分了

resultsStruct = struct([]);

for i = 1:height(testData)

    % Read the image.
    I = imread(testData.imageFilename{i});
    % Run the detector.
    [bboxes, scores, labels] = detect(detector, I);

    % Collect the results.
    resultsStruct(i).Boxes = bboxes;
    resultsStruct(i).Scores = scores;
    resultsStruct(i).Labels = labels;
end

% Convert the results into a table.
results = struct2table(resultsStruct);

如果你想查看 Faster R-CNN 的实现https://www.mathworks.com/help/vision/examples/object-detection-using-faster-r-cnn-deep-learning.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-27
    • 1970-01-01
    • 2019-07-18
    • 1970-01-01
    • 1970-01-01
    • 2019-04-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多