WildDet3D / vis4d /eval /utils.py
weikaih's picture
WildDet3D Gradio demo
f71ac1d verified
"""Utility functions for evaluation."""
import numpy as np
from vis4d.common.array import array_to_numpy
from vis4d.common.typing import ArrayLike, NDArrayNumber
def dense_inputs_to_numpy(
prediction: ArrayLike, target: ArrayLike
) -> tuple[NDArrayNumber, NDArrayNumber]:
"""Convert dense prediction and target to numpy arrays."""
prediction = array_to_numpy(prediction, n_dims=None, dtype=np.float32)
target = array_to_numpy(target, n_dims=None, dtype=np.float32)
return prediction, target
def check_shape_match(
prediction: NDArrayNumber, target: NDArrayNumber
) -> None:
"""Check if the shape of prediction and target matches."""
assert prediction.shape == target.shape, (
f"Shape mismatch between prediction {prediction.shape} and target"
f"{target.shape}."
)