【问题标题】:matlab neural network training batch sizematlab神经网络训练批量大小
【发布时间】:2012-03-15 05:09:00
【问题描述】:

我正在尝试使用不同的批量大小来训练神经网络,但我不确定如何将生成的网络合并在一起。

这是我编写的以批量大小为参数训练网络的代码。

%% Train the Network using batches
batch_size = 50;

total_size = size(inputs,2);
batch_num = ceil(total_size / batch_size);

for i = 1:batch_num
    start_index = i + batch_size * (i - 1);
    end_index = batch_size + batch_size * (i - 1);

    if i == batch_num
        end_index = total_size;
    end

    [net,tr] = train(net,inputs(:,start_index:end_index), targets(:,start_index:end_index));
end

这是net和tr的结构

tr =

    trainFcn: 'traingdm'
  trainParam: [1x1 nnetParam]
  performFcn: 'mse'
performParam: [1x1 nnetParam]
    derivFcn: 'defaultderiv'
   divideFcn: 'dividerand'
  divideMode: 'sample'
 divideParam: [1x1 nnetParam]
    trainInd: [1x538 double]
      valInd: [1x115 double]
        ...

净 =

Neural Network

          name: 'Pattern Recognition Neural Network'
    efficiency: .cacheDelayedInputs, .flattenTime,
                .memoryReduction
      userdata: (your custom info)

dimensions:

     numInputs: 1
     numLayers: 4
    numOutputs: 1
numInputDelays: 0
numLayerDelays: 0
 numFeedbackDelays: 0
 numWeightElements: 845
    sampleTime: 1

connections:

   biasConnect: [1; 1; 1; 1]
  inputConnect: [1; 0; 0; 0]
  layerConnect: [4x4 boolean]
 outputConnect: [0 0 0 1]

subobjects:

        inputs: {1x1 cell array of 1 input}
        layers: {4x1 cell array of 4 layers}
       outputs: {1x4 cell array of 1 output}
        biases: {4x1 cell array of 4 biases}
  inputWeights: {4x1 cell array of 1 weight}
  layerWeights: {4x4 cell array of 3 weights}
    ...

在所有批次完成后,我如何获得结果 net 变量来保存结果神经网络?

【问题讨论】:

    标签: matlab neural-network


    【解决方案1】:

    如果我理解正确,您将覆盖变量 net 和 tr。只需使用元胞数组:

    在开头声明它:

     net = {};
     tr = {};
    

    并将相关行更改为:

     [net{end+1},tr{end+1}] = ...
    

    【讨论】:

    • 嗯,好像net和tr比较复杂
    • 它应该可以正常工作,因为您可以制作任何类型对象的元胞数组,无论它多么复杂。有用吗?
    • 很遗憾没有。 net 是一个 1x1 网络。这是我得到的错误:???逗号分隔的列表扩展具有非单元格数组的单元格语法。 ==> 122 [net{end+1},tr{end+1}] = train(net,inputs(:,start_index:end_index), targets(:,start_index:end_index)) 的分类错误;
    • 还是不行。我想我可以继续使用 net 它不会覆盖它,因为我也将它用作输入参数。对于 tr,我想我会在第一次迭代中得到它,并停止为下一次迭代生成它。感谢您的帮助
    猜你喜欢
    • 2010-11-20
    • 1970-01-01
    • 2021-02-11
    • 1970-01-01
    • 2015-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-28
    相关资源
    最近更新 更多