Skip to content

Commit

Permalink
add inference
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphvK committed Jul 12, 2024
1 parent 8a7c240 commit a400ab9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions _tc/ros/yolov5_tc/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<depend>cv_bridge</depend>
<depend>perception_msgs</depend>
<depend>python-transforms3d-pip</depend>
<depend>python3-ultralytics-pip</depend>
<depend>rclpy</depend>
<depend>sensor_msgs</depend>

Expand Down
13 changes: 8 additions & 5 deletions _tc/ros/yolov5_tc/yolov5_tc/inference_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from sensor_msgs.msg import Image
from perception_msgs.msg import ObjectList
from rclpy.node import Node
from cv_bridge import CvBridge
import torch

# constants
INPUT_TOPIC = "~/input"
Expand Down Expand Up @@ -32,17 +34,18 @@ def setup(self):
qos_profile=1)
self.get_logger().info(f"Publishing to '{self.publisher.topic_name}'")

self.cv_bridge = CvBridge()
self.model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True)

def topicCallback(self, msg: Image):

# echo received message
self.get_logger().info(f"Received image with stamp: '{msg.header.stamp}'")

# skip if the published topic has no subscription
# if self.publisher.get_subscription_count() == 0:
# return

# TODO Inference
cv_image = self.cv_bridge.imgmsg_to_cv2(msg, desired_encoding="bgr8")

result = self.model(cv_image)
print(result)

# create and publish a new message
object_list = ObjectList()
Expand Down

0 comments on commit a400ab9

Please sign in to comment.