training_utils

fgvc.core.training.training_utils.concat_arrays(*lists: List[List[ndarray | dict]]) List[List[ndarray | dict] | None]

Concatenate lists of numpy arrays with predictions and targets to numpy arrays.

Parameters:

lists – (One or multiple items) List of numpy arrays or dictionary of lists.

Return type:

(One or multiple items) Numpy array or dictionary of numpy arrays.

fgvc.core.training.training_utils.get_gradient_norm(model_params: Tensor | Iterable[Tensor], norm_type: float = 2.0) float

Compute norm of model parameter gradients.

Parameters:
  • model_params – Model parameters.

  • norm_type – The order of norm.

Return type:

Norm of model parameter gradients.

fgvc.core.training.training_utils.to_device(*tensors: List[Tensor | dict], device: device) List[Tensor | dict]

Convert pytorch tensors to device.

Parameters:
  • tensors – (One or multiple items) Pytorch tensor or dictionary of pytorch tensors.

  • device – Device to use (CPU,CUDA,CUDA:0,…).

Return type:

(One or multiple items) Pytorch tensor or dictionary of pytorch tensors.

fgvc.core.training.training_utils.to_numpy(*tensors: List[Tensor | dict]) List[ndarray | dict]

Convert pytorch tensors to numpy arrays.

Parameters:

tensors – (One or multiple items) Pytorch tensor or dictionary of pytorch tensors.

Return type:

(One or multiple items) Numpy array or dictionary of numpy arrays.