Module flashy.loggers.base

Expand source code
from abc import ABC, abstractmethod
from argparse import Namespace
import typing as tp


class ExperimentLogger(ABC):
    """Base interface for logging to experiment management tools"""

    @abstractmethod
    def log_hyperparams(self, params: tp.Union[tp.Dict[str, tp.Any], Namespace],
                        metrics: tp.Optional[dict] = None) -> None:
        """Record experiment hyperparameters.
        This method logs the hyperparameters associated to the experiment.

        Args:
            params: Dictionary of hyperparameters
            metrics: Dictionary of final metrics for the set of hyperparameters
        """
        ...

    @abstractmethod
    def log_metrics(self, prefix: tp.Union[str, tp.List[str]], metrics: dict,
                    step: tp.Optional[int] = None) -> None:
        """Records metrics.
        This method logs metrics as as soon as it received them.

        Args:
            prefix: Prefix(es) to use for metric names when writing to smart logger
            metrics: Dictionary with metric names as keys and measured quantities as values
            step: Step number at which the metrics should be recorded
        """
        ...

    @abstractmethod
    def log_audio(self, prefix: tp.Union[str, tp.List[str]], key: str, audio: tp.Any, sample_rate: int,
                  step: tp.Optional[int] = None, **kwargs: tp.Any) -> None:
        """Records audio.
        This method logs audio wave as soon as it received them.

        Args:
            prefix: Prefix(es) to use for metric names when writing to smart logger
            key: Key for the audio
            audio: Torch Tensor representing the audio as [C, T]
            sample_rate: Sample rate corresponding to the audio
            step: Step number at which the metrics should be recorded
        """
        ...

    @abstractmethod
    def log_image(self, prefix: tp.Union[str, tp.List[str]], key: str, image: tp.Any,
                  step: tp.Optional[int] = None, **kwargs: tp.Any) -> None:
        """Records image.
        This method logs image as soon as it received them.

        Args:
            prefix: Prefix(es) to use for metric names when writing to smart logger
            key: Key for the image
            image: Torch Tensor representing the image
            step: Step number at which the metrics should be recorded
        """
        raise NotImplementedError

    @abstractmethod
    def log_text(self, prefix: tp.Union[str, tp.List[str]], key: str, text: str,
                 step: tp.Optional[int] = None, **kwargs: tp.Any) -> None:
        """Records text.
        This method logs text as soon as it received them.

        Args:
            prefix: Prefix(es) to use for metric names when writing to smart logger
            key: Key for the text
            text: String containing message
            step: Step number at which the metrics should be recorded
        """
        raise NotImplementedError

    @property
    @abstractmethod
    def with_media_logging(self) -> bool:
        """Whether the logger can save media or ignore them."""
        ...

    @property
    @abstractmethod
    def save_dir(self) -> tp.Optional[str]:
        """Directory where the data is saved."""
        ...

    @property
    @abstractmethod
    def name(self) -> str:
        """Name of the experiment logger."""
        ...

    @property
    def group_separator(self) -> str:
        """Character used as group separator."""
        return '/'

Classes

class ExperimentLogger

Base interface for logging to experiment management tools

Expand source code
class ExperimentLogger(ABC):
    """Base interface for logging to experiment management tools"""

    @abstractmethod
    def log_hyperparams(self, params: tp.Union[tp.Dict[str, tp.Any], Namespace],
                        metrics: tp.Optional[dict] = None) -> None:
        """Record experiment hyperparameters.
        This method logs the hyperparameters associated to the experiment.

        Args:
            params: Dictionary of hyperparameters
            metrics: Dictionary of final metrics for the set of hyperparameters
        """
        ...

    @abstractmethod
    def log_metrics(self, prefix: tp.Union[str, tp.List[str]], metrics: dict,
                    step: tp.Optional[int] = None) -> None:
        """Records metrics.
        This method logs metrics as as soon as it received them.

        Args:
            prefix: Prefix(es) to use for metric names when writing to smart logger
            metrics: Dictionary with metric names as keys and measured quantities as values
            step: Step number at which the metrics should be recorded
        """
        ...

    @abstractmethod
    def log_audio(self, prefix: tp.Union[str, tp.List[str]], key: str, audio: tp.Any, sample_rate: int,
                  step: tp.Optional[int] = None, **kwargs: tp.Any) -> None:
        """Records audio.
        This method logs audio wave as soon as it received them.

        Args:
            prefix: Prefix(es) to use for metric names when writing to smart logger
            key: Key for the audio
            audio: Torch Tensor representing the audio as [C, T]
            sample_rate: Sample rate corresponding to the audio
            step: Step number at which the metrics should be recorded
        """
        ...

    @abstractmethod
    def log_image(self, prefix: tp.Union[str, tp.List[str]], key: str, image: tp.Any,
                  step: tp.Optional[int] = None, **kwargs: tp.Any) -> None:
        """Records image.
        This method logs image as soon as it received them.

        Args:
            prefix: Prefix(es) to use for metric names when writing to smart logger
            key: Key for the image
            image: Torch Tensor representing the image
            step: Step number at which the metrics should be recorded
        """
        raise NotImplementedError

    @abstractmethod
    def log_text(self, prefix: tp.Union[str, tp.List[str]], key: str, text: str,
                 step: tp.Optional[int] = None, **kwargs: tp.Any) -> None:
        """Records text.
        This method logs text as soon as it received them.

        Args:
            prefix: Prefix(es) to use for metric names when writing to smart logger
            key: Key for the text
            text: String containing message
            step: Step number at which the metrics should be recorded
        """
        raise NotImplementedError

    @property
    @abstractmethod
    def with_media_logging(self) -> bool:
        """Whether the logger can save media or ignore them."""
        ...

    @property
    @abstractmethod
    def save_dir(self) -> tp.Optional[str]:
        """Directory where the data is saved."""
        ...

    @property
    @abstractmethod
    def name(self) -> str:
        """Name of the experiment logger."""
        ...

    @property
    def group_separator(self) -> str:
        """Character used as group separator."""
        return '/'

