2011-04-06 64 views
2

根據last question,我能夠使用已提供的方法保存功能設置。神經網絡的進給功能

FeaturesTest.roundness = roundness;  
FeaturesTest.nWhite = nWhite; 
FeaturesTest.color = color; 
FeaturesTest.descriptors = descriptors; 
FeaturesTest.outputs = outputs; 
FeaturesTest = {roundness,nWhite, color, descriptors, outputs}; 

現在我的第一個4個特徵輸入神經網絡,第5個特徵輸入到目標。我是這樣寫的。

load('features.mat','FeaturesTest'); 
A = FeaturesTest; 
P=A(:,1:4)'; 
T=A(:,5:5)'; 
rand('seed', 491218382); 
net = newff(minmax(P),T,20); 

現在同樣的錯誤出現輸入功能...

???錯誤使用==> horzcat參數尺寸不是 一致。錯誤在==> minmax at 38 pr {i} = minmax([p {i,:}]);

有沒有人有這方面的想法?


@Itamar Katz感謝您向我展示單元陣列和結構的使用。我現在改了它。有這樣一個函數返回一個圖像的特徵。圓度和nWhite只有一個值。描述符是移位描述符。有5種類型的輸出。對於第一個圖像輸出應該是1,第二個,2等等。顏色顯示在.mat文件中[196,186,177]。輸出類似於[1,0,0,0,0]。

function[FeaturesTest] = features(image) 
[siftImage, descriptors, locs] = sift(image); 
FeaturesTest = {roundness, nWhite, color, descriptors, outputs}; 

現在從訓練集中逐一獲取圖像,併爲每個圖像調用上述函數。

for i=1:size(list, 1); 
    if (~(list(i).isdir)) 
     [FeatureSet] = features(fullfile('F:\ProjectWork\Coin_Recognition\TrainingSet', list(i).name)); 
     Features = [Features; FeatureSet]; 
    end 
end 
save('features.mat','Features'); 

現在我想訓練這個功能。我做的是

load('features.mat','Features'); 
A = Features; 
P=A(:,1:4)'; 
T=A(:,5:5)'; 
rand('seed', 491218382); 
net = newff(minmax(P),T,20); 
Error comes here. 

請幫幫我。謝謝。 6個圖像

features.mat文件是這樣的

0.776914651509411 1874 [196,186,177] <14x128 double> 
    [1,0,0,0,0] 
0.839974548665116 1794 [219,213,202] <7x128 double> 
    [1,0,0,0,0] 
0.841707612525928 1796 [192,182,171] <5x128 double> 
    [1,0,0,0,0] 
0.861761793121658 1783 [202,199,192] <13x128 double> 
    [1,0,0,0,0] 
0.411077484660635 3689 [97,88,72] <238x128 double> 
    [0,1,0,0,0] 
0.844865287736163 3372 [166,139,89] <228x128 double> 
    [0,1,0,0,0] 

回答

0

您鏈接到答案使用一個單元陣列,與字段的結構的建議,但你正在做,和你的最後一行:

FeaturesTest = {roundness,nWhite, color, descriptors, outputs}; 

只是覆蓋FeaturesTest使其成爲一個單元陣列,所以所有的行之前是不相關的。

我猜你需要的是這樣的:

P = [roundness(:), nWhite(:), color(:), descriptors(:)]; 
T = outputs(:); 

但是,如果你給有關每個字段的尺寸信息,它會更容易幫助您找出錯誤。

+0

謝謝。在特徵提取功能中,像這樣返回特徵。 FeaturesTest.nWhite = nWhite; FeaturesTest.descriptors =描述符; FeaturesTest.roundness =圓度; FeaturesTest.color = color; FeaturesTest.outputs =輸出;然後FeaturesTest = {圓度,nWhite,顏色,描述符};假設一個圖像的圓度爲<1x1 double>顏色爲<1x3 double> nWhite爲<1x1 double>描述符爲<14x128 double>,輸出爲<1x5 double>有18個硬幣需要訓練。所以FeaturesTest輸入和輸出是<18x5 cell> – 2011-04-06 08:59:58

+0

請參考我上面的問題。我編輯它以提供您要求的尺寸。謝謝 – 2011-04-06 09:22:46

0

你應該看看Itamar Katz的建議。

我想添加以下內容:我認爲問題的核心(對於你的問題)是你不明白在MATLAB中你不能連接不同大小的矩陣。

例如下面是無效:零(5,5),一(4,4)]

如果你嘗試,你會得到正是你得到同樣的錯誤。

矩陣(:)運算符(請參閱Itemar的答案)將其轉換爲一維數組,因此可以連接許多事物。

作爲一個建議,我花了幾個小時才真正理解MATLAB中的矩陣。然後,您可以更有效地推進您的工作。

+0

如果我不能連接不同大小的矩陣,我如何添加篩選特徵描述符到我的特徵。在我訓練圖像之前,我沒有使用這個篩選特徵描述符,並且訓練得很好。即使我沒有使用單元陣列b',因爲所有的特徵都只有1x1的雙倍值。但是,現在我想將這個篩選描述符添加到我的特徵文件中。根據從sift算法返回的關鍵點,它會轉到多行,但對於一個圖像的其他特徵,只有一行存在。有什麼辦法可以將這個篩選特徵放到一行中嗎? – 2011-04-06 09:44:46

+0

可以總結特定列的所有行中的值從篩選返回。那麼對於那個專欄我只能有一行?如果我這樣做,篩選工作的功能會不會好?我對matlab沒有太多的瞭解。你能幫我嗎? – 2011-04-06 09:47:39