Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
# limitations under the License.


import logging
from os import PathLike
from typing import Dict

import cv2
import torch
from cv_bridge import CvBridge
from groundingdino.util.inference import Model
from rclpy.time import Time
Expand Down Expand Up @@ -64,14 +66,21 @@ def __init__(
weight_path: str | PathLike,
use_cuda: bool = True,
):
self.logger = logging.getLogger(__name__)
self.cfg_path = __file__.replace(
"vision_markup/boxer.py", "configs/gdino_config.py"
)
self.weight_path = str(weight_path)
if not use_cuda:
self.model = Model(self.cfg_path, self.weight_path, device="cpu")
if use_cuda:
if torch.cuda.is_available():
self.device = "cuda"
else:
self.logger.warning("CUDA is not available but requested, using CPU")
self.device = "cpu"
else:
self.model = Model(self.cfg_path, self.weight_path)
self.device = "cpu"

self.model = Model(self.cfg_path, self.weight_path, device=self.device)
self.bridge = CvBridge()

def get_boxes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.


import logging
from os import PathLike
from typing import List

Expand All @@ -33,13 +34,18 @@ def __init__(
weight_path: str | PathLike,
use_cuda: bool = True,
):
self.logger = logging.getLogger(__name__)
self.cfg_path = "seg_config.yml"
hydra.core.global_hydra.GlobalHydra.instance().clear()
hydra.initialize_config_module("rai_perception.configs")

self.weight_path = str(weight_path)
if use_cuda:
self.device = "cuda" if torch.cuda.is_available() else "cpu"
if torch.cuda.is_available():
self.device = "cuda"
else:
self.logger.warning("CUDA is not available but requested, using CPU")
self.device = "cpu"
else:
self.device = "cpu"
self.sam2_model = build_sam2(
Expand Down