Giter Club home page Giter Club logo

keras2caffe's Introduction

Keras2Caffe

Keras to Caffe

This is a script that converts Keras models to Caffe models from the common Keras layers into caffe NetSpecs, and into prototext and caffemodel files. This allows you to pipe directly into your favorite Caffe framework of choice.

Be aware that Keras has much more flexible functionality and thus will miss lots of goodies such as Lambda functions, some acitvaiton functions, and some of the pooling, text preprocessing, recurrent, and noise layers. For those you can try your luck with custom python layers or custom c++ layers.

This is build with a very simple structure of parsing layer by layer, and the same goes for caffe weights.

Why

For anyone who needs to use Caffe for some reason. This was a script I wrote while at IBM Watson, in Spark.tc for Keras2DML to run Common pretrained keras models to run on large clusters. This was partly used to piggy back off Caffe2DML. Definitely recommend checking out SystemML if you want to train models on clusters and distributed machine learning concepts in general.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

What things you need to install the software and how to install them

sudo apt-get install caffe
pip install tensorflow keras

Eventually I will add Caffe.proto to generate files so you don't get bloated from the caffe dependency.

Installing

A step by step series of examples that tell you have to get a development env running

Import the script to use the functions

import keras2caffe

Things That Work and What Needs To

Currently the layers that work are:

  • Dense
  • Dropout
  • Add, Multiply, Maximum, and Concat
  • Conv2D, MaxPooling2D, Conv2DTranspose(Does not map anything that doesn't exist in Caffe, such as regulaizers, and intiallizers)
  • All activations in Caffe except Threshold, bias, and Scale
  • All Losses in Caffe, including both combined activation and loss layers

Things that I need to add

  • LSTM (Map as much as possible with keras parameters)
  • Crop, AveragePooling, and Embedding

If I missed anything, make sure to inform me so I can add it, or merge pull requests.

REMINDER: You can't get one to one models, so don't expect everything to work perfectly!

Authors

License

This project is licensed under the Apache License

Acknowledgments

  • Mike
  • Caffe for making it a game to find valid documentation for pycaffe

keras2caffe's People

Contributors

anoojpatel 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.