GithubHelp home page GithubHelp logo

bentengma / netdissect Goto Github PK

View Code? Open in Web Editor NEW

This project forked from csailvision/netdissect

0.0 1.0 0.0 1.26 MB

Network Dissection http://netdissect.csail.mit.edu for quantifying interpretability of deep CNNs.

License: MIT License

MATLAB 5.56% Shell 8.34% Python 86.10%

netdissect's Introduction

Network Dissection

News (Jan.18, 2018)!

We release a light and portable version of Network Dissection in pyTorch at NetDissect-Lite. It is much faster than this first version and the code structure is cleaned up, without any complex shell commands. It takes about 30 min for a resnet18 model and 2 hours for a densenet161. If you have questions, please open issues at NetDissect-Lite

Introduction

This repository contains the demo code for the CVPR'17 paper Network Dissection: Quantifying Interpretability of Deep Visual Representations. You can use this code with naive Caffe, with matcaffe and pycaffe compiled. We also provide a PyTorch wrapper to apply NetDissect to probe networks in PyTorch format. There are dissection results for several networks at the project page.

This code includes

  • Code to run network dissection on an arbitrary deep convolutional neural network provided as a Caffe deploy.prototxt and .caffemodel. The script rundissect.sh runs all the needed phases.

  • Code to create the merged Broden dataset from constituent datasets ADE, PASCAL, PASCAL Parts, PASCAL Context, OpenSurfaces, and DTD. The script makebroden.sh runs all the needed steps.

Download

  • Clone the code of Network Dissection from github
    https://github.com/CSAILVision/NetDissect.git
    cd NetDissect
  • Download the Broden dataset (~1GB space) and the example pretrained models.
    script/dlbroden_227.sh
    script/dlzoo_example.sh

Note that you can run script/dlbroden.sh to download Broden dataset with images in all three resolution (227x227,224x224,384x384), or run script/dlzoo.sh to download more CNN models. AlexNet models work with 227x227 image input, while VGG, ResNet, GoogLeNet works with 224x224 image input.

Run in Caffe

  • Run Network Dissection in Caffe to probe the conv5 layer of the AlexNet trained on Places365. Results will be saved to dissection/caffe_reference_model_places365/, in which html contains the visualization of all the units in a html page and conv5-result.csv contains the raw predicted labels for each unit. The code takes about 40 mintues to run, and it will generate about 1.5GB intermediate results (mmap) for one layer, which you could delete after the code finishes running.
    script/rundissect.sh --model caffe_reference_places365 --layers "conv5" --dataset dataset/broden1_227 --resolution 227
  • Run Network Dissection to compare three layers of AlexNet trained on ImageNet. Results will be saved to dissection/caffe_reference_model_imagenet/.
    script/rundissect.sh --model caffe_reference_imagenet --layers "conv3 conv4 conv5" --dataset dataset/broden1_227 --resolution 227
  • If you need to regenerate the Broden dataset from scratch, you can run script/makebroden.sh. The script will download the pieces and merge them.

  • Network dissection depends on scipy as well as pycaffe. Details on installing pycaffe can be found here.

Run in PyTorch

    script/rundissect_pytorch.sh
  • Or try script/rundissect_pytorch_external.sh on a resnet18 trained on Places365.
    script/rundissect_pytorch_external.sh

Report

  • At the end of the dissection script, a report will be generated that summarizes the semantics of the networks. For example, after you have tested the conv5 layer of caffe_reference_places365, you will have:
    dissection/caffe_reference_places365/html/conv5.html
    dissection/caffe_reference_places365/html/image/conv5-bargraph.svg
    dissection/caffe_reference_places365/html/image/conv5-0[###].png    
    dissection/caffe_reference_places365/conv5-result.csv

These are, respectively, the HTML-formatted report, the semantics of the units of the layer summarized as a bar graph, visualizations of all the units of the layer (using zero-indexed unit numbers), and a CSV file containing raw scores of the top matching semantic concepts in each category for each unit of the layer.

  • Dissect results of all the existing networks in mat format. After the csv file containing the raw data of the unit semantics is generated, you could use the sample scripts in plot/extract_csv.m to plot the figure. plot/semantics_cvpr_release.mat contains the semantics of all the networks analyzed in the CVPR paper. It will generate a figure showing the number of unique detectors across different networks.

Reference

If you find the codes useful, please cite this paper

@inproceedings{netdissect2017,
  title={Network Dissection: Quantifying Interpretability of Deep Visual Representations},
  author={Bau, David and Zhou, Bolei and Khosla, Aditya and Oliva, Aude and Torralba, Antonio},
  booktitle={Computer Vision and Pattern Recognition},
  year={2017}
}

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.