Skip to content

Commit

Permalink
Merge pull request #50 from knorth55/device-path
Browse files Browse the repository at this point in the history
  • Loading branch information
knorth55 authored Jan 14, 2021
2 parents e3889fc + 01478e6 commit 8bfb6c6
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "python/coral_usb/posenet"]
path = python/coral_usb/posenet
url = https://github.com/google-coral/project-posenet
url = https://github.com/knorth55/project-posenet.git
2 changes: 2 additions & 0 deletions launch/edgetpu_face_detector.launch
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<arg name="INPUT_IMAGE"/>
<arg name="IMAGE_TRANSPORT" default="raw"/>
<arg name="model_file" default="$(find coral_usb)/models/mobilenet_ssd_v2_face_quant_postprocess_edgetpu.tflite"/>
<arg name="device_id" default="0" />

<node name="edgetpu_face_detector"
pkg="coral_usb" type="edgetpu_face_detector.py"
Expand All @@ -10,6 +11,7 @@
<rosparam subst_value="true" >
model_file: $(arg model_file)
image_transport: $(arg IMAGE_TRANSPORT)
device_id: $(arg device_id)
</rosparam>
</node>
</launch>
2 changes: 2 additions & 0 deletions launch/edgetpu_human_pose_estimator.launch
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<arg name="INPUT_IMAGE"/>
<arg name="IMAGE_TRANSPORT" default="raw"/>
<arg name="model_file" default="$(find coral_usb)/python/coral_usb/posenet/models/mobilenet/posenet_mobilenet_v1_075_481_641_quant_decoder_edgetpu.tflite"/>
<arg name="device_id" default="0" />

<node name="edgetpu_human_pose_estimator"
pkg="coral_usb" type="edgetpu_human_pose_estimator.py"
Expand All @@ -10,6 +11,7 @@
<rosparam subst_value="true" >
model_file: $(arg model_file)
image_transport: $(arg IMAGE_TRANSPORT)
device_id: $(arg device_id)
</rosparam>
</node>
</launch>
4 changes: 4 additions & 0 deletions launch/edgetpu_node_manager_params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ edgetpu_node_manager:
edgetpu_face_detector:
model_file: package://coral_usb/models/mobilenet_ssd_v2_face_quant_postprocess_edgetpu.tflite
image_transport: raw
device_id: 0
edgetpu_object_detector:
model_file: package://coral_usb/models/mobilenet_ssd_v2_coco_quant_postprocess_edgetpu.tflite
label_file: package://coral_usb/models/coco_labels.txt
image_transport: raw
device_id: 0
edgetpu_human_pose_estimator:
model_file: package://coral_usb/python/coral_usb/posenet/models/mobilenet/posenet_mobilenet_v1_075_481_641_quant_decoder_edgetpu.tflite
image_transport: raw
device_id: 0
edgetpu_semantic_segmenter:
image_transport: raw
device_id: 0
2 changes: 2 additions & 0 deletions launch/edgetpu_object_detector.launch
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<arg name="IMAGE_TRANSPORT" default="raw"/>
<arg name="model_file" default="$(find coral_usb)/models/mobilenet_ssd_v2_coco_quant_postprocess_edgetpu.tflite"/>
<arg name="label_file" default="$(find coral_usb)/models/coco_labels.txt"/>
<arg name="device_id" default="0" />

<node name="edgetpu_object_detector"
pkg="coral_usb" type="edgetpu_object_detector.py"
Expand All @@ -12,6 +13,7 @@
model_file: $(arg model_file)
label_file: $(arg label_file)
image_transport: $(arg IMAGE_TRANSPORT)
device_id: $(arg device_id)
</rosparam>
</node>
</launch>
2 changes: 2 additions & 0 deletions launch/edgetpu_semantic_segmenter.launch
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<launch>
<arg name="INPUT_IMAGE"/>
<arg name="IMAGE_TRANSPORT" default="raw"/>
<arg name="device_id" default="0" />

<node name="edgetpu_semantic_segmenter"
pkg="coral_usb" type="edgetpu_semantic_segmenter.py"
output="screen" respawn="true">
<remap from="~input" to="$(arg INPUT_IMAGE)" />
<rosparam subst_value="true" >
image_transport: $(arg IMAGE_TRANSPORT)
device_id: $(arg device_id)
</rosparam>
</node>
</launch>
16 changes: 15 additions & 1 deletion python/coral_usb/detector_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

