Skip to content

charlielito/convnets-on-raspberry-tensorflow

Repository files navigation

Running convents in a Raspberry 3

Requirements

  • Latest version of Raspbian Jessie Lite
  • Python 2.7+
  • Official Tensorflow 1.1.0 for Raspberry compatible from this repository. Short version, just run:
# For Python 2.7
wget https://github.com/samjabrahams/tensorflow-on-raspberry-pi/releases/download/v1.1.0/tensorflow-1.1.0-cp27-none-linux_armv7l.whl
sudo pip install tensorflow-1.1.0-cp27-none-linux_armv7l.whl

Python Requirements

  • Pillow
  • numpy
  • pandas
  • dataget
  • tfinterface
  • juypter, matplotlib (optional for visualization)

Pillow needs some external libraries to run (install) properly. Install them before running pillow:

sudo apt-get install libjpeg8-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev libharfbuzz-dev libfribidi-dev tcl8.6-dev tk8.6-dev python-tk

Then you can run:

sudo pip install -r requirements.txt

Note: If you had memory problems (aka MemoryError) installing matplotlib, try it with

sudo pip --no-cache-dir install matplotlib

Dataset

The model aims to solve the German Traffic Signs Dataset, which contains 50000 images of 43 different categories.

alt text alt text alt text alt text alt text alt text alt text alt text alt text

To download the dataset I used this library. Just type:

dataget get german-traffic-signs

Model and training

A convolutional neural network was used with the following architecture:

  • Inputs: 3 filters (32x32 RGB)
  • Convolutional layer: 16 filters, kernel 5x5, padding 'same', ELU activation
  • Convolutional layer: 32 filters, kernel 5x5, padding 'same', ELU activation
  • Max Pool: kernel 2x2, stride 2
  • Convolutional layer: 64 filters, kernel 3x3, padding 'same', ELU activation
  • Max Pool: kernel 2x2, stride 2
  • Convolutional layer: 64 filters, kernel 3x3, padding 'same', ELU activation
  • Flatten vector
  • Fully connected: 256 neurons, ELU activation, dropout = 0.15
  • Fully connected: 128 neurons, ELU activation
  • Dense layer for output: 43 neurons, Softmax activation

The model only has 1,156,747 parameters. That is approx. 13 Mb.

Training

The training of the model was accomplished in the cloud using FloydHub. This repo contains the procedure to train the model using tensorflow and tfinterface that helps building and training the model.

The accuracy of the model is 95,32%

Runing the model and Making Inference

The model from the previous section was saved and located in the subfolder models. From there tensorflow reads the weights of the network. You can test it by runnning the following:

python main.py -i path_to_image

It will load the image given (if any, otherwise it charges a default image from ./test folder), and it will predict the class of the image and report the time consumed in this task.

Time of inference

The time that takes to classify one image on the Raspberry pi 3 is approximately 0.06 seconds, almost in real time, quite good! In comparison with an Asus Core i7, in the raspberry it runs almost 10x slower.

Running interctive with Jupyter

If you want to use jupyter to interact with the model, use:

jupyter notebook --ip=0.0.0.0 .

To access the Web Interface you need to know your Raspberry's IP Address (with ifconfig you can scan it). For example, in your browser access to http://192.168.1.110:8888/?token=f493e32b58b6e1b5a7f30ad2bad8e7e8a48997619af512f0. It will ask you for the token, in that case the token is what follows ?token=.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors