使用place2创建场景识别的demo

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

1.需要预先安装包:

  • numpy
  • pytorch
  • opencv-python
  • Pillow


2. 首先将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.txt,IO_places365.txt,labels_sunattribute.txt,W_sceneattribute_wideresnet18.npy,wideresnet18_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饭厅,底下还有相关的场景属性描述(没有地平线,封闭空间,人造场景,社交等等)以及生成分类激活图片: 

è¿éåå¾çæè¿°
实在是很神奇~
 
原文:https://blog.csdn.net/weixin_39449466/article/details/80369349 
 

猜你喜欢

转载自blog.csdn.net/jinking01/article/details/88719573
今日推荐