2012-04-25 55 views
-2

使用神經網絡比訓練需要更長的時間。我在做可怕的錯誤嗎? 2分鐘使用vs 14秒進行訓練。如何加快matlab中的神經網絡性能?

load building_dataset % 4208 examples 

inputs = buildingInputs; 
targets = buildingTargets; 

% Create a Fitting Network 
hiddenLayerSize = 10; 
net = fitnet(hiddenLayerSize); 

% Setup Division of Data for Training, Validation, Testing 
net.divideParam.trainRatio = 70/100; 
net.divideParam.valRatio = 15/100; 
net.divideParam.testRatio = 15/100; 

% Train the Network 
tic 
[net,tr] = train(net,inputs,targets); 
training_time = toc % ~= 14 seconds 

% use the neural network 
time = 0; 
for i = 1:4208 
    test_input = buildingInputs(:,i); 
    tic 
    test_output = net(test_input); 
    time = time + toc; 
end 

time % ~= 117 seconds 
average_time = time/4208 % ~= 0.028 seconds 

回答

1

您必須對輸入進行矢量化。與此替換for循環:

test_input = buildingInputs(:,:); 
    tic 
    test_output = net(test_input); 
    time = time + toc; 

輸出將結果

的矩陣