Giter Site home page Giter Site logo

anirband / cnn_finetune Goto Github PK

View Code? Open in Web Editor NEW

This project forked from flyyufelix/cnn_finetune

0.0 2.0 0.0 36 KB

Fine-tune CNN in Keras

Home Page: https://flyyufelix.github.io/2016/10/08/fine-tuning-in-keras-part2.html

License: MIT License

Python 100.00%

cnn_finetune's Introduction

Fine-tune Convolutional Neural Network in Keras with ImageNet Pretrained Models

The reason to create this repo is that there are not many online resources that provide sample codes for performing fine-tuning, and that there is not a centralized place where we can easily download ImageNet pretrained models for common ConvNet architectures such as VGG, Inception, ResNet, and DenseNet. This repo serves to fill this gap by providing working examples of fine-tuning on Cifar10 dataset with ImageNet pretrained models on popular ConvNet implementations.

See this for a comprehensive treatment of fine-tuning Deep Learning Models in Keras

Usage

For illustration purpose, let's say you want to perform fine-tuning with VGG-16. First, download the ImageNet pretrained weights for VGG-16 to the imagenet_models directory. The schema and sample code for fine-tuning on Cifar10 can be found in vgg16.py. Run the file:

python vgg16.py

The code will automatically download Cifar10 dataset and performs fine-tuning with VGG-16. Please be aware that it might take some time (up to minutes) for the model to compile and load the ImageNet weights.

Finetune with your own dataset

If you wish to perform fine-tuning on your own dataset, you have to replace the module which loads the Cifar10 dataset with your own load_data() module to load your own dataset.

X_train, Y_train, X_valid, Y_valid = load_data()

In particular, the following image preprocessing step have to be performed to get the format of the dataset compatible with the pretrained models:

# For Tensorflow 
# Switch RGB to BGR order 
x = x[:, :, :, ::-1]  

# Subtract ImageNet mean pixel 
x[:, :, :, 0] -= 103.939
x[:, :, :, 1] -= 116.779
x[:, :, :, 2] -= 123.68

# For Theano
# Switch RGB to BGR order 
x = x[:, ::-1, :, :]

# Subtract ImageNet mean pixel 
x[:, 0, :, :] -= 103.939
x[:, 1, :, :] -= 116.779
x[:, 2, :, :] -= 123.68

ImageNet Pretrained Models

Network Theano Tensorflow
VGG-16 model (553 MB) -
VGG-19 model (575 MB) -
GoogLeNet (Inception-V1) model (54 MB) -
Inception-V3 model (95 MB) -
Inception-V4 model (172 MB) model (172 MB)
ResNet-50 model (103 MB) model (103 MB)
ResNet-101 model (179 MB) model (179 MB)
ResNet-152 model (243 MB) model (243 MB)
DenseNet-121 model (32 MB) model (32 MB)
DenseNet-169 model (56 MB) model (56 MB)
DenseNet-161 model (112 MB) model (112 MB)

Requirements

  • Keras 1.2.2 2.0.5
  • Theano 0.8.2 or TensorFlow 0.12.0 1.2.1

Updates

  • Keras 2.0.5 and TensorFlow 1.2.1 are supported

cnn_finetune's People

Contributors

flyyufelix avatar

Watchers

James Cloos avatar Ani 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.