1. 程式人生 > >[Learning Deep Features for Scene Recognition using Places Database]場景分類demo的實現

[Learning Deep Features for Scene Recognition using Places Database]場景分類demo的實現

需要預先安裝包:

numpy
pytorch
opencv-python
Pillow

首先將places365的程式碼git到本地:

git clone https://github.com/CSAILVision/places365.git

程式包大約有1.37Mb左右。

cd palces365

執行demo程式:

python run_placesCNN_basic.py

程式run_placesCNN_basic.py中使用的架構(arch)是resnet18網路,因此程式碼段中會通過http請求自動下載與訓練好的權重resnet18_places365.pth.tar

以及標籤目錄categories_places365.txt檔案,再通過http請求下載測試圖片12.jpg,返回訓練結果:
12

2018-05-18 20:01:26 (82.8 KB/s) - 已儲存 “12.jpg” [63736/63736])

resnet18 prediction on 12.jpg
0.621 -> patio
0.296 -> restaurant_patio
0.021 -> porch
0.018 -> beer_garden
0.012 -> courtyard

識別結果為院子。
如果覺得上面的功能太簡單,還可以執行下面的demo程式:

 python run_placesCNN_unified.py

需要下載categories_places365.txtIO_places365.txtlabels_sunattribute.txtW_sceneattribute_wideresnet18.npywideresnet18_places365.pth.tar以及測試圖片test.jpg當然程式會自動將這些檔案下載好,直接輸出結果:
這裡寫圖片描述

RESULT ON http://places.csail.mit.edu/demo/6.jpg
--TYPE OF ENVIRONMENT: indoor
--SCENE CATEGORIES:
0.511 -> food_court
0.085 -> 
fastfood_restaurant 0.083 -> cafeteria 0.040 -> dining_hall 0.021 -> flea_market/indoor --SCENE ATTRIBUTES: no horizon, enclosed area, man-made, socializing, indoor lighting, cloth, congregating, eating, working Class activation map is saved as cam.jpg

可以看出來ResNet將圖片識別成food_court飯廳,底下還有相關的場景屬性描述(沒有地平線封閉空間人造場景社交等等)以及生成分類啟用圖片:
這裡寫圖片描述

實在是很神奇~