簡體   English   中英

如何在 matlab 中多次訓練神經(模式識別)網絡?

[英]How can I train a neural (pattern recognition) network multiple times in matlab?

我需要在 matlab 中訓練一個模式識別網絡。 我有幾個數據集可用於訓練。 我的腳本如下所示:

%%% train network with a couple of datasets
pathStr = 'Daten_Training';
files = dir(sprintf('%s/*.mat',pathStr)); 

for k = 1:length(files)

    %%% load data for training
    load(sprintf('%s/%s',pathStr, files(k).name));

    %%% manually set targets to train the network with
    Targets = setTargets(Data);

    %%% create and train neural network
    % Create a Pattern Recognition Network
    hiddenLayerSize = 20;
    net = patternnet(hiddenLayerSize);

    % Train the network with our Data
    net = trainNetwork(net,Data,Targets);

end

trainNetwork函數如下所示:

function [ net ] = trainNetwork( net, Data, Targets )

    % calculate features
    [Features, TargetsBlock, blockIdx] = calcFeatures_Training(Data, Targets);

    % split data for training
    net.divideParam.trainRatio = 70/100;
    net.divideParam.valRatio = 15/100;
    net.divideParam.testRatio = 15/100;

    % Train the network
    [net, tr] = train(net, Features, TargetsBlock);

end

有沒有辦法以相同的結果進行多次訓練,就像我對所有數據集連續使用一次訓練一樣? 現在看起來網絡只是用新數據重新訓練,之前的一切都丟失了。

不要現在它是否實際,但也許對某人有幫助。

一個網絡只能訓練一次。 如果你再次訓練,它將是一個新的網絡。 :) 權重會有所不同。 如果您提供相同的名稱,MATLAB 將在您每次運行腳本時覆蓋。

我認為最好的方法是:

  1. 使用您自己的輸入、層和選項訓練您的網絡。
  2. 使用以下函數將您的網絡保存到一個文件中: save('myFilename.mat','myNetname');
  3. 從文件加載你的網絡: load('myFilename.mat');
  4. 更改輸入 - 也許您有多個數據集。
  5. 更新網絡上的權重,並評論訓練選項 (%)! 不要再次訓練網絡。 您可以使用以下函數進行更新: myNetname = predictAndUpdateState(myNetname,someInput);

希望這對某人有幫助:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM