File size: 822 Bytes
f71ac1d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""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}."
    )