Fork me on GitHub

Java meets Caffe, deep learning in perspective

March 14, 2015

My main field of expertise being basically computer vision, there I see something like JavaCPP playing an important role. Apart from my own efforts with JavaCV, recently I became aware of similar sentiments in the field of deep learning, which has been gaining tremendously in popularity over the past few years. Namely, Yann LeCun, one of the gurus of deep learning, has made surprisingly relevant comments last year about their own efforts:

(At Facebook) We are using Torch7 for many projects (as does Deep Mind and several groups at Google) and will be contributing to the public version.

Torch is a numerical/scientific computing extension of LuaJIT with an ML/neural net library on top.

The huge advantage of LuaJIT over Python is that it way, way faster, leaner, simpler, and that interfacing C/C++/CUDA code to it is incredibly easy and fast.

Yann LeCun’s answers from the Reddit AMA

In other words, he admits that they would probably be using Python if the runtime were faster and could easily interface with native functionality, the lack of which are reason enough to justify taking some distance from the more vibrant communities evolving around NumPy, SciPy, and Theano. Java already has performance and simplicity on its side, and even leanness with implementations like Avian sporting a footprint of less than 1 MB, but easy and fast access to native functionality never materialized — until JavaCPP became reality. Lua can interface directly with C only, but we have a better solution here that can even use C++ template libraries for CUDA, such as Thrust, all that without writing a single line of C++: Interface Thrust and CUDA with JavaCPP. To illustrate my point and demonstrate the potential of our approach, I created Java bindings for Caffe, one of the most popular deep learning frameworks, that also happens to feature a complicated C++ API. Nevertheless, it took only a weekend’s time to create an almost complete interface, now available on GitHub as JavaCPP Presets for Caffe. At the time of this writing, we are not aware of any other existing Java wrappers, not even partial, for Caffe.

Now, for someone working in this kind of field, what else is missing from Java to become an attractive alternative to Python or Lua? An interactive command line interface would be one of those things. Even though languages such as Groovy or Scala already have REPL on top of the JVM, it might become a standard feature of the JDK itself as soon as Java 9 with JEP 222: Java Read-Eval-Print Loop (REPL). The only other important missing piece seems to be extensive library support for image processing, statistics, operations on matrices, data visualization, etc. We ourselves are attempting to provide some of these APIs by taping into available native libraries via the JavaCPP Presets, but given the recent interest expressed by the industry for deep learning, where Java is king, popular frameworks such as Deeplearning4j have already emerged, in a renewed quest to fill those gaps in Java.

That said, we hope the tools offered here can help you succeed in your own endeavors, deep learning or not. We would very much like to hear what you have to say, so do not hesitate to leave a comment. Moreover, if there is anything you need that is not currently available and would like to have a more private discussion, please contact us by email. This will also help us considerably in better orienting our future goals. Thank you very much for your time!


To add a comment, please edit the comments file and send a pull request!