我把補充的內容放最前面,顯眼!
補充:1 關於負樣本。架構裡面提取負樣本的方式是選擇樣本庫中不包含訓練類型的圖片為負樣本。我直接用庫裡面的圖片。我用1000張左右的負樣本,自己準備的話也簡單沒太多好說的。提供圖片路徑就OK了,它自己會裁。
2 關於自己準備正樣本要注意的問題:
(1) pos(numpos).flip = false;
pos(numpos).trunc = 0;
(2) 最好不要自己手動裁正樣本小圖片當正樣本圖片,而應該將一張圖片的中的正樣本用座標表示出來,做成類似原架構中的解析檔案(用OPENCV之類的東西做 應該容易吧),我是寫指令碼解析的別人的樣本庫,我的解析檔案格式是:x1 y1 x2 y2 filepath, 這樣一行對應一個正樣本,在MATLAB格式化讀取也方便。注意!沒有標LABEL,RESIZE之類的步驟!只需要指明正樣本的框,和相應的圖片路徑就OK。
3 關於pascal()第二個參數的問題:按作者的說法(組件的個數)不太好理解。我理解的意思是:Model中子模型的個數。這個值的設定比較重要,一般設定成1. 如果正樣本比較多樣化,比如行人樣本中有兩種情況:站立的,躺著的。這時應該設定成2。如果基本上只有一種情況,設成1就夠了,因為設定成多個的話, 效果提 高不了多少,檢測速度還慢了不少!看一下代碼應該知道,組件分類的時候,只是簡單的按SIZE的寬高比例分,並沒有還可以分正面反面那麼進階。
4 part個數 part大小的設定:在pascal_train.m裡面model_addparts函數的最後兩個參數。目標不同,這兩個參數也可能不一樣,可以先目測一下,大約多少個part可以基本捕獲目標的基本特徵。可能需要實驗多次。
5 訓練時間問題:剛開始調整訓練參數的時候,只需要看大致的效果,所以只用很少的樣本量就可以,還嫌慢的話,可以減少learn.cc裡面的迭代次數(我就是這麼幹 的),還可以把pascal_train裡面的maxneg的值改小,比如50。
6 怎麼產生PCA統計資訊檔: 參見http://blog.csdn.net/pozen/article/details/7282124
--------------------邪惡的補充完結分割線-----------------------------
我是在windows平台下訓練模型的。因為Felzenszwalb的架構是不支援WINDOWS的,需要進行一些小的修改才可以,不過一些小錯誤好像是平台無關的,不清楚UNIX下是否同樣存在。
1 首先要下載Felzenszwalb的VOC-release4, 這裡麵包含有模型的訓練指令碼。再下載2011 PASCAL VOC devkit and dataset,這裡麵包含了樣本圖片和這些樣本圖片的解析資訊,以及擷取樣本的相關指令碼。重新指定pascal_init,global中的路徑設定。
Felzenszwalb的代碼中直接調用VOC devkit的指令碼擷取正負樣本。如果你要訓練的模型在樣本庫中不存在樣本,需要自己準備OR需要使用其它樣本庫。那麼你需要更改VOC-release4的pascal_data.m指令碼,它的功能是為訓練準備正負樣本,包含的資訊比較簡單主要就是樣本相對於圖片的框,以及你的本樣圖片的路徑。
2 pascal_data.m中需要幾行代碼來防止因圖片不存在而報錯:
if exist([VOCopts.datadir rec.imgname]) == 0
continue;
end
VOCopts.datadir rec.imgname代表樣本圖片的絕對路徑,建立正負樣本集的時候 都應該進行判斷,我下載的2011的庫存在個別圖片不存在的情況。
3 如果正樣本個數太多的話(超過10000?)會報 out of memory錯誤。這個時候需要在pascal_data.m裡面限制收集樣本的數量。
4 compile learn.cc。如果是在UNIX/LINUX(OR 其類比環境)下的話,可以直接MAKE產生可執行檔,windows下可以用nmake來產生。也可以用VS建一個工程來產生。當然會報一些錯誤,都可以通過GOOGLE解決。
5 compile c++ helper functions.參見:前一篇
6 WINDOWS下需要修正的錯誤(以pascal開頭的幾個指令碼,還有rewritedat.m):
調用unix()的地方換成system() (還需要把mv 換成move, rm 換成del,cp換成copy 等等)
調用./learn 的地方改成 learn
7 執行pascal('person', 3); % train and evaluate a 6 component person model
8 我訓練時出現過的錯誤和解決方案:
把 unix 調用換成system調用 感覺運行不穩定,把rewritedat.m裡面的 unix(['mv ' datfile ' ' oldfile]) 改成 movefile(datfile, oldfile)
unix(['rm ' oldfile]) 改成delete(oldfile)。
同樣是rewritedat.m中還會出現下標越界的情況:
把這段代碼:
I = sort(I);pos = 1;for i = 1:length(I) cnt = I(i)-pos; while cnt > 0 % + 2 to include the num non-zero blocks and example length info = fread(fin, labelsize+2, 'int32'); dim = info(end); fseek(fin, dim*4, 0); cnt = cnt - 1; end y = fread(fin, labelsize+2, 'int32'); dim = y(end);
x = fread(fin, dim, 'single'); fwrite(fout, y, 'int32'); fwrite(fout, x, 'single'); pos = I(i)+1;end
替換成:
I = sort(I);pos = 1;for i = 1:length(I) cnt = I(i)-pos; while cnt > 0 % + 2 to include the num non-zero blocks and example length info = fread(fin, labelsize+2, 'int32'); if length(info) == 0 dim = 0; else dim = info(end); end %dim = info(end); fseek(fin, dim*4, 0); cnt = cnt - 1; end y = fread(fin, labelsize+2, 'int32'); %//! if length(y) == 0 dim = 0; else dim = y(end); end x = fread(fin, dim, 'single'); fwrite(fout, y, 'int32'); fwrite(fout, x, 'single'); pos = I(i)+1;end
類似的越界錯誤在檢測模組中,檢測完成提取框時,如果檢測個數為0的話也可能出現,不過影響不大。
Readme裡面的原文:
Using the learning code
=======================
1. Download and install the 2006/2007/2008 PASCAL VOC devkit and dataset.
(you should set VOCopts.testset='test' in VOCinit.m)
2. Modify 'globals.m' according to your configuration.
3. Run 'make' to compile learn.cc, the LSVM gradient descent code.
(Run from a shell, not Matlab.)
4. Start matlab.
5. Run the 'compile' script to compile the helper functions.
(you may need to edit compile.m to use a different convolution
routine depending on your system)
6. Use the 'pascal' script to train and evaluate a model.
example:
> pascal('person', 3); % train and evaluate a 6 component person model
The learning code saves a number of intermediate files in a cache
directory defined in 'globals.m'. You should delete these files before
training models on different datasets, or when training new models after
modifing the code.
The code also generates some very large temporary files during training
(the default configuration produces files up to about 3GB). They are
placed in a temporary directory defined in 'globals.m'. This directory
should be in a local filesystem.