Deep Learning with Raspberry Pi Explored (Part 2) - Hackster.io

Deep Learning with Raspberry Pi Explored (Part 2) - Hackster.io - 图1

Hi! Please confirm your email address by clicking the link in the email we sent you. Haven’t received it? Resend confirmation email

Deep Learning with Raspberry Pi Explored (Part 2) - Hackster.io - 图2

×

1

Notifications

1

ProjectsProjectsNewsContestsEventsVideosWorkshopsLaunch

×

Embed the widget on your own site

Add the following snippet to your HTML:

[Deep Learning with Raspberry Pi Explored (Part 2) - Hackster.io - 图4

Deep Learning with Raspberry Pi Explored (Part 2) - Hackster.io - 图5

Read about deep learning XNOR networks on a Raspberry Pi 3 B+ with nice FPS.

Read up about this project on ](https://prod.hackster-cdn.online/assets/hackster_logo_text-21b76ddd8e1fdebbdc3634afac217796f9101e956c0107d58a3adbd35d16badd.png#alt=) “Deep Learning with Raspberry Pi Explored (Part 2)”)

Deep Learning with Raspberry Pi Explored (Part 2)

Tinus Treuzel

12 4,011

12

Deep Learning with Raspberry Pi Explored (Part 2) - Hackster.io - 图7

Tinus Treuzel

Published June 10, 2019

Deep Learning with Raspberry Pi Explored (Part 2)

Read about deep learning XNOR networks on a Raspberry Pi 3 B+ with nice FPS.

IntermediateProtip4,172

Deep Learning with Raspberry Pi Explored (Part 2) - Hackster.io - 图8

[

](https://www.hackster.io/workshops/particle-101)

Access the virtual, hands-on Particle 101 Workshop today for just $19.99!

Advertisement

Things used in this project

Hardware components

Deep Learning with Raspberry Pi Explored (Part 2) - Hackster.io - 图9

Raspberry Pi 3 Model B

×

1

Story

Last time I investigated deep learning networks on a Raspberry Pi. They didn’t perform very well. The main reason is that deep learning networks are very resource hungry. They need a lot of memory to store their weights and a lot of computer power.

Is there nothing we can do? Yes, there are some challenging ideas about running deep learning networks with a good FPS, even on a Raspberry.

Let’s go back to the basic, a neural node. They are at the very heart of any network.

Deep Learning with Raspberry Pi Explored (Part 2) - Hackster.io - 图10

Real-valued neural node

The output is the sum of all the inputs multiplied with all their corresponding weights. The ReLU is a so-called activation function. Even a relatively small and simple network as AlexNet has 60 million weights, consuming 0.5 Gbyte of memory. It needs roughly 727 MFLOPS to calculate the outcome of a single frame. No match for our Raspberry.

Strategies to improve the performance are based upon the idea to decrease the memory load. As a result, the calculation load will usually drop too.

The most simple method is replacing all double precision real numbers for 8-bit integers. TensorFlow Lite uses this technique for instance. The memory load of AlexNet becomes now 60 Mbyte which can be allocated in a Raspberry. At the same time, the network execution time is reduced by a factor of two, because multiplying floating points takes twice as much time as integers. However, the computational burden still stays substantial.

The second method is pruning. All inputs with negligible influence on the output are deleted. As expected, the more weights are pruned, the greater the overall error becomes. Below a graph.

Deep Learning with Raspberry Pi Explored (Part 2) - Hackster.io - 图11

Pruning the weights

The big problem with pruning is software implementation. All input-weight calculations are coded in for-loops. Now, the loop becomes gaped, open places where the input is pruned. In one way or another, this generates always conditional jumps, slowing down the execution. Not to speak about GPU acceleration. The architecture of the GPU is matrix optimized, badly capable of branching. Also not the solution for a Raspberry.

There are many other similar techniques, all trying to reduce the number of weights. Some better than others. However, they all are not capable of reducing the execution time significantly because they all use time-consuming multiplications.

A complete other approach is the replacement of the weights by a single bit, giving you a binary neural network (BNN). Below a picture of such an element.

Deep Learning with Raspberry Pi Explored (Part 2) - Hackster.io - 图12

Binary neural node

Now only the sign of the weight is used. If the initial weight was greater than 0 it becomes +1, otherwise -1. Looking at the calculation, all multiplications are now replaced by adds and subs. And these are far less time-consuming.

A logic step further is also the replacement of all inputs with a single bit. It seems at first glance a very radical method with dubious results. However, it appears to perform reasonably well with just a little less accuracy.

The multiplications are now replaced by simple logic XNOR operator. Below the truth table of an XNOR.

Deep Learning with Raspberry Pi Explored (Part 2) - Hackster.io - 图13

XNOR operation

When the -1 are represented by zeros in the software, the multiplication works correctly. Hence the name of the network, an XNOR network.

A simple XOR on the 64-bit Raspberry gives you now 64 multiplications in a single instruction. That speeds things up!

Below an overview of the three types.

Deep Learning with Raspberry Pi Explored (Part 2) - Hackster.io - 图14

Overview neural types

The XNOR operation between an input and its weights results in a binary number. The sum of all 1’s in this number forms the output. In the end, some threshold is applied to get the new binary input for the next layer.

Deep Learning with Raspberry Pi Explored (Part 2) - Hackster.io - 图15

XNOR multiplications at work

This XNOR technique is very promising. It gives good results with nice FPS even on a Raspberry Pi.

Much more information about this topic and initial software can be found here: https://qengineering.eu/deep-learning-with-fpga-aka-bnn.html

See also part 1 on Hackster.io: https://www.hackster.io/tinus-treuzel/deep-learning-with-raspberry-pi-explored-5fa573

This time the picture above is the Rainbow flat in Hong Kong (22° 20’ 6’’ N, 114° 12’ 24’’ E). It just looks like a floorplan of an FPGA with its LUTs and L2 cache in the middle.

Enjoy!

Read more)

Credits

Deep Learning with Raspberry Pi Explored (Part 2) - Hackster.io - 图16

Tinus Treuzel

3 projects • 14 followers

First µP was the 8080 back in the 80’s. Now many years later I’m an expert on embedded vision, FPGAs, VHDL, C++, Math, Deep learning etc.

Follow ContactContact

Comments

Please confirm your email before commenting. Haven’t received a confirmation email? Resend. Contact us at help@hackster.io for help.

Deep Learning with Raspberry Pi Explored (Part 2) - Hackster.io - 图17

user515604

3 months ago

;)

  • Report

