- 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
- 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
The model aims to solve the German Traffic Signs Dataset, which contains 50000 images of 43 different categories.
To download the dataset I used this library. Just type:
dataget get german-traffic-signs
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.
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%
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.
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.
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=
.