Skip to content

Commit c9ea8e0

Browse files
some progress, but things still don't work well enough...
1 parent c0a7edc commit c9ea8e0

4 files changed

Lines changed: 57 additions & 28 deletions

File tree

predicators/envs/spot_env.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,18 +1180,23 @@ def _actively_construct_initial_object_views(
11801180

11811181
# Capture images from the current position and run detection
11821182
# without moving the robot.
1183-
rgbds = capture_images(self._robot, self._localizer)
1184-
detection_ids = set(self._detection_id_to_obj.keys())
1185-
detections, artifacts = detect_objects(
1186-
detection_ids, rgbds, self._allowed_regions)
1187-
1188-
if CFG.spot_render_perception_outputs:
1189-
outdir = Path(CFG.spot_perception_outdir)
1190-
time_str = time.strftime("%Y%m%d-%H%M%S")
1191-
detections_outfile = outdir / f"detections_{time_str}.png"
1192-
no_detections_outfile = outdir / f"no_detections_{time_str}.png"
1193-
visualize_all_artifacts(artifacts, detections_outfile,
1194-
no_detections_outfile)
1183+
# rgbds = capture_images(self._robot, self._localizer)
1184+
# detection_ids = set(self._detection_id_to_obj.keys())
1185+
# detections, artifacts = detect_objects(
1186+
# detection_ids, rgbds, self._allowed_regions)
1187+
1188+
# if CFG.spot_render_perception_outputs:
1189+
# outdir = Path(CFG.spot_perception_outdir)
1190+
# time_str = time.strftime("%Y%m%d-%H%M%S")
1191+
# detections_outfile = outdir / f"detections_{time_str}.png"
1192+
# no_detections_outfile = outdir / f"no_detections_{time_str}.png"
1193+
# visualize_all_artifacts(artifacts, detections_outfile,
1194+
# no_detections_outfile)
1195+
1196+
# Detection is currently disabled (commented out above), so default
1197+
# to empty so the fallback to known poses below still works.
1198+
detections: Dict[ObjectDetectionID, math_helpers.SE3Pose] = {}
1199+
artifacts: Dict[str, Any] = {}
11951200

11961201
obj_to_se3_pose = {
11971202
self._detection_id_to_obj[det_id]: val

predicators/ground_truth_models/spot_env/options.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,9 @@ def _fn() -> None:
522522
time.sleep(0.5) # Wait for the hand image to settle
523523
while True:
524524
robot, localizer, lease_client = get_robot()
525-
rgbds = capture_images(robot, localizer, relocalize=True)
525+
rgbds = capture_images(robot, localizer,
526+
camera_names=["hand_color_image"],
527+
relocalize=True)
526528
pick_obj_id = get_detection_id_for_object(objects[target_obj_idx])
527529
_, artifacts = detect_objects([pick_obj_id], rgbds)
528530
try:

predicators/pretrained_model_interface.py

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import base64
99
import logging
1010
import os
11+
import signal
1112
from io import BytesIO
1213
from typing import Collection, Dict, List, Optional, Union
1314

@@ -198,6 +199,26 @@ def call_openai_api(self,
198199
return completion.choices[0].message.content
199200

200201

202+
class _GeminiTimeout:
203+
"""Context manager that raises TimeoutError after a deadline (seconds)."""
204+
205+
def __init__(self, seconds: int = 30) -> None:
206+
self._seconds = seconds
207+
208+
def _handler(self, signum, frame):
209+
raise TimeoutError(
210+
f"Gemini API call timed out after {self._seconds}s")
211+
212+
def __enter__(self):
213+
self._old_handler = signal.signal(signal.SIGALRM, self._handler)
214+
signal.alarm(self._seconds)
215+
return self
216+
217+
def __exit__(self, *args):
218+
signal.alarm(0)
219+
signal.signal(signal.SIGALRM, self._old_handler)
220+
221+
201222
class GoogleGeminiModel():
202223
"""Common interface and methods for all Gemini-based models.
203224
@@ -260,8 +281,8 @@ class GoogleGeminiLLM(LargeLanguageModel, GoogleGeminiModel):
260281
necessary API key to query the particular model name.
261282
"""
262283

263-
# @retry(wait=wait_random_exponential(min=1, max=60),
264-
# stop=stop_after_attempt(10))
284+
@retry(wait=wait_random_exponential(min=1, max=30),
285+
stop=stop_after_attempt(5))
265286
def _sample_completions(
266287
self,
267288
prompt: str,
@@ -275,10 +296,11 @@ def _sample_completions(
275296
config = types.GenerateContentConfig(
276297
temperature=temperature,
277298
candidate_count=num_completions)
278-
response = self._client.models.generate_content(
279-
model=self._model_name,
280-
contents=[prompt],
281-
config=config)
299+
with _GeminiTimeout(seconds=30):
300+
response = self._client.models.generate_content(
301+
model=self._model_name,
302+
contents=[prompt],
303+
config=config)
282304
return [response.text]
283305

284306
def get_id(self) -> str:
@@ -292,8 +314,8 @@ class GoogleGeminiVLM(VisionLanguageModel, GoogleGeminiModel):
292314
necessary API key to query the particular model name.
293315
"""
294316

295-
# @retry(wait=wait_random_exponential(min=1, max=60),
296-
# stop=stop_after_attempt(10))
317+
@retry(wait=wait_random_exponential(min=1, max=30),
318+
stop=stop_after_attempt(5))
297319
def _sample_completions(
298320
self,
299321
prompt: str,
@@ -306,12 +328,12 @@ def _sample_completions(
306328
assert imgs is not None
307329
config = types.GenerateContentConfig(
308330
temperature=temperature,
309-
candidate_count=num_completions,
310-
http_options=types.HttpOptions(timeout=15_000))
311-
response = self._client.models.generate_content(
312-
model=self._model_name,
313-
contents=[prompt] + imgs,
314-
config=config)
331+
candidate_count=num_completions)
332+
with _GeminiTimeout(seconds=30):
333+
response = self._client.models.generate_content(
334+
model=self._model_name,
335+
contents=[prompt] + imgs,
336+
config=config)
315337
return [response.text]
316338

317339
def get_id(self) -> str:

predicators/spot_utils/graph_nav_maps/b45-621-cleanup/metadata.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ approach_angle_bounds:
181181
clear_plastic_container: [1.47, 1.67]
182182
recycling_bin: [-0.1, 0.1]
183183
pink_furry_eraser: [-1.67, -1.47]
184-
green_and_blue_furry_eraser: [-1.67, -1.47]
184+
green_and_blue_furry_eraser: [-0.1, 0.1]
185185
soda_can: [-1.67, -1.47]
186186

187187
# Wiping skill params.

0 commit comments

Comments
 (0)