Skip to content

Commit 7e3a30f

Browse files
committed
fix(dataloader): use specific exception, add cv2 availability check
P2: replace bare except with except Exception - bare except catches KeyboardInterrupt/SystemExit unexpectedly - now allows interrupt signals to propagate P2: add _HAS_CV2 check before using cv2 - _HAS_CV2 was defined but never checked - added ImportError with clear message in _mv_energy_norm
1 parent 1a718c2 commit 7e3a30f

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

dataloader/ap_dataloader_dali_ip_mv.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ def _mv_energy_norm(
5555
pct: float = 95.0,
5656
):
5757
"""Return (norm_HxW_float32_in_[0,1], scale_max_px). No gamma/colormap."""
58+
if not _HAS_CV2: # fix: check cv2 availability before use
59+
raise ImportError("cv2 is required for _mv_energy_norm but not available")
5860
vx = mvx.astype(np.float32) / float(mv_unit_div)
5961
vy = mvy.astype(np.float32) / float(mv_unit_div)
6062
mag = np.sqrt(vx * vx + vy * vy) # pixels
@@ -315,7 +317,7 @@ def __call__(self, sample_info):
315317
video_path, video_label = example_info
316318
try:
317319
combined_data, duration, frame_id_list = self.get_frame_id_list(video_path, self.sequence_length)
318-
except:
320+
except Exception: # fix: avoid bare except to allow KeyboardInterrupt/SystemExit to propagate
319321
video_path, video_label = self.replace_example_info
320322
combined_data, duration, frame_id_list = self.get_frame_id_list(video_path, self.sequence_length)
321323

0 commit comments

Comments
 (0)