Ancestors

  • abc.ABC

Subclasses

Instance variables

var group_separator : str

Character used as group separator.

Expand source code
@property
def group_separator(self) -> str:
    """Character used as group separator."""
    return '/'
var name : str

Name of the experiment logger.

Expand source code
@property
@abstractmethod
def name(self) -> str:
    """Name of the experiment logger."""
    ...
var save_dir : Optional[str]

Directory where the data is saved.

Expand source code
@property
@abstractmethod
def save_dir(self) -> tp.Optional[str]:
    """Directory where the data is saved."""
    ...
var with_media_logging : bool

Whether the logger can save media or ignore them.

Expand source code
@property
@abstractmethod
def with_media_logging(self) -> bool:
    """Whether the logger can save media or ignore them."""
    ...

Methods

def log_audio(self, prefix: Union[str, List[str]], key: str, audio: Any, sample_rate: int, step: Optional[int] = None, **kwargs: Any) ‑> None

Records audio. This method logs audio wave as soon as it received them.

Args

prefix
Prefix(es) to use for metric names when writing to smart logger
key
Key for the audio
audio
Torch Tensor representing the audio as [C, T]
sample_rate
Sample rate corresponding to the audio
step
Step number at which the metrics should be recorded
Expand source code
@abstractmethod
def log_audio(self, prefix: tp.Union[str, tp.List[str]], key: str, audio: tp.Any, sample_rate: int,
              step: tp.Optional[int] = None, **kwargs: tp.Any) -> None:
    """Records audio.
    This method logs audio wave as soon as it received them.

    Args:
        prefix: Prefix(es) to use for metric names when writing to smart logger
        key: Key for the audio
        audio: Torch Tensor representing the audio as [C, T]
        sample_rate: Sample rate corresponding to the audio
        step: Step number at which the metrics should be recorded
    """
    ...
def log_hyperparams(self, params: Union[Dict[str, Any], argparse.Namespace], metrics: Optional[dict] = None) ‑> None

Record experiment hyperparameters. This method logs the hyperparameters associated to the experiment.

Args

params
Dictionary of hyperparameters
metrics
Dictionary of final metrics for the set of hyperparameters
Expand source code
@abstractmethod
def log_hyperparams(self, params: tp.Union[tp.Dict[str, tp.Any], Namespace],
                    metrics: tp.Optional[dict] = None) -> None:
    """Record experiment hyperparameters.
    This method logs the hyperparameters associated to the experiment.

    Args:
        params: Dictionary of hyperparameters
        metrics: Dictionary of final metrics for the set of hyperparameters
    """
    ...
def log_image(self, prefix: Union[str, List[str]], key: str, image: Any, step: Optional[int] = None, **kwargs: Any) ‑> None

Records image. This method logs image as soon as it received them.

Args

prefix
Prefix(es) to use for metric names when writing to smart logger
key
Key for the image
image
Torch Tensor representing the image
step
Step number at which the metrics should be recorded
Expand source code
@abstractmethod
def log_image(self, prefix: tp.Union[str, tp.List[str]], key: str, image: tp.Any,
              step: tp.Optional[int] = None, **kwargs: tp.Any) -> None:
    """Records image.
    This method logs image as soon as it received them.

    Args:
        prefix: Prefix(es) to use for metric names when writing to smart logger
        key: Key for the image
        image: Torch Tensor representing the image
        step: Step number at which the metrics should be recorded
    """
    raise NotImplementedError
def log_metrics(self, prefix: Union[str, List[str]], metrics: dict, step: Optional[int] = None) ‑> None

Records metrics. This method logs metrics as as soon as it received them.

Args

prefix
Prefix(es) to use for metric names when writing to smart logger
metrics
Dictionary with metric names as keys and measured quantities as values
step
Step number at which the metrics should be recorded
Expand source code
@abstractmethod
def log_metrics(self, prefix: tp.Union[str, tp.List[str]], metrics: dict,
                step: tp.Optional[int] = None) -> None:
    """Records metrics.
    This method logs metrics as as soon as it received them.

    Args:
        prefix: Prefix(es) to use for metric names when writing to smart logger
        metrics: Dictionary with metric names as keys and measured quantities as values
        step: Step number at which the metrics should be recorded
    """
    ...
def log_text(self, prefix: Union[str, List[str]], key: str, text: str, step: Optional[int] = None, **kwargs: Any) ‑> None

Records text. This method logs text as soon as it received them.

Args

prefix
Prefix(es) to use for metric names when writing to smart logger
key
Key for the text
text
String containing message
step
Step number at which the metrics should be recorded
Expand source code
@abstractmethod
def log_text(self, prefix: tp.Union[str, tp.List[str]], key: str, text: str,
             step: tp.Optional[int] = None, **kwargs: tp.Any) -> None:
    """Records text.
    This method logs text as soon as it received them.

    Args:
        prefix: Prefix(es) to use for metric names when writing to smart logger
        key: Key for the text
        text: String containing message
        step: Step number at which the metrics should be recorded
    """
    raise NotImplementedError