-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into find-person-skill
- Loading branch information
Showing
46 changed files
with
1,400 additions
and
874 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env python3 | ||
import rospy | ||
from typing import List | ||
from lasr_vision_clip.clip_utils import load_model, query_image_stream | ||
from lasr_vision_msgs.srv import VqaRequest, VqaResponse, Vqa | ||
from sensor_msgs.msg import Image | ||
|
||
|
||
class VqaService: | ||
def __init__(self, model_device: str = "cuda") -> None: | ||
"""Caches the clip model. | ||
Args: | ||
model_device (str, optional): device to load model onto. Defaults to "cuda". | ||
""" | ||
|
||
self._model = load_model(model_device) | ||
self._debug_pub = rospy.Publisher("/clip_vqa/debug", Image, queue_size=1) | ||
rospy.loginfo("Clip VQA service started") | ||
|
||
def query_clip(self, request: VqaRequest) -> VqaResponse: | ||
"""Queries CLIP from the robot's image stream and returns | ||
the most likely answer and cosine similarity score. | ||
Args: | ||
possible_answers (List[str]): set of possible answers. | ||
Returns: | ||
VqaResult | ||
""" | ||
possible_answers = request.possible_answers | ||
answer, cos_score, annotated_img = query_image_stream( | ||
self._model, possible_answers, annotate=True | ||
) | ||
|
||
self._debug_pub.publish(annotated_img) | ||
|
||
result = VqaResponse() | ||
result.answer = answer | ||
rospy.loginfo(f"Answer: {answer}") | ||
result.similarity = float(cos_score) | ||
return result | ||
|
||
|
||
if __name__ == "__main__": | ||
rospy.init_node("clip_vqa_service") | ||
service = VqaService() | ||
rospy.Service("/clip_vqa/query_service", Vqa, service.query_clip) | ||
rospy.spin() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
string[] possible_answers | ||
|
||
--- | ||
|
||
# most likely answer | ||
string answer | ||
|
||
# cosine similarity | ||
float32 similarity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import smach_ros | ||
from lasr_vision_msgs.srv import Vqa, VqaRequest | ||
|
||
from typing import List, Union | ||
|
||
|
||
class QueryImage(smach_ros.ServiceState): | ||
|
||
def __init__(self, possible_answers: Union[None, List[str]] = None): | ||
|
||
if possible_answers is not None: | ||
super(QueryImage, self).__init__( | ||
"/clip_vqa/query_service", | ||
Vqa, | ||
request=VqaRequest(possible_answers=possible_answers), | ||
response_slots=["answer", "similarity"], | ||
) | ||
else: | ||
super(QueryImage, self).__init__( | ||
"/clip_vqa/query_service", | ||
Vqa, | ||
request_slots=["possible_answers"], | ||
response_slots=["answer", "similarity"], | ||
) |
Oops, something went wrong.