Skip to content

Commit 66b6452

Browse files
committed
Resolve comments [3]
1 parent 00ddd57 commit 66b6452

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

sdks/python/apache_beam/examples/inference/pytorch_image_captioning.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,9 @@ def run_inference(
202202
uris.append(x.get("uri", ""))
203203
try:
204204
images.append(decode_pil(b))
205-
except Exception:
205+
except Exception as e:
206206
# fallback: a blank image (so pipeline keeps going)
207+
logging.warning("Failed to decode image %s: %s", uris[-1], e)
207208
images.append(PILImage.new("RGB", (224, 224), color=(0, 0, 0)))
208209

209210
# Processor makes pixel_values
@@ -305,7 +306,8 @@ def run_inference(
305306

306307
try:
307308
img = decode_pil(image_bytes)
308-
except Exception:
309+
except Exception as e:
310+
logging.warning("Failed to decode image for CLIP ranking: %s", e)
309311
img = PILImage.new("RGB", (224, 224), color=(0, 0, 0))
310312

311313
start_i = len(texts)

sdks/python/apache_beam/examples/inference/pytorch_imagenet_rightfit.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,12 @@ def process(self, kv: Tuple[str, PredictionResult]):
181181
# fallback: try first value if dict shape differs
182182
try:
183183
logits = next(iter(inference_obj.values()))
184+
logging.warning(
185+
'Could not find <logits> key in model output.'
186+
'Falling back to first value in dict.'
187+
)
184188
except Exception:
185-
logits = None
189+
logging.warning('Could not find <logits> key in dict.')
186190
else:
187191
logits = inference_obj
188192

@@ -454,7 +458,7 @@ def run(
454458
mdl(torch.unsqueeze(dummy, 0))
455459
bs_ok = bs if bs is not None else 64
456460
break
457-
except Exception as e:
461+
except RuntimeError as e:
458462
last_err = e
459463
logging.warning("Batch size %s failed during warmup: %s", bs, e)
460464
continue

0 commit comments

Comments
 (0)