# Sample code for the Class Activation Mapping
### NEW: PyTorch Demo code
* The popular networks such as ResNet, DenseNet, SqueezeNet, Inception already have global average pooling at the end, so you could generate the heatmap directly without even modifying the network architecture. Here is a [sample script](pytorch_CAM.py) to generate CAM for the pretrained networks.
```
python pytorch_CAM.py
```
You also could take a look at the [unified PlacesCNN scene prediction code](https://github.com/CSAILVision/places365/blob/master/run_placesCNN_unified.py) to see how the CAM along with scene categories, scene attributes are predicted. It has been used in the [PlacesCNN scene recognition demo](http://places2.csail.mit.edu/demo.html).
We propose a simple technique to expose the implicit attention of Convolutional Neural Networks on the image. It highlights the most informative image regions relevant to the predicted class. You could get attention-based model instantly by tweaking your own CNN a little bit more. The paper is published at [CVPR'16](http://arxiv.org/pdf/1512.04150.pdf).
The framework of the Class Activation Mapping is as below:

Some predicted class activation maps are:

### Pre-trained models in Caffe:
* GoogLeNet-CAM model on ImageNet: ```models/deploy_googlenetCAM.prototxt``` weights:[http://cnnlocalization.csail.mit.edu/demoCAM/models/imagenet_googlenetCAM_train_iter_120000.caffemodel]
* VGG16-CAM model on ImageNet: ```models/deploy_vgg16CAM.prototxt``` weights:[http://cnnlocalization.csail.mit.edu/demoCAM/models/vgg16CAM_train_iter_90000.caffemodel]
* GoogLeNet-CAM model on Places205: ```models/deploy_googlenetCAM_places205.prototxt``` weights:[http://cnnlocalization.csail.mit.edu/demoCAM/models/places_googlenetCAM_train_iter_120000.caffemodel]
* AlexNet+-CAM on ImageNet:```models/deploy_alexnetplusCAM_imagenet.prototxt``` weights:[http://cnnlocalization.csail.mit.edu/demoCAM/models/alexnetplusCAM_imagenet.caffemodel]
* AlexNet+-CAM on Places205 (used in the [online demo](http://places.csail.mit.edu/demo.html)):```models/deploy_alexnetplusCAM_places205.prototxt``` weights:[http://cnnlocalization.csail.mit.edu/demoCAM/models/alexnetplusCAM_places205.caffemodel]
### Usage Instructions:
* Install [caffe](https://github.com/BVLC/caffe), compile the matcaffe (matlab wrapper for caffe), and make sure you could run the prediction example code classification.m.
* Clone the code from Github:
```
git clone https://github.com/metalbubble/CAM.git
cd CAM
```
* Download the pretrained network
```
sh models/download.sh
```
* Run the demo code to generate the heatmap: in matlab terminal,
```
demo
```
* Run the demo code to generate bounding boxes from the heatmap: in matlab terminal,
```
generate_bbox
```
The demo video of what the CNN is looking is [here](https://www.youtube.com/watch?v=fZvOy0VXWAI). The reimplementation in tensorflow is [here](https://github.com/jazzsaxmafia/Weakly_detector). The pycaffe wrapper of CAM is reimplemented at [here](https://github.com/gcucurull/CAM-Python).
### ILSVRC evaluation
* See the script [ILSVRC_evaluate_bbox.m](ILSVRC_evaluate_bbox.m) and [ILSVRC_generate_heatmap.m](ILSVRC_generate_heatmap.m) if you want to reproduce the ILSVRC localizatgion result. Also see [this file](http://cnnlocalization.csail.mit.edu/ILSVRC_evaluation_raw.tar.gz) for some intermedate files. You still need to download the ILSVRC toolkit at http://image-net.org/challenges/LSVRC/2012/. The code is written in a rush and without any clean-up, Please figure out how to set up things
properly by yourself.
### Reference:
```
@inproceedings{zhou2016cvpr,
author = {Zhou, Bolei and Khosla, Aditya and Lapedriza, Agata and Oliva, Aude and Torralba, Antonio},
title = {Learning Deep Features for Discriminative Localization},
booktitle = {Computer Vision and Pattern Recognition},
year = {2016}
}
```
### License:
The pre-trained models and the CAM technique are released for unrestricted use.
Contact [Bolei Zhou](http://people.csail.mit.edu/bzhou/) if you have questions.
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
流行的网络,如ResNet、DenseNet、SqueezeNet、Inception,最终已经有了全局平均池,因此您甚至可以在不修改网络架构的情况下直接生成热图。这里有一个[示例脚本](pytorch_CAM.py),用于为预训练的网络生成CAM。 我们提出了一种简单的技术来暴露卷积神经网络在图像上的隐含注意力。它突出显示与预测类别相关的信息量最大的图像区域。你可以通过调整自己的CNN来立即获得基于注意力的模型。该论文发表在[CVPR'16](http://arxiv.org/pdf/1512.04150.pdf)。
资源推荐
资源详情
资源评论

格式:zip 资源大小:15.4MB












格式:pdf 资源大小:254.5KB 页数:4

















收起资源包目录





























































共 56 条
- 1
资源评论


hello_中年人
- 粉丝: 8
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- Java课程设计方案报告-酒店客房管理系统.doc
- 各国强化工业互联网战略标准化成重要切入点.docx
- ANSYS有限元软件建模基础.ppt
- 互联网+对高职学生思想政治教育的影响及其应对探析.docx
- 地铁弱电系统IP网络分配建议方案.docx
- 基于虚拟现实技术的网络会展发展展望.docx
- 数学物理化学生物地理常用软件介绍.doc
- 通信行业发展情况分析-行业集中度整体趋势上行.docx
- 大学设计方案松下FPC型PLC实现交通灯控制大学方案.doc
- 单片机乳化物干燥过程控制系统设计方案.docx
- 物联网工程专业C++程序设计教学改革探索.docx
- 单片机研究分析报告路抢答器.doc
- PLC控制的生活给水泵系统设计.doc
- 非授权移动接入在GSM网络应用中的安全分析.docx
- 2019年二级建造师建设工程项目管理精品小抄.doc
- 《数据库系统》教学设计.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
