bayonã使ã£ã¦ç»åããbag-of-keypointsãæ±ãã
クラスタリングツールbayonã¨OpenCVã使ã£ã¦ãç»åããbag-of-keypointsãç¹å¾´éã¨ãã¦æ½åºããæé ã«ã¤ãã¦æ¸ãããã¨æãã¾ããbag-of-keypointsã¯èªç¶è¨èªå¦çã§ãã使ç¨ãããbag-of-words(æç« ãåèªã®éåã§è¡¨ç¾ãããã®)ã¨åããããªãã®ã§ãç»åä¸ã®å±æçãªç¹å¾´é(keypoint)ã®éåã§ç»åã®ç¹å¾´ã表ãã¾ããbag-of-wordsã¨åãå½¢å¼ã§ãã®ã§è¨èªå¦çã¨åãããã«ãbag-of-keypointsãã¼ã¿ã使ã£ã¦ã¯ã©ã¹ã¿ãªã³ã°ãã¼ã«ã«é©ç¨ãããã転置ã¤ã³ããã¯ã¹ã«è¼ãããã¨ãã£ããã¨ãå¯è½ã«ãªãã¾ãã
ä»åã¯ç»åããbag-of-keypointsãåãåºãããã®ãã¼ã¿ã使ã£ã¦bayonã§ç»åéåãã¯ã©ã¹ã¿ãªã³ã°ããã¨ããã¾ã§ãã£ã¦ã¿ã¾ããã¡ãªã¿ã«ç»åå¦çã¯å®å ¨ã«ç´ 人ã§ããã®è¨äºããã¯ã«ç¥èã§æ¸ãã¦ããã®ã§ãééã£ã¦ããç®æããã£ã¨å¹çã®ããææ³ãããããããã¾ããããã®éã¯è¨äºã«ã³ã¡ã³ãããã ããã°å¹¸ãã§ãm(_ _)m
bag-of-keypointæ½åºæé ã®æ¦è¦
- åç»åããå±æç¹å¾´éãæ½åºãã
- å±æç¹å¾´éãã¯ã©ã¹ã¿ãªã³ã°ããã¯ã©ã¹ã¿ã®ä¸å¿ãvisual words(代表çãªãã¿ã¼ã³)ã¨ãã
- åå±æç¹å¾´éã«å¯¾ãä¸çªè¿ãvisual wordãæ±ããç»åå ¨ä½ã®ç¹å¾´éãvisual wordsã®ãã¹ãã°ã©ã (bag-of-keypoints)ã§è¡¨ç¾ãã
ç»åã®å±æç¹å¾´éã¯SIFTã使ãã¾ããSIFTã§ã¯ç»åä¸ã®ç¹å¾´çãªç¹(keypoint)ãããã¤ãæ½åºãã¾ããåkeypointã¯128次å ã®ç¹å¾´ãã¯ãã«ã¨ãªããæ½åºãããkeypointã®æ°ã¯ç»åã«ãã£ã¦ç°ãªãã¾ãããã®ããã«keypointãã¨ã«ç¹å¾´ãã¯ãã«ãæã¤ãããç»åå ¨ä½ã®ç¹å¾´ãã¯ãã«ã表ãã«ã¯ãã®ã¾ã¾ä½¿ç¨ããã®ã¯å°é£ã§ãã
ããã§å±æç¹å¾´éãã¯ã©ã¹ã¿ãªã³ã°ãã¦åã¯ã©ã¹ã¿ã®ä¸å¿ãã¯ãã«ãç¹å¾´çãªãã¿ã¼ã³(ããã§ã¯Visual Wordsã¨å¼ã¶)ã¨ããåå±æç¹å¾´éã¯æãè¿ãVisual Wordã§ç½®ãããããã¨ã§ãç»åå ¨ä½ã®ç¹å¾´ãVisual Wordã®é »åº¦(ãã¹ãã°ã©ã )ã§è¡¨ç¾ãããã¨ãã§ãã¾ãããã®Visual wordã®ãã¹ãã°ã©ã ãbag-of-keypointã¨å¼ã³ã¾ãã
SIFTãbag-of-keypointsã«ã¤ãã¦ã¯ã以ä¸ã®è³æãé常ã«åãããããã£ãã®ã§ããã詳ããç¥ãããæ¹ã¯ãã¡ãããåç §ä¸ããã
å¿ è¦ãªãã®
- OpenCV
- SIFT Feature Detector
- クラスタリングツールbayonの最新版
- Caltech101(ç»åã®ãã¼ã¿ã»ãã)
- 記事用に作成したコード
OpenCVã®ãã¼ã¸ã§ã³ã2.0以éã®å ´åã¯ãSIFT Feature Detectorãã³ã³ãã¤ã«ããæã¯ä»¥ä¸ã®ãã¼ã¸ãåèã«ãã¦ã½ã¼ã¹ã³ã¼ããä¿®æ£ãã¦ããã¦ãã ããã
ç»åãã¼ã¿ã¯ã¨ããããcaltech101ã使ç¨ãã¾ãããå¥ã§ç¨æã§ããã®ã§ããã°ä½ã§ãæ§ãã¾ããã
1.å±æç¹å¾´éãæ½åºãã¦bayonã®å ¥åãä½æ
ã¾ãã¯SIFT Feature Detectorã使ã£ã¦åç»åããSIFTãç¹å®ããbayonã«é©ç¨ããå ¥åãã¡ã¤ã«ãä½æãã¾ãã以ä¸ã®ããã«å®è¡ãã¦ãã ããã"/path/sift/bin/siftfeat"ã¯SIFT Feature Detectorããã«ãããæã«çæãããå®è¡ããã°ã©ã ã®ãã¹ã§ãã
% mkdir data % find /path/caltech101 -name "*.jpg" | ./save_sift.pl /path/sift/bin/siftfeat data/siftmap.tsv > data/input.tsv
SIFTã®å座æ¨ã1ã¤ã®ããã¥ã¡ã³ãã¨ãã¦åºåãã¾ãããã®ã¨ãå座æ¨ã«åºæã®IDãå²ãæ¯ãã®ã§ãåç»åä¸ã®SIFTç¹å¾´éãã©ã®IDã«æ¡çªããããã data/siftmap.tsv ã«ä¿åãã¦ããã¾ãã
2. å±æç¹å¾´éãã¯ã©ã¹ã¿ãªã³ã°ãã¦Visual Wordsãç¹å®
次ã«ä¸è¨ã®SIFTç¹å¾´éãã¯ã©ã¹ã¿ãªã³ã°ãã¾ããå¾ãããã¯ã©ã¹ã¿ã®ä¸å¿ãã¯ãã«ãVisual wordsã«ãªãã¾ãã
ãã ãå®è¡ç°å¢ã«ãã£ã¦ã¯ããã¹ã¦ã®SIFTç¹å¾´éãã¯ã©ã¹ã¿ãªã³ã°ããã«ã¯ã¡ã¢ãªã足ããªãå ´åãããã¾ããããã§ã©ã³ãã ã«ããã¤ãã®åº§æ¨ãæãåºãã¦ããã®åº§æ¨ã®ã¿ã§ã¯ã©ã¹ã¿ãªã³ã°ãè¡ãããã«ãã¾ããä¸è¨ã§ã¯å ¥åãã¡ã¤ã«ããã©ã³ãã ã«10åã®1è¡é¸æãã¦ã¾ããæ¬æ¥ãªãåã«ãã´ãªããåçã«é¸æããããã«ããæ¹ãããããã§ãããä»åã¯å ¨ä½ããã©ã³ãã ã«æ½åºãã¾ãã
% ./rand_line.pl data/input.tsv 10 > data/input_10.tsv
ã§ã¯æ¬¡ã«ã¯ã©ã¹ã¿ãªã³ã°ãè¡ãã¾ããbayonã使ã£ã¦ä»¥ä¸ã®ããã«å®è¡ãã¦ãã ããã
% bayon -l 1.5 -c data/centroid.tsv --clvector-size 128 data/input_10.tsv > /dev/null
ã¯ã©ã¹ã¿ã®ä¸å¿ãã¯ãã«(ããã visual words ã«ãªãã¾ã)ã data/centroid.tsv ã«ä¿åãã¦ããã¾ãããã®éããã©ã«ãã§ã¯50次å ã¾ã§ãããã¯ãã«ã®è¦ç´ ãä¿åããªãã®ã§ãä¸å¿ãã¯ãã«ã®ãµã¤ãºãSIFTã¨åã128次å ã«æå®ãã¦ããå¿ è¦ãããã¾ããã¾ãã¯ã©ã¹ã¿ãªã³ã°çµæãã®ãã®ã¯ç¹ã«ä½¿ããªãã®ã§ã/dev/nullã«æµãè¾¼ãã§å»æ£ãã¾ãã
åSIFTç¹å¾´éã«æãè¿ãvisual wordãç¹å®ãbag-of-keypointsãä½æ
次ã«åSIFTç¹å¾´éã«å¯¾ããä¸çªé¡ä¼¼ãã¦ããvisual wordãç¹å®ãã¾ããããã¯bayonã®-Cãªãã·ã§ã³ã§ããã£ã¨ã§ãã¾ããä¸çªè¿ããã®ã ãåããã°ããã®ã§ã--classify-size=1 ãæå®ãã¦é¡ä¼¼ãããã¯ãã«ã®åºåã1ã¤ã ãã«ãã¦ããã¾ããçµæ§æéããããã®ã§æ°é·ã«å¾ ã¡ã¾ãã
% bayon -C data/centroid.tsv --classify-size 1 data/input.tsv > data/classify.tsv
æå¾ã«åç»åã®ç¹å¾´éãvisual wordsã®ãã¹ãã°ã©ã (bag-of-keypoints)ã§è¡¨ç¾ãã¾ãã
% ./assign_vwords.pl data/siftmap.tsv data/classify.tsv > data/bok.tsv
å¾ãããbag-of-keypointsã¯ä»¥ä¸ã®ããã«ãªãã¾ãã
% cat data/bok.tsv /path/caltech101/101_ObjectCategories/accordion/image_0001.jpg 20 1 39 1 59 1 77 1 79 1 120 6 122 1 144 2 167 1 200 1 ...
å é ãç»åãã¡ã¤ã«åã§ããã以é㯠"visualword_id1 \t count1 \t visualword_id2 \t count2 ..." ã¨ãªãã¾ããvisualword_idé¨åãä¾ãã°ããããããå¤§æ ¹ãã®ãããªåèªã«å¤ãã¦ã¿ãã°ãããã¯bag-of-wordsã¨ã¾ã£ããåã表ç¾ã§ãããã¨ãåããã¾ãã
ããã§ã¡ãã£ã¨æã£ãã®ã§ãããbag-of-keypointsã¯å¥ã«ä¸çªä¼¼ã¦ãããã®ã®é »åº¦ãããªãã¦ãä¼¼ã¦ãããã®ä¸ä½5åãããã®é¡ä¼¼åº¦(0ã1)ãåããããã¯ãã«ã§ãããããããªãããª...ï¼ã¾ãã¨ããããä»åã¯æç®ã®ããæ¹ã«å¾ãã¾ãã
ç»åéåãã¯ã©ã¹ã¿ãªã³ã°
ä½æããbag-of-keypointsã使ã£ã¦ãç»åéåãbayonã§ã¯ã©ã¹ã¿ãªã³ã°ãã¦ã¿ã¾ããcaltechã¯ç·æ°ã9143åã§ãããã¨ãããã500åã®ã¯ã©ã¹ã¿ã«åå²ãã¾ããã¾ãbayonãå®è¡ããéã--idfãªãã·ã§ã³ãã¤ãã¦ç¹å¾´ãã¯ãã«ã«è£æ£ãããããã¨ã«ãã¾ãã
% bayon -n 500 --idf data/bok.tsv > data/cluster.tsv
å°ãã¯ã©ã¹ã¿ãªã³ã°çµæãçºãã¦ã¿ãå°è±¡ã ã¨ã人ã®é¡ã¯ãã解æã§ãã¦ãããã©ãããããã®ã¯ã©ã¹ã¿ãçµæ§ãªå²åã§ããã®ã§ãããå°ãæ¹åãå¿ è¦ãªæãã§ãããbayonã®ç²¾åº¦ããã¾ãã¡ãªã®ããbag-of-keypointsã®çµæããã¾ãã¡ãªã®ããã¡ããã¨æ¤è¨¼ã§ãã¦ãªãã®ããã¡ãªã®ã§ãããã¾ãã¨ããããããç¨åº¦ã¯ä½¿ããããªã¨ã
ãªããªããã¾ãã§ããã¯ã©ã¹ã¿ãããã¤ãè¼ãã¦ããã¾ãã
ã¾ã¨ã
bayonã使ã£ã¦ç»åããbag-of-keypointsãæ½åºãã¾ãããã¾ãæ½åºçµæã使ç¨ãã¦bayonã§ç»åéåãã¯ã©ã¹ã¿ãªã³ã°ããããç¨åº¦ã®ç²¾åº¦ãå¾ããã¦ãããã¨ã確èªãã¾ãããbag-of-wordsã¨åãå½¢å¼ã§ãã®ã§ãä»ã«ãæ¢åã®æ¤ç´¢ã¨ã³ã¸ã³ãåé¡å¨ã«å ¥ãããã¨ãã£ããã¨ãã§ããã¨æãã¾ããããããã¯é¡ä¼¼ç»åæ¤ç´¢ãä½ããã°ãããªã¼ã¨å¦æ³ãã¦ã¾ãã
ã¾ãä»åã¯å±æç¹å¾´éã«SIFTã使ç¨ããã®ã§ãããSIFTã¯ç¹è¨±ãåããã¦ããã®ã§åç¨ã§ä½¿ãå ´åã¯ã¡ãã£ã¨å³ãããã§ããããã§SIFTã¨åããããªå±æç¹å¾´éã¨ãã¦SURFã¨ããã¢ã«ã´ãªãºã ãããããã§ãã®ã§ãç¾å¨ããã使ã£ã¦bag-of-keypointsãæ±ããããå®è£ ä¸ã§ããSURFã¯OpenCVã«ãå ¥ã£ã¦ããã®ã§æ¯è¼çç°¡åã«ä½¿ãã¾ãã
ãã¨ä»åã¯ã³ãã³ãã©ã¤ã³ããä¸ã¤ä¸ã¤å¼ã³åºãããã«ãã¦ã¾ããããå®éã«ä½¿ãã¨ãã¯é¢åãªã®ã§ãããå°ãã¾ã¨ããå½¢ã§å®è£ ãç´ãã¦å ¬éãããã§ããã
追è¨ï¼SURFãç¹è¨±ãã¨ããã¦ããããããåç¨å©ç¨ã¯è¨±å¯ãããããã§ãã
çµå±ã®ã¨ããåç¨ã§å±æç¹å¾´éã¯ä½ã使ãã®ããããã§ãããï¼ç¥èã足ããªãéããâ¦ã