3

I'm brand new to Raspberry Pi and I'm not sure if the Pi Zero is sufficient for something I'm trying to do (I want to use Pi Zero since cost is my main concern). I've been searching through the forums, Stack, and other websites online, but I can't seem to find a definitive answer, which is what brings me to ask here!

Basically, I have a bird feeder that I would like to monitor using Raspberry Pi. What I want it to do is take 1 photo every 1 minute (or couple minutes), analyze that photo using a Tensorflow model, and if it detects a bird, an LED should light up. If it detects a squirrel or any other animal, nothing should happen (since the Tensorflow model doesn't detect squirrels anyway).

I don't want to do the image analysis on the cloud or on another place - I want to do it right on the Raspberry Pi Zero without needing any additional hardware or connections (except maybe an SD card for additional storage).

I have a Tensorflow model (200MB size file) for detecting a bird in an image. I know these microcomputers use Tensorflow Lite, so I'll be sure to use Tensorflow Lite.

I know that this is a simple and easy problem using one of the larger Raspberry Pi models, but cost is my main issue (because I plan to purchase many Pi's for similar uses). I saw that the Raspberry Pi Zero is $5, which is why I was thinking of using it! I haven't purchased any, so I'd like to know if it's capable of accomplishing this task.

I've read a bunch of things online about using the Zero for tasks similar to this (such as face detection), but I don't think any examples used Tensorflow Lite, so I don't know if the Zero can handle this goal.


So all-in-all, I just want to know if a Pi Zero would be able to run a Tensorflow Lite model on-board without additional hardware (except SD card and camera) and without the cloud. I don't need any fancy features, and I'm not looking to do something resource-intensive with it (such as analyzing videos or real-time computer vision); it just needs to be able to take a photo, process/analyze that 1 photo (using Tensorflow model... like YOLO) within 1 minute (or couple... performance isn't important), and light up an LED.

I'd greatly appreciate it if someone who actually has a Pi Zero tried it out, so that answers are not just speculations; I would, but I don't have one, unfortunately.

F16Falcon
  • 101
  • 1
  • 6
  • TBH I've never tried but you may like to have a read through https://www.pyimagesearch.com/2018/06/18/face-recognition-with-opencv-python-and-deep-learning/ that covers facial recognition on the Pi - it may give you some ideas. –  May 28 '20 at 19:52
  • @Andyroo Hi, thanks for the comment! I'll take a look through it, but just from scanning the article, it seems to be for real time analyzing a video stream. I'm looking to only classify pictures (like once per minute), which should take significantly less resources. So I'm wondering if it would take low enough resources that the Pi Zero can handle it. – F16Falcon May 28 '20 at 20:08
  • The pi can easily do that in terms of RAM and CPU power – Sim Son May 30 '20 at 09:25
  • @SimSon Hi Sim Son, I appreciate your comment. So I'm assuming this means my tensorflow models would work for my projects! Would you mind writing it as an answer? It answers my question so I'd like to +1 and mark as best! :) – F16Falcon May 30 '20 at 12:46
  • @SimSon Also, just to clarify, you are referring to the Pi Zero, right? Not just the more expensive and powerful models? – F16Falcon May 30 '20 at 13:20
  • Do ypu know how much RAM the processing will require? Do the entire 200MB need to be in RAM at once? Depending on the OS, the RPiZ's 500MB of RAM will probably be still sufficient. – Sim Son May 30 '20 at 20:35
  • @SimSon That's actually a great question, but I'm not exactly sure of the answer. I've been searching online and can't really seem to figure out how to estimate the RAM it takes to run my YOLO model. I tried checking using Python's psutil library and it said around 600MB total, but note that this is with my regular Tensorflow model. I'd assume Tensorflow Lite with a Tiny YOLO model would be less than this? – F16Falcon May 30 '20 at 21:14
  • The RPiZ is definitely more than powerful enough to perform the required task. The esp32 e.g. is way less powerful than the RPiZ (half a MB of RAM, few MB of flash), but even for this chip there is firmware that supports facial recognition. I just don't know how tensorflow works on Pi... – Sim Son May 30 '20 at 21:26
  • 1
    @Sim Son Hmm, maybe I don't even need Tensorflow in that case. Do you know of any libraries/tools that'll allow me to do custom object detection to detect things such as animals, people, cars, etc. without having to use Tensorflow on the RPiZ? Facial recognition libraries can help with people detection, but I'm interested in using custom models for custom objects (like animals) that I'll train on my computer and use my Pi to use that model to analyze single photos. – F16Falcon May 30 '20 at 22:33
  • Sorry, unfortunately I've no experience with machine learning. But from what I found on a quick google search, using tensorflow on a pi doesn't seem to be unusual. – Sim Son May 30 '20 at 22:48
  • I think this article may interest you... https://medium.com/@haraldfernengel/compiling-tensorflow-lite-for-a-raspberry-pi-786b1b98e646 It's running Tensorflow Lite on a Raspberry Pi Zero W to label images. – Martin Muelas Jun 02 '20 at 19:42
  • I believe the zero should work perfectly fine, as long as you keep it from overheating. It appears there is already a kit that does human face with tensorflow. Here is the link https://aiyprojects.withgoogle.com/vision/ It uses a zero so believe that your idea should work! :) – UNKNOWN May 31 '20 at 13:26
  • Interesting issue, personally I tried on Rpi3 and on live video (i achieved ~1fps), but I found and article, what maybe could help you to achieve this project: Animal Detecting project Another thing, what I read about it is the project "Yolo" what seems quite good with embed systems. Here is a link for rpi+yolo. – huncyrus Jun 04 '20 at 17:37

2 Answers2

2

I will try to explain things here. Pi zero has ARM V6. The binaries will work very badly with this CPU. The RAM is 512. With a lots of software and modification you may run it but the performance will be very very slow.ML is best to be practices in PI4.

Sohan Arafat
  • 1,828
  • 1
  • 10
  • 40
  • Hi Sohan Arafat, Thanks for your answer. I'm not particularly concerned with performance. After all, all I need to do is scan a single image (not a video) within like 1 minute (so yeah, it can be slow) using my Tensorflow model to detect if there is a bird or person or car or other object. It's fine if it works badly (as in slow), as long as it's possible. Have you tried this out? I've seen some videos/articles that claim to use Tensorflow using the Zero, but others say you can't run Tensorflow on it. Not quite sure which to believe! – F16Falcon May 31 '20 at 13:21
  • @F16Falcon Slow processing is not the main concern. Te problem is with compatibility. And I was not talking about a video piece . Scanning an image with ML is a very complicating process. But I said you can do it. If you have a Pi0 you should try it first. – Sohan Arafat May 31 '20 at 20:06
1

Yes it can - I tested this example on Pi3 A+ - once opencv/model is loaded image recognition takes ~1.5 seconds. I expect Pi Zero to do the same in ~10-20 seconds.

On pi zero you might have a problem with installing opencv - you want to use pip install opencv-contrib-python-headless not sure if the NN stuff might be in the contrib part. But expect it to compile opencv wheels, that takes forever (a full day). And needs 1Gbyte of swap. Someone mentioned taking the sd card initialized on Zero and booting it on Pi4 and run the pip install on pi4. Which hopefully compiles zero binaries with the speed of pi4.

cezar t
  • 11
  • 1