ไม่สามารถเล่นวิดีโอนี้
ขออภัยในความไม่สะดวก
Introduction to object detection on Raspberry Pi
ฝัง
- เผยแพร่เมื่อ 14 ส.ค. 2024
- In the first episode of Machine Learning for Raspberry Pi, learn how to download a pre-trained TensorFlow Lite object detection model and deploy it to your Raspberry Pi. This model can be used to recognize general objects such as an apple, a television, or a car.
00:00 Welcome to the Machine Learning for Raspberry Pi
00:12 What you’ll learn in this series
1:14 Get started running object detection
1:35 Download the latest version of Raspberry Pi OS (link below)
2:29 Connect a camera to Raspberry Pi
3:12 Setting up Raspberry Pi
3:42 Create a Python virtual environment
4:30 Clone the TensorFlow examples
5:18 Run python detect.py to see what the model can detect!
5:45 Specific objects and faster speeds
6:16 A closer look at the code
9:34 What’s next
Download Raspberry Pi OS → goo.gle/raspbe...
Gist to setup your Raspberry Pi environment → goo.gle/3GdeQvz
GitHub repository containing the sample code → goo.gle/3GaABw3
Train a custom object detection model using your data → goo.gle/31qq4yg
Choose an object detection model architecture for Raspberry Pi → goo.gle/3lDe9DO
Make object detection run faster by using Coral → goo.gle/3EuH3xn
Watch all Machine Learning for Raspberry Pi videos → goo.gle/ML-ras...
Subscribe to TensorFlow → goo.gle/Tensor...
#TensorFlow #MachineLearning #ML #RaspberryPi
product: TensorFlow - TensorFlow Lite, TensorFlow - General; fullname: Khanh LeViet;
Guys if you want to detect specific objects use category_name_allowlist=['cat', 'dog'] in processor.Detector Options.
Raspberry Pi is so useful. Thanks for this
I was able to install requirement.txt only with Python 3.7.12, but for the latest Pi OS which has Python 3.11.2 it's not working. Additional issue is that opencv not working with raspberry cameras so you actually can't realy test any of examples. One of proposed workaround to use picamera2 package (but unfortunatly, you cant install it in venv). Looking for the way to run object detection using latest version of python, opencv and TFlite... Any working axample would be highly appreciated!
I did this last year but I was running python 3.7.3/3.7.4, can I ask what version of OpenCV you installed and guide please? I'm trying to run this again but a year after I noticed RaspiOS has completely changed
Hi, I get this error when running detect.py
RuntimeError: module compiled against API version 0xf but this version of numpy is 0xe
Traceback (most recent call last):
File "/home/pi/examples/lite/examples/object_detection/raspberry_pi/detect.py", line 19, in
import cv2
File "/home/pi/.pyenv/versions/3.7.0/lib/python3.7/site-packages/cv2/__init__.py", line 8, in
from .cv2 import *
ImportError: numpy.core.multiarray failed to import
I have already tried upgrading opencv and numpy but they are latest version
same problem :(. I don't know how to fix this problem tried different solution
@@janecagas7380 Try to uninstall numpy by this command: "pip uninstall numpy " *and* install :"pip install numpy"
if it does not work watch the video again and follow the setup correctly
If anyone is having trouble setting up the label_allow_list thingy gor filtering out unwanted detections, you could try using category_label_allowlist instead
It's also not working can you help please🙏
0:11 tonight ko
0:28 to be there
@@Ajey23 I ended up using an if statement, if it was a person or type=='person', I count it, then else it won't do anything, I think I edited it on the model code or something
tried the example on raspberry pi 3,its breaking and displaying with error, "no attribute imageDataFree".What could be the problem
After I had the issue with Rasbian Bullseye and the new pi camera settings: Don't forget to enable Legacy Camera on your Raspberry! Otherwise, the example from this video won't work.
Could TF be trained to determine wnd speed based on tree/branch/leaf movement?
All went well until the final command which did not launch the camera.. Does not seem to working with latest Bullseye
I've tested it and it works. I am thrilled and have now also ordered the Coral USB hardware accelerator. But now I think about how I can adapt the code so that I can get the recognized objects and write them down. The goal is that the Pi announces to me what it has recognized via voice output. Does anyone have an idea.
You can check out a Python library called gTTS from Google to make the device speak out the detected objects.
gtts.readthedocs.io/en/latest/
Yes. You should spend more time to learn it ... It's looks, that you read/watch tutorial, use prepared/ready code, and try to do more .. But now You need to learn alone .. You have to delve into the topic .. because of what you wrote, you did it very superficially ..
@@PraiseTheLord527 hello, thanks for the question. That's fine. I've seen that before, but unfortunately I don't have a Google Coral Accelerator myself. was unfortunately not available.
One more thing. I also tried to test it with my Chromebook. Of course, I then get the error message regarding the camera ID. I'm not sure if it is a general problem to address a USB camera from the Linux container. There is obviously an open bug. But I might be wrong. If there is someone who has had success with a Chromebook and where there are instructions, I would be grateful for a hint.
Can it tell if an object is a hotdog or not hotdog?
I have tested. It working but the camera was delay about 2-3 sec. How to fix this problem? system is PI4 8GB, HD camera.
I am having a problem where the virtual machine is not being loaded it is saying that it needs the following arguments : ENV_DIR how do I fix it?
Did you forget to specify the path to create a virtual environment like in this case?
goo.gle/3skfxBr
Thank you for the information sir! Is it possible to run tensorflow object detection directly on a raspberry pi 3 without the TensorFlow lite?
Technically yes, but the performance will be much worse compared to running using TensorFlow Lite because TensorFlow is not designed for edge devices like the Raspberry Pi. We have a tutorial on converting TF Object Detection API models to TFLite. Check it out here: github.com/tensorflow/models/blob/master/research/object_detection/colab_tutorials/convert_odt_model_to_TFLite.ipynb
@@khanhleviet5416 thank you very much!
Nice✨
TensorFlow is ❤️🔥
The code isn't the same is you showed in the video so how can I detect specific objects with the new code? What you told us dosnt work with the new code ☹️
Looking forward to this series
What about the pico? That is supported right? Can't have a Pi 4 for every little project.
Can this machine learning model capable of detecting texture of an object?
Can we modify the code like the detected object are list or telling in headphones
I want to glow led when car is detected what will the changes?
Hi, I'm an engineering student and I have to build a beer bot pong. I've use your video for create my model and use it. I can not return the position of my object. i've read lots of article aboute bounding box but i can not use it. does anybody know how a can return contact details?
thanks in advance
Thank you very much
a ơi, cho e hỏi, e chạy đc camera của raspberry bình thường, nhưng chạy lệnh python detect.py nó báo lỗi : " Unable to read from webcam. Please verify you webcam settings" là sao ạ, e cần sửa gì ạ?
can u help meee? huu
It means OpenCV can't read from your camera. If you use a Pi camera, please make sure you've enabled it from Preferences > Raspberry Pi Configuration. If you have a USB camera, you can try connecting it to your Raspberry Pi and see if it works.
@@khanhleviet5416 yes, pi's camera is working fine. I used another model and it works, but using your model it gives such error
@@khanhleviet5416 I reinstalled Pi's OS and it worked, I'm very happy, your video is very good, thank you so muchhh
Thank you!
Which camera and connection type do you using for the raspberryPi ?
I have two setup options:
1. Use a Pi camera connected directly to the camera port on the RPi.
2. Use an USB camera connected to the RPi.
Both work with the same code I showed in the video.
@@khanhleviet5416 Thank you, friend!
I am getting this error
[ WARN:0] global /tmp/pip-wheel-hwcmjluw/opencv-python_dc56ddd000dd4893b1f852d88d4a5959/opencv/modules/videoio/src/cap_v4l.cpp (890) open VIDEOIO(V4L2:/dev/video0): can't open camera by index. Using bullseye OS on a pi4 model b with a high quality pi cam
I had this same issue, try snapping a test image by issuing: raspistill -o test.jpg . Also make sure that your camera is enabled under interfaces in Raspberry Pi Configuration. Try again after doing this and it should work.
can i install tensorflow2 latest version in rasberry pi 4b 8gb edition?
if yes,then please give some suggestions.
You can technically do it, but there's no benefit of doing so. TensorFlow isn't designed for edge devices like Raspberry Pi. Therefore, you'll get significant performance boost when using TensorFlow Lite compared to using TensorFlow. Besides, there's no easy way to build and install TensorFlow on Raspberry Pi, but you can install TensorFlow Lite just by running "pip install tflite-runtime"
Anyone had problems opening files: RuntimeErro: unable to open file at efficientdet_lite0?
wow Thank you you just saved a life .,
So this worked for me but for some reason it don’t work on my camera that I put on the raspberry car the webcam it basically gives error
Did you happen to use the old TFLite Raspberry Pi sample? We did update it to work with both the Pi camera and USB camera, so please give it another shot by following the instructions in this video.
So it does work with the usb camera that comes with the raspberry that you put onto the car but for some reason when I put the camera back on my car and turn on my pi and do the ssh so I can get the raspberry as my terminal without having to hook up to the monitor when I put the command so it can detect it won’t go through it just gives error idk why
@@yoonmeonme9842 Oh I see. A quick fix would be to remove the cv2.imshow line in the detect.py file. We'll release a headless mode to our Raspberry Pi sample later so that you can run it in an SSH session.
@@khanhleviet5416 it didn’t work I have deleted that line in the code
Error: Could not find a version that satisfies the requirement tflite-runtime==2.5.0 Error: No matching distribution found for tflite-runtime==2.5.0. Using clean/new Raspberry Pi Bullseye OS
Help please! Did I miss something?
Can you try with tflite-runtime==2.7.0?
@@levietgiakhanh9818 I'm getting the same error as Jacque and changing it to 2.7.0 in requirements_tflite.txt resulted in the same error. I'm running on a Pi Zero W (not the new Pi Zero 2), has this been tested on a Pi Zero?
@@sbaueraz I got the same error as Jacque and changed it to 2.7.0 in request_tflite.txt, it worked, did you make sure pip install tflite-runtime?
Same issue here - changing to 2.7.0 doesn't help, either. I do have Python 3.9.2, though. When I tried to install Python 3.7.3 and re-run, the code still seems to look for some 3.9 elements. Some help available?
@@sbaueraz No, you'll need a RPi 3 or RPi 4. Pi Zero uses ARMV6 architecture which isn't supported.
Thank you so much
how to convert model yolov5 (.pt) to tflite?
Thanks!
If you want to train a custom model using your own dataset, check out the second video in this series on how to use Model Maker to train a custom EfficientDet-Lite object detection model. th-cam.com/video/-ZyFYniGUsw/w-d-xo.html
Sir what's the fps offered by raspberry Pi 3 and 4,iam working on a project for object detection using pi cam,and I want to keep the cost as low as possible,so can u tell me whats the fps offered??
around 5 fps
@@gerardoblanco9119 if it can give five detections a second, not bad.
How do i run it on Bullseye OS?
or on Bookworm ? :/
What Raspberry Pi should I use? The one with 2 Gb of RAM, 4 or 8 Gb? Is there any difference for this task?
The one with 2GB should be enough. In the video, I used a 4GB Raspberry Pi 4.
@@khanhleviet5416 Thank you very much.
Do you know if there would be possible to run 2 parallel object detection processes at the same time with multithread?
@@GoodMFM Yes, but it means the frame rate would drop roughly by half. For example, on a Raspberry Pi 4, you'll get about 3fps, instead of 6fps if you run one model.
If you need to run two models in your pipeline, I'd recommend running them one by one rather than use threading to run them at the same time. It'll make your code cleaner.
@@khanhleviet5416 But how can i do that if I want to simultaneously detect some object in real life?? I mean, I think 3 fps would be enough for the task, but I think it will have to be running constantly.
@@GoodMFM Yes you can run object detection continuously using a synchronize program like in the sample in our GitHub repo. goo.gle/3GaABw3
Unfortunately this tutorial does not work with the latest OS of PI
I installed it today, with latest update of OS. Worked fine for me.
With Bullseye, you'll need to enable the legacy camera stack. th-cam.com/video/E7KPSc_Xr24/w-d-xo.html
Mine worked with Bullseye today. I'm using a Logitech video cam.
will this work with the 64 bit OS version?
Yes it works. You'll need to enable the legacy camera stack on Raspberry Pi so that OpenCV can access the webcam to capture images. See this for more details. th-cam.com/video/E7KPSc_Xr24/w-d-xo.html
Thanks for that video!
Is there a way to detect ONLY persons in a video and spare all other detections?
Yes, you just need to set the label_allow_list = ['person'] in the ObjectDetectorOption when initializing the object detector.
@@khanhleviet5416 can you please tell me to where i can add this? on detect.py
Nice
How can I label my own data?
"!pip install --upgrade pyqt5 lxml" run it on jupyter notebook and load you're folder that contained the image
Anything you CAN install with apt, install with apt. It saves you a boatload of "Externally Managed Environment" whines.
Eventually deadends in missing modules anyway.
Now an AI that can write proper-and-working install scripts and cleans up its crap after it is no longer relevant. It's ridiculous we anno 2024 still rely on human installscriptwebpage interpreters.
Mmm, best put this in its own comment I suppose. After changing the tflite version to 2.7.0, and run detect.py, I get:
File "/home/pi/tflite/lib/python3.9/site-packages/cv2/__init__.py", line 5, in
from .cv2 import *
ImportError: libcblas.so.3: cannot open shared object file: No such file or directory
Any Ideas? (I need to get into Pytnon more...)
Ooof, I should learn how to read first... At the bottom of the linked gist: sudo apt-get install libatlas-base-dev
hey I got the same error any idea on how to fix it?
I get the same error as well
when i run the code on my pi 3 it gets stuck on building wheer for numpy (pyproject.toml) ... /
when it gets to that part it starts rotating and then it just freezes and i can't even move the mouse, any suggestions on what to do?
I am having the exact same issue...just curious if you found a solution?
@@tomplatner8890 if you close chrome while it's building it should work. Chrome takes a lot of processing power
@@neomax4 Thanks for the tip..it works now!
Thanks for the wonderful tutorial, I got this error despite following all the instructions(i am using latest versions of python[3.9] and ROS [11]. I also enabled my pi camera with sudo raspi-config)
python detect.py
Unable to init server: Could not connect: Connection refused
Traceback (most recent call last):
File "/home/pi/examples/lite/examples/object_detection/raspberry_pi/detect.py", line 142, in
main()
File "/home/pi/examples/lite/examples/object_detection/raspberry_pi/detect.py", line 137, in main
run(args.model, int(args.cameraId), args.frameWidth, args.frameHeight,
File "/home/pi/examples/lite/examples/object_detection/raspberry_pi/detect.py", line 95, in run
cv2.imshow('object_detector', image)
cv2.error: OpenCV(4.5.3) /tmp/pip-wheel-hwcmjluw/opencv-python_dc56ddd000dd4893b1f852d88d4a5959/opencv/modules/highgui/src/window_gtk.cpp:635: error: (-2:Unspecified error) Can't initialize GTK backend in function 'cvInitSystem'
If you are using Raspberry Pi Bullseye, you'll need to enable the legacy camera stack. See this video for step-by-step instructions.
th-cam.com/video/E7KPSc_Xr24/w-d-xo.html