减少Matlab中的迭代次数

时间:2014-06-16 11:47:20

标签: matlab neural-network

我正在使用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);

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

1 个答案:

答案 0 :(得分:1)

现在我知道了答案。我找到了办法。

networkname.trainParam.epochs = #Number of iterations;