from chainercv.visualizations import vis_bbox
from cv_bridge import CvBridge
from edgetpu.basic.edgetpu_utils import EDGE_TPU_STATE_ASSIGNED
from edgetpu.basic.edgetpu_utils import EDGE_TPU_STATE_NONE
from edgetpu.basic.edgetpu_utils import ListEdgeTpuPaths
from edgetpu.detection.engine import DetectionEngine
import PIL.Image
from resource_retriever import get_filename
Expand Down Expand Up @@ -50,7 +53,18 @@ def __init__(self, model_file=None, label_file=None, namespace='~'):
self.enable_visualization = rospy.get_param(
namespace + 'enable_visualization', True)

self.engine = DetectionEngine(self.model_file)
device_id = rospy.get_param(namespace + 'device_id', None)
if device_id is None:
device_path = None
else:
device_path = ListEdgeTpuPaths(EDGE_TPU_STATE_NONE)[device_id]
assigned_device_paths = ListEdgeTpuPaths(EDGE_TPU_STATE_ASSIGNED)
if device_path in assigned_device_paths:
rospy.logwarn(
'device {} is already assigned: {}'.format(
device_id, device_path))

self.engine = DetectionEngine(self.model_file, device_path=device_path)
if label_file is None:
self.label_ids = None
self.label_names = None
Expand Down
17 changes: 16 additions & 1 deletion python/coral_usb/human_pose_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

from chainercv.visualizations import vis_point
from cv_bridge import CvBridge
from edgetpu.basic.edgetpu_utils import EDGE_TPU_STATE_ASSIGNED
from edgetpu.basic.edgetpu_utils import EDGE_TPU_STATE_NONE
from edgetpu.basic.edgetpu_utils import ListEdgeTpuPaths
from resource_retriever import get_filename
import rospkg
import rospy
Expand Down Expand Up @@ -59,7 +62,19 @@ def __init__(self, namespace='~'):
self.enable_visualization = rospy.get_param(
namespace + 'enable_visualization', True)

self.engine = PoseEngine(self.model_file, mirror=False)
device_id = rospy.get_param(namespace + 'device_id', None)
if device_id is None:
device_path = None
else:
device_path = ListEdgeTpuPaths(EDGE_TPU_STATE_NONE)[device_id]
assigned_device_paths = ListEdgeTpuPaths(EDGE_TPU_STATE_ASSIGNED)
if device_path in assigned_device_paths:
rospy.logwarn(
'device {} is already assigned: {}'.format(
device_id, device_path))

self.engine = PoseEngine(
self.model_file, mirror=False, device_path=device_path)
self.resized_H = self.engine.image_height
self.resized_W = self.engine.image_width

Expand Down
2 changes: 1 addition & 1 deletion python/coral_usb/posenet
Submodule posenet updated 1 files
+2 −2 pose_engine.py
16 changes: 15 additions & 1 deletion python/coral_usb/semantic_segmenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
from chainercv.visualizations import vis_semantic_segmentation
from cv_bridge import CvBridge
from edgetpu.basic.basic_engine import BasicEngine
from edgetpu.basic.edgetpu_utils import EDGE_TPU_STATE_ASSIGNED
from edgetpu.basic.edgetpu_utils import EDGE_TPU_STATE_NONE
from edgetpu.basic.edgetpu_utils import ListEdgeTpuPaths
from resource_retriever import get_filename
import rospkg
import rospy
Expand Down Expand Up @@ -52,7 +55,18 @@ def __init__(self, namespace='~'):
self.enable_visualization = rospy.get_param(
namespace + 'enable_visualization', True)

self.engine = BasicEngine(self.model_file)
device_id = rospy.get_param(namespace + 'device_id', None)
if device_id is None:
device_path = None
else:
device_path = ListEdgeTpuPaths(EDGE_TPU_STATE_NONE)[device_id]
assigned_device_paths = ListEdgeTpuPaths(EDGE_TPU_STATE_ASSIGNED)
if device_path in assigned_device_paths:
rospy.logwarn(
'device {} is already assigned: {}'.format(
device_id, device_path))

self.engine = BasicEngine(self.model_file, device_path)
self.input_shape = self.engine.get_input_tensor_shape()[1:3]

if label_file is None:
Expand Down

0 comments on commit 8bfb6c6

Please sign in to comment.