4.2. 線下部份實作流程
4.2.2. Facial Word Matrix 的產生
Facial Word Matrix 的產生主要分爲三個部分。1)對 Comic Faces 進行 clustering 的工作。但由於資料量較大,實作時爲了防止 Clustering 過程中記憶體不足的 問題,我們把每個網頁內相似的 Comic Face 優先合併為一個 Facial Word。這樣 可以減少之後對所有網頁進行 Hierarchical Clustering 時的空間複雜度和時間複
‧
30 雜度。我們採用的方法是:
Step 1: 將一個網頁中所有的 Comic Face 及其 Euclidean Distance 建立成一個 Graph。每個 Comic Face 是 Graph 中的 Vertex, 兩個 Comic Face 之間 的Distance 以 Edge 表示。
Step 2: 設定 Threshold,將距離大於 threshold 的 Edge 去除;
Step 3: 最後將 Graph 中每個 Connected Component 中的 Comic Faces 視為一個 Facial Word。
完成每個網頁相似 Comic Faces 的合併後,再對所有網頁中的所有的 clusters 進 行全局的Hierarchical Clustering。實作中我們使用了 Python2.7 的 SciPy Lib 中自 帶的 Hierarchical Clustering 模組來運算後一步驟中的全局分群。在該 Lib 中,
Hierarchical Clustering 的 threshold 有 3 種,分別是 inconsistent,distance 與 max_clusters。我們選用了 inconsistent 作為 Hierarchical Clustering 的分群標準,
inconsistent 指某個 cluster 中父元素與他的子元素們的不一致性,而參照的子元 素的數量則由變數 depth 控制。在我們的實作中, inconsistent threshold 設定爲 0.95,depth 設定為 20,距離計算的方式爲 Euclidean Distance。在實際計算的過 程中,該部份由於需要較大的 RAM,我們將資料上傳至 AWS 進行分群的計 算,並在完成後將結果下載回本機端。2)將每一個分好群的 Clusters 映射爲一 個Facial Word(如圖 4-5 所示),從而構建成 Facial Word Dictionary。3)針對每 個網頁,統計出該網頁中所有 Facial Word 出現的次數作爲權重,並使用 Vector Space Model [20]的形式表現。最後將所有網頁的 Facial Word Vector 整合,形成 Facial Word Matrix,這將使用在最後的圖文特徵整合部分。
‧
31 4.2.3. 網頁文字處理
由於網頁文檔(HTML 檔案)的結構和語法規則相對鬆散,這使得在進行文字 分析前,對於網頁文檔的內容提純成爲必頇。實作中我們使用了“Beautiful Soup 4” 對 網 頁 文 本 進 行 內 容 提 取 的 工 作 , 實 際 結 果 表 明 Beautiful Soup 對 HTML/XML 解析有不錯的效果。
在提取了 HTML 中的中文文字後,我們使用中國大陸研發的 jieba 斷詞工 具進行了中文斷詞的工作,其效果可見第 3 章圖 3-11。最後我們根据經典的 Bag-of-Words 文檔分析方法,將斷詞後的每一個文檔都表示成 Vector Space Model 的形式,最後將這些向量拼合成 Textual Word Matrix。
4.2.4. 圖文矩陣 & 網頁相似度
在進行圖文特徵矩陣的語義分析時,我們使用 Gensim Library 進行 LDA Model 的訓練,實現了對圖文特徵矩陣從高維到低維的映射。但由於資料量較大,這 一過程我們運用 AWS 將 Large Scale Matrix 的降維計算放到雲端進行,但是計 算後的 LDA model 同樣是個很大的檔案,無法從 AWS 上整個下載到本機端,
圖 4-5 Face ROIs Clusters 到 Facial Word 的映射
‧
國
立 政 治 大 學
‧
Na tiona
l Ch engchi University
32
也就無法進行高精度的Web Topic Possibility Feature 之間的相似度計算。因此我 們退而求其次,我們在實作中使用 Gensim 計算得到的 LDA model 所自帶的 show 函數,將每個網頁的 Web Topic Possibility Feature 中較重要得維度顯示
(如圖 4-6 所示)並保存到本機端,之後自行運算網頁間的相似度。由於只保 留了向量中部分權重較高的維度,因此這使得實作中網頁之間通過 Web Topic Possibility Feature 進行相似度計算存在誤差。這種情況的優勢在於,它忽略了 權重較低的特徵維度,使得明顯不相關的網頁之間的相互干擾降到了最低;但 這同樣也是缺點,它使得不同網頁之間的關聯不再那麼頻繁,缺失了不少資 訊。
此外還有一個較明顯的問題,因爲 Web Topic Possibility Feature 中的低權重 分量被刪除,導致原本經過 Normalization 的向量之間變得權重不再等同,這等 價於網頁之間的重要性失去平衡;對於網頁而言,被刪除的 Topic 分量的模越 大,將會使得該網頁的重要性越低。爲此我們針對這一情況,重新對每個網頁
圖 4-6 Web Topic Possibility Feature 的顯示效果(局部)
‧
國
立 政 治 大 學
‧
Na tiona
l Ch engchi University
33
的 Web Topic Possibility Feature 進行了 Normalization 的工作,此後才重新計算 相互之間的網頁相似度。
34
圖 4-7 系統的動漫搜索介面
圖 4-8 系統的搜索結果返回介面
‧
國
立 政 治 大 學
‧
Na tiona
l Ch engchi University
35
圖 4-9 依據圖、文特徵給出推薦
‧
國
立 政 治 大 學
‧
Na tiona
l Ch engchi University
36
Number of Web Pages 28,898
Number of Web Pages with Images 17,655
Number of Images 269,671
Average Number of Images per Web Page 9.33 Average Number of Images per Web Pages with Images 15.27 Number of Textual Words 767,220 Number of Facial Words 155,606
我們不僅希望由種子網頁所推薦出來的動漫網頁都與種子網頁同屬於一部
37
38
39
評分的均值。從該圖上可以比較直觀的看到圖文關聯特徵擁有較優秀的表現,
然後則依次是純文字特徵,圖、文比例特徵,最後則是純圖像特徵。對於不同 類別的種子在四種特徵(評估方法)下的表現,我們依據所有種子所推薦的前 10 個網頁中,前n 項的網頁評分均值將它們依次繪製在圖 5-3~圖 5-5 中。
圖 5-1 排在第 n 名的網頁的評分均值
圖 5-2 前 n 個網頁的評分均值對比
‧
國
立 政 治 大 學
‧
Na tiona
l Ch engchi University
40
圖 5-3 前 n 個網頁的評分均值對比(動漫本體類別)
圖 5-4 前 n 個網頁的評分均值對比(動漫元素類別)
‧
國
立 政 治 大 學
‧
Na tiona
l Ch engchi University
41
圖 5-5 前 n 個網頁的評分均值對比(聲優/漫畫家類別)
表 5-3 四種評估方法在不同類別的種子網頁前提下的 DCG 表現 方法
類別
圖像特徵 文字特徵 圖文比例特徵 圖文關聯
動漫本體 32.3191 38.5411 35.3084 40.4968 動漫元素 30.9400 37.4039 34.4132 40.8913 聲優/漫畫家 27.1689 29.1072 29.7503 29.3304 整體 30.8209 36.6954 34.0753 39.4384
表 5-4 四種評估方法在不同類別的種子網頁前提下的 NDCG 表現 方法
類別
圖像特徵 文字特徵 圖文比例特徵 圖文關聯
動漫本體 0.9252 0.9378 0.9517 0.9545 動漫元素 0.9319 0.9388 0.9457 0.9484 聲優/漫畫家 0.9577 0.9625 0.9547 0.9540 整體 0.9333 0.9414 0.9482 0.9505
‧
國
立 政 治 大 學
‧
Na tiona
l Ch engchi University
42
我們可以觀察到圖文關聯特徵在針對動漫本體、動漫元素時都有較優的表 現,但是在評估種子類別為“聲優/漫畫家”時,並無突出表現。
最後,我們依據動漫種子的分類,測詴了 4 種特徵(評估方法)的 DCG
(Discounted Cumulative Gain)值以及 NDCG(Normalize DCG)值,如表 5-3 和表 5-4 所示,在當前實驗資料中,就 DCG 而言圖文關聯特徵整體上優於其他 三類特徵,根據DCG 的特性,我們可以推測測詴者打分時給圖文關聯特徵這種 方法的分數相較于其他 3 種 baseline 要高,但在“聲優/漫畫家”類別的動漫種子
網頁中,圖文關聯特徵並無優勢。而 NDCG 則主要衡量了網頁排名的優劣問
題,我們可以觀察到除了“聲優/漫畫家”類別的動漫種子網頁,圖文關聯特徵在 網頁排名問題上相較于其他3 種 baseline 特徵略佔優勢。
‧
國
立 政 治 大 學
‧
Na tiona
l Ch engchi University
43 word 的 distribution 並不一定符合 LDA 所要求的 multinomial distribution,2)純
‧
44
圖像特徵當做 facial word 來看時,word 互相之間的關聯性並不高。因此我們將 在 未 來 的 研 究 中 應 用 圖 像 分 析 領 域 較 常 見 的 Principal Component Analysis
(PCA)來獲取純圖像特徵,並將純圖像的 PCA 特徵添加到評估的 baseline 中,使得在評估我們所提出的圖文關聯方法時,幾種 baseline 特徵能夠更為客 觀可靠,更有參考價值。
‧
國
立 政 治 大 學
‧
Na tiona
l Ch engchi University
45
參考文獻
[1] H. Bay, T. Tuytelaars and L. Van Gool, "SURF: Speeded up Robust Features,"
European Conference on Computer Vision, 2006.
[2] D. M. Blei, Andrew Ng and M. Jordan. "Latent Dirichlet Allocation," The Journal of Machine Learning Research, Vol.3, pp. 993-1022, 2003.
[3] M. Brown and D. Lowe, "Recognizing Panoramas," The 9th International Conference on Computer Vision, pp. 1218-1227, 2003.
[4] J. Canny. "A Computational Approach to Edge Detection," IEEE Transactions on Pattern Analysis and Machine Intelligence, Vol.8, No.6, pp. 679-698, 1986.
[5] N. Dalal and B. Triggs, "Histograms of Oriented Gradients for Human Detection," IEEE Conference on Computer Vision and Pattern Recognition, Vol.1, pp. 88–893, 2005.
[6] S. Deerwester, S. Dumais, T. Landauer, G. Furnas, and R. Harshman, "Indexing by latent semantic analysis," Journal of the American Society for Information Science and Technology , Vol.41, pp. 391-407, 1990.
[7] T. Gritti , C. Shan , V. Jeanne and R. Braspenning, "Local features based facial expression recognition with face registration errors," Automatic Face & Gesture Recognition, FG '08. 8th IEEE International Conference, pp. 1-8, 2008.
[8] T. Hofmann, "Probabilistic Latent Semantic Analysis," Uncertainty in Artificial Intelligence, UAI’99, pp. 289-296, 1999.
[9] L. Juan and O. Gwun, "A Comparison of SIFT, PCA-SIFT and. SURF,"
International Journal of Image Processing, Vol. 65, pp. 143-152, 2009.
[10] Y. Ke and R. Sukthankar, "PCA-SIFT: A More Distinctive Representation for Local Image Descriptors," Computer Vision and Pattern Recognition, Vol.2, 2004.
[11] M. La Cascia , S. Sethi , S. Sclaroff, "Combining Textual and Visual Cues for
46
Content-Based Image Retrieval on the World Wide Web," IEEE Workshop on Content - Based Access of Image and Video Libraries, pp.24, June. 1998
[12] R. Lienhart and J. Maydt, "An Extended Set of Haar-like Features for Rapid Object Detection," IEEE International Conference on Image Processing 2002, Vol.
1, pp. 900-903, Sep. 2002.
[13] D. G. Lowe, "Object Recognition from Local Scale-invariant Features," the International Conference on Computer Vision, Vol.2, pp. 1150–1157, 1999.
[14] D. G. Lowe, "Distinctive Image Features from Scale-invariant Keypoints,"
International Journal of Computer Vision, Vol.60, No.2, pp. 91-110, 2004.
[15] K. Mikolajczyk and C. Schmid, "A Performance Evaluation of Local Descriptors," IEEE Transactions on Pattern Analysis and Machine Intelligence, Vol.27, No.10, pp. 1615-1630, 2005.
[16] T. Ojala, M. Pietikäinen, and D. Harwood, "Performance evaluation of texture measures with classification based on Kullback discrimination of distributions,"
IAPR International Conference on Pattern Recognition (ICPR), Vol. 1, pp.582–
585, 1994.
[17] T. Ojala, M. Pietikäinen, and D. Harwood, "A Comparative Study of Texture Measures with Classification Based on Feature Distributions," Pattern Recognition, Vol. 29, pp. 51-59, 1996.
[18] T. Ojala, M. Pietikainen and T. Maenpaa, "Multiresolution Gray-Scale and Rotation Invariant Texture Classification with Local Binary Patterns," IEEE Transaction on Pattern Analysis and Machine Intelligence, Vol. 24, No. 7, pp.971−987, 2002.
[19] T. Reenskaug, "Thing-model-view-editor - an Example from a Planning System,
" Xerox PARC Technical Note, 1979.
[20] G. Salton, A. Wong, and C. S. Yang, "A Vector Space Model for Automatic Indexing," Communications of the ACM, Vol. 18, No. 11, pp. 613–620, 1975.
[21] H. Schneiderman and T. Kanade, "A Statistical Method for 3D Object Detection Applied to Faces and Cars," IEEE Conference on Computer Vision and Pattern
‧
47 Recognition, 2000.
[22] W. Sun and K. Kise, "Detecting Printed and Handwritten Partial Copies of Line Drawings Embedded in Complex Backgrounds," International Conference on Document Analysis and Recognition, pp. 909–919, 2009.
[23] W. Sun and K. Kise, "Similar Partial Copy Detection of Line Drawings Using a Cascade Classifier and Feature Matching," International Workshop on Computational Forensics, pp.126-137, 2010.
[24] W. Sun and K. Kise, "Similar Manga Retrieval Using Visual Vocabulary Based on Regions of Interest," International Conference on Document Analysis and Recognition, pp. 1075-1079, 2011.
[25] S. Tollari, H. Glotin, "Web Image Retrieval on ImagEVAL: Evidences on Visualness and Textualness Concept Dependency in Fusion Model," ACM International Conference on Image and Video Retrieval (CIVR), July. 2007.
[26] P. Viola and M. Jones, "Robust Real-Time Face Detection," International Journal of Computer Vision, Vol. 57, No. 2, pp.137–154, 2004.
[27] Q. Zhu, S. Avidan, M. Yeh and K. Cheng, "Fast Human Detection Using a Cascade of Histograms of Oriented Gradients," IEEE Conference on Computer Vision and Pattern Recognition, Vol. 2, pp.1491–1498, 2006.
[28] Naotoshi Seo's note site, http://note.sonots.com/
[29] 百度百科,http://baike.baidu.com/
[30] 日本動漫,http://baike.baidu.com/view/495014.htm