[Learning Deep Features for Scene Recognition using Places Database]场景分类demo的实现

参考:https://github.com/CSAILVision/places365
论文:Learning Deep Features for Scene Recognition using Places Database

需要预先安装包:

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饭厅,底下还有相关的场景属性描述(没有地平线封闭空间人造场景社交等等)以及生成分类激活图片:
这里写图片描述

实在是很神奇~

猜你喜欢

转载自blog.csdn.net/weixin_39449466/article/details/80369349
今日推荐