pytorch_lightning.metrics.converters module¶
This file provides functions and decorators for automated input and output
conversion to/from numpy.ndarray
and torch.Tensor
as well as utilities to
sync tensors between different processes in a DDP scenario, when needed.
-
pytorch_lightning.metrics.converters.
_apply_to_inputs
(func_to_apply, *dec_args, **dec_kwargs)[source]¶ Decorator function to apply a function to all inputs of a function.
-
pytorch_lightning.metrics.converters.
_apply_to_outputs
(func_to_apply, *dec_args, **dec_kwargs)[source]¶ Decorator function to apply a function to all outputs of a function.
-
pytorch_lightning.metrics.converters.
_convert_to_numpy
(data)[source]¶ Convert all tensors and numpy arrays to numpy arrays.
-
pytorch_lightning.metrics.converters.
_convert_to_tensor
(data)[source]¶ Maps all kind of collections and numbers to tensors.
-
pytorch_lightning.metrics.converters.
_numpy_metric_conversion
(func_to_decorate)[source]¶ Decorator handling the argument conversion for metrics working on numpy. All inputs of the decorated function will be converted to numpy and all outputs will be converted to tensors.
-
pytorch_lightning.metrics.converters.
_numpy_metric_input_conversion
(func_to_decorate)[source]¶ Decorator converting all inputs of a function to numpy
-
pytorch_lightning.metrics.converters.
_sync_ddp_if_available
(result, group=None, reduce_op=None)[source]¶ Function to reduce the tensors from several ddp processes to one master process
- Parameters
- Return type
- Returns
reduced value
-
pytorch_lightning.metrics.converters.
_tensor_collection_metric_conversion
(func_to_decorate)[source]¶ Decorator Handling the argument conversion for metrics working on tensors. All inputs of the decorated function and all numpy arrays and numbers in it’s outputs will be converted to tensors
-
pytorch_lightning.metrics.converters.
_tensor_collection_metric_output_conversion
(func_to_decorate)[source]¶ Decorator converting all numpy arrays and numbers occuring in the outputs of a function to tensors
-
pytorch_lightning.metrics.converters.
_tensor_metric_conversion
(func_to_decorate)[source]¶ Decorator Handling the argument conversion for metrics working on tensors. All inputs and outputs of the decorated function will be converted to tensors
-
pytorch_lightning.metrics.converters.
_tensor_metric_input_conversion
(func_to_decorate)[source]¶ Decorator converting all inputs of a function to tensors
-
pytorch_lightning.metrics.converters.
_tensor_metric_output_conversion
(func_to_decorate)[source]¶ Decorator converting all outputs of a function to tensors
-
pytorch_lightning.metrics.converters.
numpy_metric
(group=None, reduce_op=None)[source]¶ This decorator shall be used on all function metrics working on numpy arrays. It handles the argument conversion and DDP reduction for metrics working on numpy. All inputs of the decorated function will be converted to numpy and all outputs will be converted to tensors. In DDP Training all output tensors will be reduced according to the given rules.
-
pytorch_lightning.metrics.converters.
sync_ddp
(group=None, reduce_op=None)[source]¶ This decorator syncs a functions outputs across different processes for DDP.
-
pytorch_lightning.metrics.converters.
tensor_collection_metric
(group=None, reduce_op=None)[source]¶ This decorator shall be used on all function metrics working on tensors and returning collections that cannot be converted to tensors. It handles the argument conversion and DDP reduction for metrics working on tensors. All inputs and outputs of the decorated function will be converted to tensors. In DDP Training all output tensors will be reduced according to the given rules.
-
pytorch_lightning.metrics.converters.
tensor_metric
(group=None, reduce_op=None)[source]¶ This decorator shall be used on all function metrics working on tensors. It handles the argument conversion and DDP reduction for metrics working on tensors. All inputs and outputs of the decorated function will be converted to tensors. In DDP Training all output tensors will be reduced according to the given rules.