简体   繁体   English

tflite object 检测中的 Raspberry Pi GPIO 引脚问题

[英]Raspberry Pi GPIO pin issue in tflite object detection

I have successfully trained my custom model and used it for object detection.我已经成功训练了我的自定义 model 并将其用于 object 检测。 However, I am facing a slight issue regarding the if-else condition on my custom model.但是,我在自定义 model 上的 if-else 条件方面遇到了一个小问题。 I only have one object/class in my trained model, when it is detected I want to make a gpio pin to go HIGH (LED) and when the object is removed from the webcam feed the pin should go LOW. I only have one object/class in my trained model, when it is detected I want to make a gpio pin to go HIGH (LED) and when the object is removed from the webcam feed the pin should go LOW. When I run the code the pin does go HIGH on a perfect detection but stays HIGH even if I remove the object from webcam feed.当我运行代码时,引脚在完美检测时会执行 go 高电平,但即使我从网络摄像头馈送中删除 object 也会保持高电平。 I used the following if-else condition:我使用了以下 if-else 条件:

if (object_name == labels[int(classes[i])]) and (scores[i]) >= 0.95):
GPIO.output(13, GPIO.HIGH)
else:
GPIO.output(13, GPIO.LOW)

I am using the code found in Edje Electronics's tflite object detection code:我正在使用 Edje Electronics 的 tflite object 检测代码中的代码:

https://github.com/EdjeElectronics/TensorFlow-Lite-Object-Detection-on-Android-and-Raspberry-Pi/blob/master/TFLite_detection_webcam.py

There are two loops in the object detection code one for the webcam feed and second for creating the bounding boxes when object is detected . object 检测代码中有两个循环,一个用于网络摄像头馈送,第二个用于在检测到 object 时创建边界框 If I try to LOW the gpio pin after the second loop the LED does not turn on.如果我在第二个循环后尝试降低 gpio 引脚,则 LED 不会亮起。

It is difficult to tell the exact cause of it without seeing your code, but based on the example code you linked, it sounds like you are doing something like this:如果不查看您的代码,很难说出它的确切原因,但是根据您链接的示例代码,听起来您正在做这样的事情:

# First loop for webcam frame
while True:

  # ...

  # Second loop for detection / drawing bounding box
  for i in range(len(scores)):
    if <your match condition>:
      GPIO.output(13, GPIO.HIGH)
    else:
      GPIO.output(13, GPIO.LOW)

    # ...

In case this is what your code looks like, what you're doing is turning on/off your LED always based on the last item in the scores list, which is probably not what you want.如果这是您的代码的样子,您所做的是始终根据scores列表中的最后一项打开/关闭 LED,这可能不是您想要的。 I would suggest revising the code something like the following:我建议修改代码如下:

# First loop for webcam frame
while True:

  # ...

  found_match = False  
  # Second loop
  for i in range(len(scores)):
    if <your match condition>:
      found_match = True

    # ...

  # Outside the second loop
  GPIO.output(13, found_match)

This would make your LED turn on only when there is at least one detected object according to your match condition, and off otherwise.这将使您的 LED 仅在根据您的匹配条件检测到至少一个 object 时打开,否则关闭。

If this was not your issue, please update your question with your full code.如果这不是您的问题,请使用您的完整代码更新您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM