# 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:

![](/files/-LvMRsTCgHF_dJIN3KLM)

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

![](/files/-LvMRsTGmfXtYwgG7hHP)

![](/files/-LvMRsTIpMM6lSSo0tuG)

### 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

![](/files/-LvMRsTKAbPc27CRYwqX)

* 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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://leonardoaraujosantos.gitbook.io/artificial-inteligence/machine_learning/deep_learning/deep_learning_libraries.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