Many Thanks, very useful article.

[

Deep Learning with Raspberry Pi Explored (Part 2) - Hackster.io - 图18

](https://www.hackster.io/workshops/particle-101)

Access the virtual, hands-on Particle 101 Workshop today for just $19.99!

Advertisement

Related channels and tags

Related projects

[

Deep Learning with Raspberry Pi Explored (Part 2) - Hackster.io - 图22

](/tinus-treuzel/deep-learning-with-raspberry-pi-explored-5fa573)Deep Learning with Raspberry Pi Explored

[

](/arun-gandhi/object-detection-using-deep-learning-on-a-raspberry-pi-32f94c)Object Detection Using Deep Learning on a Raspberry Pi

[

Deep Learning with Raspberry Pi Explored (Part 2) - Hackster.io - 图23

](/absoluteAbu/object-detection-raspberry-pi-machine-learning-50b194)Object Detection | Raspberry Pi | Machine Learning

[

Deep Learning with Raspberry Pi Explored (Part 2) - Hackster.io - 图24

](/idreams/control-gpio-and-pi-camera-using-raspberry-pi-telegram-app-3a776a)Control GPIO and Pi Camera using Raspberry Pi + Telegram App

[

Deep Learning with Raspberry Pi Explored (Part 2) - Hackster.io - 图25

](/sushree-subhasmita-jena/live-cam-with-raspberry-pi-e9f43d)Live Cam with Raspberry Pi

View more related projects

Similar projects you might like

[

Deep Learning with Raspberry Pi Explored (Part 2) - Hackster.io - 图26

Stream your Pi Cam outside your home network without port forwarding. This tutorial is beginner friendly.

](/fabolandry/raspberry-pi-ip-cam-aws-and-hls-streaming-b449e7)

Raspberry Pi IP Cam AWS and HLS Streaming

Fritz FABO

294.9K

[

Deep Learning with Raspberry Pi Explored (Part 2) - Hackster.io - 图27

Use a Raspberry Pi to make your “dumb” car smarter!

](/tinkernut/raspberry-pi-smart-car-8641ca)

Raspberry Pi Smart Car

Tinkernut

9449K

[

Deep Learning with Raspberry Pi Explored (Part 2) - Hackster.io - 图28

Implement camera image recognition using deep learning on Raspberry Pi Zero W and VisionBonnet (from Google AIY Vision Kit).

](/yoshihiro-ochi/raspberry-pi-zero-w-visionbonnet-image-classification-d30d85)

Raspberry Pi Zero W + VisionBonnet | Image Classification

Yoshihiro Ochi

92.1K

[

Deep Learning with Raspberry Pi Explored (Part 2) - Hackster.io - 图29

Walkthrough of setting up a Raspberry Pi 3b+ for using a Tensorflow model to do image classification from PiCam captures.

](/Ladvien/install-tensorflow-and-opencv-on-raspberry-pi-f9ed2f)

Install Tensorflow and OpenCV on Raspberry Pi

Ladvien

111.5K

[

A basic guide teaching you how to set up a dual cooling fan and thermal tape on your Raspberry Pi for increased cooling and performance.

](/infoelectorials/pi-project-001-raspberry-pi-dual-fan-thermal-tape-setup-f064ca)

Pi Project 001: Raspberry Pi Dual Fan & Thermal Tape Setup

Electorials Electronics

4993

[

A camera that describes your pictures to you instead of just showing them.

](/cchannon/raspberry-pi-smart-camera-a8c786)

Raspberry Pi Smart Camera

Charles Channon

4810K

[

This project shows how to build a professional looking Access Point with a Raspberry Pi.

](/pi-supply/raspberry-pi-access-point-with-papirus-and-pi-poe-226576)

Raspberry Pi Access Point With PaPiRus And Pi PoE

Francesco Vannini

153.7K

[

An HTML5 and NodeJS photobooth with live preview and custom borders.

](/raymond-jones/raspberry-pi-photobooth-html5-and-nodejs-476ea1)

Raspberry Pi PhotoBooth - HTML5 and NodeJS

Raymond Lewis Jones

232.5K

12

  • More cool stuff

Welcome to Hackster!Be sure to follow us to stay up to date with the latest news & projects.