fix(perception): validate decoded vegetation frames
This commit is contained in:
+3
-11
@@ -87,20 +87,12 @@ def distribution(values: list[float]) -> dict[str, float]:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def open_video(path: Path, expected_size: tuple[int, int]) -> cv2.VideoCapture:
|
def open_video(path: Path) -> cv2.VideoCapture:
|
||||||
if path.is_symlink() or not path.is_file():
|
if path.is_symlink() or not path.is_file():
|
||||||
raise IntegratedLoadError("RAVNOVES video is unavailable")
|
raise IntegratedLoadError("RAVNOVES video is unavailable")
|
||||||
capture = cv2.VideoCapture(str(path))
|
capture = cv2.VideoCapture(str(path))
|
||||||
if not capture.isOpened():
|
if not capture.isOpened():
|
||||||
raise IntegratedLoadError("RAVNOVES video decoder did not open")
|
raise IntegratedLoadError("RAVNOVES video decoder did not open")
|
||||||
metadata = (
|
|
||||||
round(capture.get(cv2.CAP_PROP_FRAME_COUNT)),
|
|
||||||
round(capture.get(cv2.CAP_PROP_FRAME_WIDTH)),
|
|
||||||
round(capture.get(cv2.CAP_PROP_FRAME_HEIGHT)),
|
|
||||||
)
|
|
||||||
if metadata != (FRAME_COUNT, expected_size[0], expected_size[1]):
|
|
||||||
capture.release()
|
|
||||||
raise IntegratedLoadError("RAVNOVES video metadata changed")
|
|
||||||
return capture
|
return capture
|
||||||
|
|
||||||
|
|
||||||
@@ -151,7 +143,7 @@ def run() -> int:
|
|||||||
config["ravnoves"]["expected_width"],
|
config["ravnoves"]["expected_width"],
|
||||||
config["ravnoves"]["expected_height"],
|
config["ravnoves"]["expected_height"],
|
||||||
)
|
)
|
||||||
warmup_capture = open_video(args.video, expected_size)
|
warmup_capture = open_video(args.video)
|
||||||
warmup_source = decode_source(warmup_capture, expected_size)
|
warmup_source = decode_source(warmup_capture, expected_size)
|
||||||
warmup_capture.release()
|
warmup_capture.release()
|
||||||
|
|
||||||
@@ -160,7 +152,7 @@ def run() -> int:
|
|||||||
warmup_tensor, _ = preprocess(warmup_source)
|
warmup_tensor, _ = preprocess(warmup_source)
|
||||||
warmup_latencies_ms = [infer(model, warmup_tensor)[1] for _ in range(3)]
|
warmup_latencies_ms = [infer(model, warmup_tensor)[1] for _ in range(3)]
|
||||||
torch.cuda.reset_peak_memory_stats()
|
torch.cuda.reset_peak_memory_stats()
|
||||||
source_capture = open_video(args.video, expected_size)
|
source_capture = open_video(args.video)
|
||||||
wait_for_shared_start(
|
wait_for_shared_start(
|
||||||
args.shared_start_ready_file,
|
args.shared_start_ready_file,
|
||||||
args.shared_start_file,
|
args.shared_start_file,
|
||||||
|
|||||||
Reference in New Issue
Block a user