ไม่สามารถเล่นวิดีโอนี้
ขออภัยในความไม่สะดวก

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;

ความคิดเห็น • 102

  • @Ajey23
    @Ajey23 ปีที่แล้ว +13

    Guys if you want to detect specific objects use category_name_allowlist=['cat', 'dog'] in processor.Detector Options.

  • @innovationscode9909
    @innovationscode9909 2 ปีที่แล้ว +11

    Raspberry Pi is so useful. Thanks for this

  • @IharRubanau
    @IharRubanau 9 หลายเดือนก่อน +3

    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!

    • @karimabdalla3136
      @karimabdalla3136 5 หลายเดือนก่อน

      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

  • @loganmurray2848
    @loganmurray2848 2 ปีที่แล้ว +2

    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

    • @janecagas7380
      @janecagas7380 2 ปีที่แล้ว +1

      same problem :(. I don't know how to fix this problem tried different solution

    • @alaawehbe371
      @alaawehbe371 2 ปีที่แล้ว

      @@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

  • @madnokof
    @madnokof ปีที่แล้ว +4

    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

    • @Ajey23
      @Ajey23 ปีที่แล้ว +1

      It's also not working can you help please🙏

    • @KeithC-M
      @KeithC-M ปีที่แล้ว

      0:11 tonight ko

    • @KeithC-M
      @KeithC-M ปีที่แล้ว

      0:28 to be there

    • @madnokof
      @madnokof ปีที่แล้ว +1

      @@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

  • @leonyamuronda4700
    @leonyamuronda4700 ปีที่แล้ว +1

    tried the example on raspberry pi 3,its breaking and displaying with error, "no attribute imageDataFree".What could be the problem

  • @Dennis12869
    @Dennis12869 2 ปีที่แล้ว +3

    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.

  • @Alpha_fitz
    @Alpha_fitz ปีที่แล้ว +2

    Could TF be trained to determine wnd speed based on tree/branch/leaf movement?

  • @ttnownow1292
    @ttnownow1292 ปีที่แล้ว +1

    All went well until the final command which did not launch the camera.. Does not seem to working with latest Bullseye

  • @TechCree
    @TechCree 2 ปีที่แล้ว +4

    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.

    • @khanhleviet5416
      @khanhleviet5416 2 ปีที่แล้ว +2

      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/

    • @1500TM
      @1500TM 2 ปีที่แล้ว +2

      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 ..

    • @TechCree
      @TechCree ปีที่แล้ว +1

      @@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.

  • @TechCree
    @TechCree 2 ปีที่แล้ว +1

    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.

  • @notapplicable793
    @notapplicable793 2 ปีที่แล้ว +1

    Can it tell if an object is a hotdog or not hotdog?

  • @atitjantapornsom4073
    @atitjantapornsom4073 ปีที่แล้ว

    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.

  • @YNightmareT
    @YNightmareT ปีที่แล้ว +1

    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?

    • @TensorFlow
      @TensorFlow  ปีที่แล้ว +1

      Did you forget to specify the path to create a virtual environment like in this case?
      goo.gle/3skfxBr

  • @yencytolentino4299
    @yencytolentino4299 2 ปีที่แล้ว +2

    Thank you for the information sir! Is it possible to run tensorflow object detection directly on a raspberry pi 3 without the TensorFlow lite?

    • @khanhleviet5416
      @khanhleviet5416 2 ปีที่แล้ว +4

      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

    • @yencytolentino4299
      @yencytolentino4299 2 ปีที่แล้ว

      @@khanhleviet5416 thank you very much!

  • @Tensordroid
    @Tensordroid 2 ปีที่แล้ว +2

    Nice✨
    TensorFlow is ❤️‍🔥

  • @Rmni2
    @Rmni2 ปีที่แล้ว

    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 ☹️

  • @69MrUsername69
    @69MrUsername69 2 ปีที่แล้ว +2

    Looking forward to this series

  • @anitamanchanda6817
    @anitamanchanda6817 ปีที่แล้ว

    What about the pico? That is supported right? Can't have a Pi 4 for every little project.

  • @cheseewow
    @cheseewow ปีที่แล้ว

    Can this machine learning model capable of detecting texture of an object?

  • @saikumardhrmavarapu8570
    @saikumardhrmavarapu8570 2 ปีที่แล้ว

    Can we modify the code like the detected object are list or telling in headphones

  • @Satish_Lakhan29
    @Satish_Lakhan29 2 ปีที่แล้ว

    I want to glow led when car is detected what will the changes?

  • @kiriobalbous8210
    @kiriobalbous8210 ปีที่แล้ว

    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

  • @fahemhamou6170
    @fahemhamou6170 ปีที่แล้ว +1

    Thank you very much

  • @tranlequynh9645
    @tranlequynh9645 2 ปีที่แล้ว

    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ì ạ?

    • @tranlequynh9645
      @tranlequynh9645 2 ปีที่แล้ว

      can u help meee? huu

    • @khanhleviet5416
      @khanhleviet5416 2 ปีที่แล้ว

      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.

    • @tranlequynh9645
      @tranlequynh9645 2 ปีที่แล้ว

      @@khanhleviet5416 yes, pi's camera is working fine. I used another model and it works, but using your model it gives such error

    • @tranlequynh9645
      @tranlequynh9645 2 ปีที่แล้ว +1

      @@khanhleviet5416 I reinstalled Pi's OS and it worked, I'm very happy, your video is very good, thank you so muchhh

  • @encoder10101
    @encoder10101 2 ปีที่แล้ว +3

    Thank you!
    Which camera and connection type do you using for the raspberryPi ?

    • @khanhleviet5416
      @khanhleviet5416 2 ปีที่แล้ว +2

      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.

    • @encoder10101
      @encoder10101 2 ปีที่แล้ว

      @@khanhleviet5416 Thank you, friend!

  • @georgoschalkiadakis2402
    @georgoschalkiadakis2402 2 ปีที่แล้ว +1

    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

    • @everwondered4839
      @everwondered4839 2 ปีที่แล้ว

      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.

  • @shashiranjan543
    @shashiranjan543 2 ปีที่แล้ว +1

    can i install tensorflow2 latest version in rasberry pi 4b 8gb edition?
    if yes,then please give some suggestions.

    • @khanhleviet5416
      @khanhleviet5416 2 ปีที่แล้ว

      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"

  • @user-zd4eo7er6d
    @user-zd4eo7er6d ปีที่แล้ว

    Anyone had problems opening files: RuntimeErro: unable to open file at efficientdet_lite0?

  • @KingTine724
    @KingTine724 2 ปีที่แล้ว

    wow Thank you you just saved a life .,

  • @yoonmeonme9842
    @yoonmeonme9842 2 ปีที่แล้ว

    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

    • @khanhleviet5416
      @khanhleviet5416 2 ปีที่แล้ว

      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.

    • @yoonmeonme9842
      @yoonmeonme9842 2 ปีที่แล้ว

      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

    • @khanhleviet5416
      @khanhleviet5416 2 ปีที่แล้ว

      @@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.

    • @yoonmeonme9842
      @yoonmeonme9842 2 ปีที่แล้ว

      @@khanhleviet5416 it didn’t work I have deleted that line in the code

  • @jacquewilson5568
    @jacquewilson5568 2 ปีที่แล้ว

    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?

    • @levietgiakhanh9818
      @levietgiakhanh9818 2 ปีที่แล้ว +1

      Can you try with tflite-runtime==2.7.0?

    • @sbaueraz
      @sbaueraz 2 ปีที่แล้ว

      @@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?

    • @tranlequynh9645
      @tranlequynh9645 2 ปีที่แล้ว

      @@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?

    • @ulrichhorstmann3565
      @ulrichhorstmann3565 2 ปีที่แล้ว

      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?

    • @khanhleviet5416
      @khanhleviet5416 2 ปีที่แล้ว +1

      ​@@sbaueraz No, you'll need a RPi 3 or RPi 4. Pi Zero uses ARMV6 architecture which isn't supported.

  • @NoNameTechnology
    @NoNameTechnology 2 ปีที่แล้ว

    Thank you so much

  • @phuongthaingoc2000
    @phuongthaingoc2000 2 ปีที่แล้ว

    how to convert model yolov5 (.pt) to tflite?
    Thanks!

    • @levietgiakhanh9818
      @levietgiakhanh9818 2 ปีที่แล้ว

      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

  • @mohammedkamran8559
    @mohammedkamran8559 2 ปีที่แล้ว

    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??

  • @MrBlitzcrank
    @MrBlitzcrank 8 หลายเดือนก่อน

    How do i run it on Bullseye OS?

    • @MrBlitzcrank
      @MrBlitzcrank 8 หลายเดือนก่อน

      or on Bookworm ? :/

  • @GoodMFM
    @GoodMFM 2 ปีที่แล้ว

    What Raspberry Pi should I use? The one with 2 Gb of RAM, 4 or 8 Gb? Is there any difference for this task?

    • @khanhleviet5416
      @khanhleviet5416 2 ปีที่แล้ว +3

      The one with 2GB should be enough. In the video, I used a 4GB Raspberry Pi 4.

    • @GoodMFM
      @GoodMFM 2 ปีที่แล้ว

      @@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?

    • @khanhleviet5416
      @khanhleviet5416 2 ปีที่แล้ว +1

      @@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.

    • @GoodMFM
      @GoodMFM 2 ปีที่แล้ว

      @@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.

    • @khanhleviet5416
      @khanhleviet5416 2 ปีที่แล้ว

      @@GoodMFM Yes you can run object detection continuously using a synchronize program like in the sample in our GitHub repo. goo.gle/3GaABw3

  • @jaykkt02
    @jaykkt02 2 ปีที่แล้ว

    Unfortunately this tutorial does not work with the latest OS of PI

    • @hoplahey
      @hoplahey 2 ปีที่แล้ว

      I installed it today, with latest update of OS. Worked fine for me.

    • @khanhleviet5416
      @khanhleviet5416 2 ปีที่แล้ว

      With Bullseye, you'll need to enable the legacy camera stack. th-cam.com/video/E7KPSc_Xr24/w-d-xo.html

    • @russhall1097
      @russhall1097 2 ปีที่แล้ว

      Mine worked with Bullseye today. I'm using a Logitech video cam.

  • @SuperVane101
    @SuperVane101 2 ปีที่แล้ว

    will this work with the 64 bit OS version?

    • @khanhleviet5416
      @khanhleviet5416 2 ปีที่แล้ว

      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

  • @sophiaschmidt7374
    @sophiaschmidt7374 2 ปีที่แล้ว

    Thanks for that video!
    Is there a way to detect ONLY persons in a video and spare all other detections?

    • @khanhleviet5416
      @khanhleviet5416 2 ปีที่แล้ว +1

      Yes, you just need to set the label_allow_list = ['person'] in the ObjectDetectorOption when initializing the object detector.

    • @dhanithlakjaya
      @dhanithlakjaya 2 ปีที่แล้ว

      @@khanhleviet5416 can you please tell me to where i can add this? on detect.py

  • @_XY_
    @_XY_ 2 ปีที่แล้ว

    Nice

  • @alexisespinosa711
    @alexisespinosa711 2 ปีที่แล้ว

    How can I label my own data?

    • @alaawehbe371
      @alaawehbe371 2 ปีที่แล้ว

      "!pip install --upgrade pyqt5 lxml" run it on jupyter notebook and load you're folder that contained the image

  • @ojoshiro
    @ojoshiro 17 วันที่ผ่านมา

    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.

  • @mannob
    @mannob 2 ปีที่แล้ว +1

    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...)

    • @mannob
      @mannob 2 ปีที่แล้ว +3

      Ooof, I should learn how to read first... At the bottom of the linked gist: sudo apt-get install libatlas-base-dev

    • @E1an9640
      @E1an9640 ปีที่แล้ว

      hey I got the same error any idea on how to fix it?

    • @ayushpatel789
      @ayushpatel789 11 หลายเดือนก่อน

      I get the same error as well

  • @neomax4
    @neomax4 ปีที่แล้ว

    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?

    • @tomplatner8890
      @tomplatner8890 ปีที่แล้ว

      I am having the exact same issue...just curious if you found a solution?

    • @neomax4
      @neomax4 ปีที่แล้ว

      @@tomplatner8890 if you close chrome while it's building it should work. Chrome takes a lot of processing power

    • @tomplatner8890
      @tomplatner8890 ปีที่แล้ว

      @@neomax4 Thanks for the tip..it works now!

  • @sam9620
    @sam9620 2 ปีที่แล้ว +1

    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'

    • @khanhleviet5416
      @khanhleviet5416 2 ปีที่แล้ว

      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