Code Monkey home page Code Monkey logo

datadrivenvision_samplecode's Introduction

###
This is an example of how to use a pretrained model to extract CNN features from images.
To begin this process, please download and install caffe, along with the typical python libraries numpy, sklearn, and scipy.
I recommend using virtualenv to manage the python environment.

Once caffe is installed, download the pretrained model you would like to use. In this example I will use the HybridCNN model introduced in the Places dataset paper. 
###

# model setup - this will have different names depending on the model you download. It could be deploy.prototxt or solver.prototxt
MODEL_FILE = '/home/gen/caffe/models/hybridCNN/hybridCNN_deploy_FC7.prototxt'

# pretrained network weights - this file will be called somthing.caffemodel
PRETRAINED = '/home/gen/caffe/models/hybridCNN/hybridCNN_iter_700000.caffemodel'

###

To extract features for images, use the sample code in create_features.py. Below is an example of command line execution to extract the HybridCNN fc7 layer feature for one test image.

The command line arguments for create_features.py allow the user to pass several images in for feature calculation. This may be desirable as loading the caffe network is usually the time consuming aspect. create_features.py contains an option on line 102 to use or not use the gpu. Executing this script for many files serially on a gpu is probably the fastest way to use it. You may also choose to use the Brown CS compute grid to parallelize feature extraction over hundreds of CPUs. Please ask about grid usage best practices if you have never used the grid before.

You are also encouraged to alter this code to extract features in a sliding window fashion or from a pre-determined region of interest. Note that this will be much slower than training a caffe network to identify regions of interest, however it might be more straightforward from a coding standpoint. 

###

~/DataDrivenVision_SampleCode $ ./create_features.py -i ~/scratch/test.png --feat_type hybridCNN --model_file /home/gen/caffe/models/hybridCNN/hybridCNN_deploy_FC7.prototxt --pretrained /home/gen/caffe/m
odels/hybridCNN/hybridCNN_iter_700000.caffemodel --layer_name fc7 --save_dir ~/scratch

datadrivenvision_samplecode's People

Contributors

ccai-course avatar

Watchers

James Cloos avatar

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.