Coder Social home page Coder Social logo

caffe2keras's Introduction

I don't use Caffe or Keras any longer and am not planning to update this code. @ysh329 has compiled a fantastic list of alternative software that you can use instead. Happy converting! 😄





































Caffe to Keras converter

Note: This converter has been adapted from code in Marc Bolaños fork of Caffe. See acks for code provenance.

This is intended to serve as a conversion module for Caffe models to Keras models. It only works with Ye Olde Caffe Classic™ (which isn't really a thing, but which probably should be a thing to prevent confusion with the Caffe 2).

Please be aware that this module is not regularly maintained. Thus, some layers or parameter definitions introduced in newer versions of either Keras or Caffe might not be compatible with the converter. Pull requests welcome!

Conversion

In order to convert a model you just need the .caffemodel weights and the .prototxt deploy file. You will need to include the input image dimensions as a header to the .prototxt network structure, preferably as an Input layer:

layer {
  name: "image"
  type: "Input"
  top: "image"
  input_param {shape {dim: 1, dim: 3, dim: 128, dim: 128}}
}

Given the differences between Caffe and Keras when applying the max pooling operation, in some occasions the max pooling layers must include a pad: 1 value even if they did not include them in their original .prototxt.

The module caffe2keras can be used as a command line interface for converting any model the following way:

python -m caffe2keras models/train_val_for_keras.prototxt models/bvlc_googlenet.caffemodel keras-output-model.h5

To use the produced model from Keras, simply load the output file (i.e. keras-output-model.h5) using keras.models.load_model.

Acknowledgments

This code is yet another iteration of a tool which many people have contributed to. Previous authors:

caffe2keras's People

Contributors

alsrgv avatar gueguenster avatar qxcv avatar thepaulm avatar

Watchers

 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.