【问题标题】:Reduce the number of iterations in Matlab减少Matlab中的迭代次数
【发布时间】:2014-06-17 23:51:07
【问题描述】:

我正在创建一个应用程序来使用 matlab 识别不同种类的叶子。一旦我开始训练网络,它将训练 1000 次迭代。(默认值)这个任务需要 2 多个小时。这是我的代码。

clear ; close all; clc
fruit_list = ['M','G','B','P'];
x = [];
y = [];
training_dir ='Training Images\';
for i = 1:size(fruit_list,2)
    directory = strcat(training_dir,fruit_list(i),'\');
    file_list = dir(strcat(directory,'*JPG'));
    for j = 1:size(file_list)
        im = imread(strcat(directory,file_list(j).name));
        resized = preprocess(im);
        Savefilename = strcat('Preprocessed Training Images\',int2str(i),'+',int2str(j),'.jpg');
        imwrite(resized,Savefilename); 
        col = resized(:);
        x = [x,col];
        o = [0;0;0;0];
        o(i) = 1;
        y = [y,o];
    end
end

nnf = newff(min_max(x),[5 4], {'tansig' 'purelin'});

res = train(nnf,x,y);

pred = sim(res,x);

[val pInd] = max(pred);

for i = pInd
    if i==1
        fprintf('Mango\n');
    elseif i == 2
        fprintf('Guava\n');
    elseif i == 3
        fprintf('Bo\n');
    elseif i == 4
        fprintf('Papaya\n');    
    end

end
[aval aInd] = max(y);
fprintf('\nTraining Set Accuracy: %f\n', mean(double(pInd == aInd)) * 100);
test_directory = 'Test Images\'
[tes_act,test_pred] = test(test_directory,fruit_list,res);
fprintf('\nTest Set Accuracy: %f\n', mean(double(test_pred == test_act)) * 100);

我想减少训练过程中的迭代次数。我该怎么做?请帮帮我。

【问题讨论】:

  • 您是在谈论对代码进行矢量化(即减少循环次数)还是在谈论提高训练过程的效率 -> 减少训练所需的时间?
  • 我想我想减少循环次数。
  • 你分析过它吗?您正在增长矩阵x 的循环可能是问题所在,而不是train 本身。
  • 你想减少神经网络的默认迭代次数吗?
  • 是的。默认的迭代次数是1000。我想把它减少到100次迭代。

标签: matlab neural-network


【解决方案1】:

现在我知道答案了。我找到了一种方法。

networkname.trainParam.epochs = #Number of iterations;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-14
    • 2013-04-15
    • 1970-01-01
    相关资源
    最近更新 更多