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
3 changes: 2 additions & 1 deletion src/inputs/plugins/vlm_coco_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def __init__(self, config: VLM_COCO_LocalConfig):
"""
super().__init__(config)

self.device = "cpu"
self.device = "cuda" if torch.cuda.is_available() else "cpu"
logging.info(f"COCO Object Detector using device: {self.device}")
self.detection_threshold = 0.2

self.camera_index = self.config.camera_index
Expand Down
16 changes: 11 additions & 5 deletions tests/inputs/plugins/test_vlm_coco_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ def mock_cv2_video_capture():

@pytest.fixture
def vlm_coco_local(mock_model, mock_check_webcam, mock_cv2_video_capture):
config = VLM_COCO_LocalConfig(camera_index=0)
return VLM_COCO_Local(config=config)
with patch(
"inputs.plugins.vlm_coco_local.torch.cuda.is_available", return_value=False
):
config = VLM_COCO_LocalConfig(camera_index=0)
return VLM_COCO_Local(config=config)


@pytest.mark.asyncio
Expand Down Expand Up @@ -67,6 +70,7 @@ async def test_raw_to_text_with_detection(vlm_coco_local, mock_model):
vlm_coco_local.class_labels = ["__background__", "cat", "dog"]
vlm_coco_local.cam_third = 213 # 640/3

vlm_coco_local.device = "cpu"
dummy_frame = np.zeros((480, 640, 3), dtype=np.uint8)
result = await vlm_coco_local._raw_to_text(dummy_frame)
assert isinstance(result, Message)
Expand Down Expand Up @@ -99,8 +103,10 @@ async def test_poll_returns_none_on_failed_frame_read(
):
"""Test that _poll returns None when cap.read() fails."""
mock_cv2_video_capture.read.return_value = (False, None)
config = VLM_COCO_LocalConfig(camera_index=0)
sensor = VLM_COCO_Local(config=config)

with patch(
"inputs.plugins.vlm_coco_local.torch.cuda.is_available", return_value=False
):
config = VLM_COCO_LocalConfig(camera_index=0)
sensor = VLM_COCO_Local(config=config)
result = await sensor._poll()
assert result is None
Loading