Code Monkey home page Code Monkey logo

class-activation-mapping's Introduction

Class Activation Mapping

Tensorflow implementation of Learning Deep Features for Discriminative Localization by Zhou et al presented in CVPR'16.

Caffe version by the author is here

Prerequisites

Data

Preparation

  1. Clone this repo, create log/ and caffe_pretrained/ folder:

    git clone https://github.com/markdtw/class-activation-mapping.git
    cd class-activation-mapping
    mkdir caffe_pretrained
    mkdir log
  2. To train on CALTECH256 dataset, download the original VGG16 graph (.prototxt) and model (.caffemodel) from here, save them in caffe_pretrained/ folder.

  3. To test directly from the pretrained ImageNet model, download the vgg16CAM graph and model from the author's repo, save them in caffe_pretrained/ folder as well.

  4. If you went through both 2 and 3, your caffe_pretrained/ folder should contain these:

    • vgg16CAM_train_iter_90000.caffemodel
    • vgg16CAM_deploy.prototxt
    • VGG_ILSVRC_16_layers.caffemodel
    • VGG_ILSVRC_16_layers_deploy.prototxt

    We need these only to convert them into .npy format.

  5. Run extract function in utils.py with proper input arguments, this will convert .caffemodel to .npy. Now your caffe_pretrained/ folder should have these two extra files:

    • vgg16CAM_train_iter_90000.npy
    • VGG_ILSVRC_16_layers.npy

    Let me know if you don't want to install caffe but still need them.

Train

Train (fine-tune) CALTECH256 from VGG_ILSVRC_16_layers with default settings:

python main.py --train

Train (fine-tune) CALTECH256 from previous checkpoint:

python main.py --train --modelpath=log/vgg16CAM_calt256-X

Check out tunable arguments:

python main.py

Test

Test the model provided by the authors (trained on ImageNet)

python main.py --test --imgpath=/path/to/img.jpg

Test the model trained on CALTECH256 by you given epoch X

python main.py --test --imgpath=/path/to/img.jpg --modelpath=log/vgg16CAM_calt256-X

This will save a result figure in this directory.

Some results

guitar monkey baseball player

Others

  • First time training will generate calt256_224_224.tfrecords file to your CALTECH256/ folder to load data in queue.
  • Unfortunately training on CALTECH256 has not yet been successful/completed (super low accuracy). Please let me know if you can train the model with good result.
  • Testing from the ImageNet model works perfectly with the same architecture.
  • Issues are more than welcome!

Resources

class-activation-mapping's People

Contributors

markdtw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

class-activation-mapping's Issues

Attribute logits as undefined

I've been following your excellent example for creating a class activation map on a similar network (VGG16-Places365). However, there is a self.logits in the model definition that is undefined (

self.xen_loss_op = tf.losses.sparse_softmax_cross_entropy(labels, self.logits)
)

Would it be possible to update the vgg.py to reflect how logits are defined? It would be very helpful to researcher like myself who are interested in recreating the CAMs in the paper.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.