Low power('ish) AIoT smart camera (3D printed) based on the Raspberry Pi Zero W and Google Coral EdgeTPU
People ask me the reason I chose to use the Raspberry Pi Zero for this project considering it's not a powerful single-board computer. I could have tried ready-made smart cameras, but the Raspberry Pi is one of the best selling general purpose computers ever (beating the Commodore 64, numbers from 4 years ago!), therefore it has a huge community. This makes life much easier when you need to find a driver or how to solve a problem. In addition to that, last year I released my work on a flexible, collision resilient, quadcopter that has as its brain... a Raspberry Pi Zero W! So, I'm quite familiar working with the Zero and I hope the Raspberry Pi Foundation will soon come up with an upgrade (maybe adding a RP2040 to the RPI Zero PCB?).
The edgetpu runtime version installed in the RPI image is 13, therefore you need to pass -m 13
to the edgetpu_compiler. The notebooks in this repo are updated, but if you need to compile a different model:
edgetpu_compiler -m 13 -s model.tflite
The models compiled using the example notebooks that use the Model Maker will ONLY work with this script: model_maker_object_detection_from_cam.py
The TL;DR; reason is: the order of the tensors in the output changed, and the pycoral version in the Maple Syrup Pi Camera image has those indices hardcoded.
- Raspberry Pi Zero W
- Raspberry Pi Camera ( + RPI Zero flat cable)
- Coral USB Accelerator
- USB-C to micro USB cable (or adapter)
- Micro SDCard (if you want to use our image it's recommended 8GB)
- 3D printed parts
- Download the image available here and flash it to your card using the Raspberry Pi Imager.
- The image available in this repo has lots of interesting stuff pre-installed and its default user is
pi
and passwordmaplesyrup
(yup, I love maplesyrup). - Another interesting thing available is the Jupyter Notebook Server. It helps a lot while testing things. You can launch it by running
/home/pi/launch_jupyter.sh
(it's slow at times, but very much usable) and the password is againmaplesyrup
(your browser will complain saying it's not a secure connection because the server is using a self-signed certificate).
- You will, at least, need to install the libedgetpu and tflite_runtime. Be aware this tflite_runtime version was compiled for Python 3.7.
- In addition to the software above, you will need to install Picamera, Pillow...
- The USB connector is used by the Coral USB Accelerator, therefore it's easier if you use the Maple-Syrup-Pi-Camera headless. A full example of wifi configuration file is available here (you just need to modify it and copy to the boot partition that appears when you connect the SDCard to your computer).
- The image comes with SSH enabled and you can learn more about how to connect using SSH here.
- If you are a Unix user, you can even mount the RPI filesystem on your computer and use VSCode remotely.
- MultiPose
- Automatic License Plate Recognition
- Face Mask Detection (Mask, No Mask, Poor Mask)
- Examples already installed in the SDCard image
- Train your own Object Detector using TFLite Model Maker:
The RPI Zero W has a USB 2.0 connection with a theoretical 480Mbit/s (50MB/s) speed, but it will never get close to that because the RPI0 has a single core ARMv6 CPU (no free lunch!). Therefore, the Google Coral USB Accelerator is very often limited by the USB bandwidth, or the ability of RPI0 to exchange data with it. This fact plays a role in keeping the average power consumption low, though. Models that need post-processing or use a custom OP (the EdgeTPU compiler runs these ops in the host) will also suffer from the small USB bandwidth and the weak ARMv6 single core.
The RPI Zero W has no protection circuit on its 5V input, therefore it connects the USB power directly to the power supply. That means the Coral USB Accelerator will be directly connected to the power supply allowing it to drain as much current as the power supply and impedance of microUSB + PCB traces allow it. According to the Google Coral USB Accelerator Datasheet, the accelerator alone could draw up to 900mA (peak). The RPI Zero W has a typical power consumption of 150mA. In my experiments, the Maple-Syrup-Pi-Camera consumes around 160mA at 5V when idle (800mW).
- Since the speed is limited by other factors than the Coral USB accelerator, it's possible to save energy by using the throttled version of the libedgetpu.
Using a hobby-grade USB power meter (and a power bank that states it can deliver up to 2A at 5V):
- MultiPose shows peaks of 350mA at 5V (1.75W)
- Automatic License Plate Recognition shows peaks of 400mA at 5V (2W)
- Face Mask Detection (Mask, No Mask, Poor Mask) shows peaks of 420mA at 5V (2.1W)
The power consumption is kept low, compared to other products using the EdgeTPU, mainly because the RPI Zero is very low power and the Coral USB accelerator usually sits idle awaiting for data.
- 3D parts adapted from https://www.thingiverse.com/thing:2254307
- Instructions on how to create RPI images using docker
- Some models and project examples are from https://coral.ai/examples/ and https://github.com/google-coral/pycoral
- SDCard image adapted from the collision resilient quadcopter CogniFly.
- Life is just much easier thanks to Netron
- Don't expose it directly to the world-WILD-web (aka "the internet") without a good firewall. Some suggestions:
- Use it at your own risk and, please, don't be evil ;)
- RPI0_GPU_FFT: Experiments using the RPI Zero GPU for FFT/IFFT 1D/2D.
- colab_utils: Some useful (or not so much) Python stuff for Google Colab notebooks.
- ExecThatCell: (Re)Execute a Jupyter (colab) notebook cell programmatically by searching for its label.
- The CogniFly Project: Open-source autonomous flying robots robust to collisions and smart enough to do something interesting!
- Bee: The Bee simulator is an open source Spiking Neural Network (SNN) simulator, freely available, specialised in Liquid State Machine (LSM) systems with its core functions fully implemented in C.