# Deep Learning Libraries

## Introduction

Discussion, and some examples on the most common deep learning libraries:

* Caffe
* Torch
* TensorFlow
* Theano
* CNTK

## Caffe

One of the most basic characteristic of caffe is that is easy to train simple non recurrent models.

Most cool features:

* Good Performance, allows training with multiple GPUs
* Implementation for CPU and GPU
* Source code is easy to read&#x20;
* Allow layer definition in Python
* Has bidings for Python and Matlab
* Allows network definition with text language (No need to write code)
* Fast dataset access through LMDB
* Allows network vizualization
* Has web interface (Digits)

### Caffe Main classes:

![](https://2109831662-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LvMRntv-nKvtl7WOpCz%2F-LvMRp9FltcwEeVxPYFs%2F-LvMRsTCgHF_dJIN3KLM%2FCaffeOverview.jpg?generation=1575572719014693\&alt=media)

* Blob: Used to store data and diffs(Derivatives)
* Layer: Some operation that transform a bottom blob(input) to top blobs(outputs)
* Net: Set of connected layers
* Solver: Call Net forward and backward propagation, update weights using gradient methods (Gradient descent, SGD, adagrad, etc...)

### Caffe training/validation files

path/to/image/1.jpg \[label]

### Simple example

Here a logistic regression classifier. Imagine as a neural network with one layer and a sigmoid (cross-entropy softmax) non-linearity.

![](https://2109831662-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LvMRntv-nKvtl7WOpCz%2F-LvMRp9FltcwEeVxPYFs%2F-LvMRsTGmfXtYwgG7hHP%2FCaffe_Logistic.jpg?generation=1575572719398642\&alt=media)

![](https://2109831662-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LvMRntv-nKvtl7WOpCz%2F-LvMRp9FltcwEeVxPYFs%2F-LvMRsTIpMM6lSSo0tuG%2FCaffe_Proto_Logistic.jpg?generation=1575572720131419\&alt=media)

### Caffe Cons

* Need to write C++ / Cuda code for new layers
* Bad to write protofiles for big networks (Resnet, googlenet)
* Bad to experience new architectures (Mainstream version does not support Fast RCNN)

## Torch

Really good for research, the problem is that use a new language called Lua.

### Torch Pros

* Flexible
* Very easy source code&#x20;
* Easy biding with C/C++
* Web interface (Digits)

### Torch Cons

* New language Lua
* Difficult to load data from directories
* No Matlab bidings
* Less Plug and play than caffe
* Not easy for RNN

## Theano

### Theano Cons

* More manual
* No matlab biding
* Slower than other frameworks
* No much pre-trained models

## Tensorflow

### Tensorflow Pros

* Flexible
* Good for RNN
* Allow distributed training
* Tensorboard for signal visualization&#x20;
* Python Numpy

### Tensorflow Cons

* Not much pre-trained models
* No Support for new object detection features (Ex Roi pooling)
* No support for datasets like Caffe
* Slower than Caffe for single GPU training

## CNTK

### CNTK Pros

* Flexible
* Good for RNN
* Allows distributed training

### CNTK Cons

* No visualization
* Any error CNTK crash
* No simple source code to read
* New language (ndl) to describe networks
* No current matlab or python bindings

## Summary

* For research use Torch or Tensorflow (Last option Theano)
* For training convnets or use pre-trained models use Caffe

### CS231n Deep learning course summary

![](https://2109831662-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LvMRntv-nKvtl7WOpCz%2F-LvMRp9FltcwEeVxPYFs%2F-LvMRsTKAbPc27CRYwqX%2FDeepLibrariesOverview.jpg?generation=1575572713737001\&alt=media)

* Get features from known model (Alexnet, Googlenet, Vgg): Use caffe
* Fine tune known models (Alexnet, Googlenet, Vgg): Use Caffe
* Image Captioning: Torch or Tensorflow
* Segmentation: Caffe, Torch
* Object Detection: Caffe with python layers, Torch (More work)
* Language Modelling: Torch, Theano
* Implement Bath Norm: Torch, Theano or Tensorflow

Normally Tensorflow can be used in all cased that torch can, but if you need to understand what a specific layer does, or if you need to create a new layer, use torch instead of tensorflow. Torch is preferable on those cases, because the layer source code is more easy to read in torch.

## Next Chapter

On the next chapter we will discuss Distributed Learning
