Lileb-Training/src/train/utils.py
def create_supervised_evaluator(model, metrics=None,
                                device=None, non_blocking=False,
                                prepare_batch=_prepare_batch,
                                output_transform=lambda x, y, y_pred: (y_pred, y,)):
    """
    Factory function for creating an evaluator for supervised models.

    Args:
        model (`torch.nn.Module`): the model to train.
        metrics (dict of str - :class:`~ignite.metrics.Metric`): a map of metric names to Metrics.
        device (str, optional): device type specification (default: None).
            Applies to both model and batches.
        non_blocking (bool, optional): if True and this copy is between CPU and GPU, the copy may occur asynchronously
            with respect to the host. For other cases, this argument has no effect.
        prepare_batch (callable, optional): function that receives `batch`, `device`, `non_blocking` and outputs
            tuple of tensors `(batch_x, batch_y)`.
        output_transform (callable, optional): function that receives 'x', 'y', 'y_pred' and returns value
            to be assigned to engine's state.output after each iteration. Default is returning `(y_pred, y,)` which fits
            output expected by metrics. If you change it you should use `output_transform` in metrics.

    Note: `engine.state.output` for this engine is defind by `output_transform` parameter and is
        a tuple of `(batch_pred, batch_y)` by default.

    Returns:
        Engine: an evaluator engine with supervised inference function.
    """
    metrics = metrics or {}

    if device:
        model.to(device)

    def _inference(engine, batch):
        model.eval()
        with torch.no_grad():
            # z is optional (e.g. task ids)
            x, y, *z = prepare_batch(batch, device=device, non_blocking=non_blocking)
            y_pred = model(*(x, *z))
            return output_transform(x, y, y_pred)

    engine = Engine(_inference)

    for name, metric in metrics.items():
        metric.attach(engine, name)

    return engine

    Factory function for creating an evaluator for supervised models.

    Args:
        model (`torch.nn.Module`): the model to train.
        metrics (dict of str - :class:`~ignite.metrics.Metric`): a map of metric names to Metrics.
        device (str, optional): device type specification (default: None).
            Applies to both model and batches.
        non_blocking (bool, optional): if True and this copy is between CPU and GPU, the copy may occur asynchronously
            with respect to the host. For other cases, this argument has no effect.
        prepare_batch (callable, optional): function that receives `batch`, `device`, `non_blocking` and outputs
            tuple of tensors `(batch_x, batch_y)`.
        output_transform (callable, optional): function that receives 'x', 'y', 'y_pred' and returns value
            to be assigned to engine's state.output after each iteration. Default is returning `(y_pred, y,)` which fits
            output expected by metrics. If you change it you should use `output_transform` in metrics.

    Note: `engine.state.output` for this engine is defind by `output_transform` parameter and is
        a tuple of `(batch_pred, batch_y)` by default.

    Returns:
        Engine: an evaluator engine with supervised inference function.
    
Factory function for creating an evaluator for supervised models.
Factory function for creating an evaluator for supervised models .
def create_supervised_evaluator(model, metrics=None,
                                device=None, non_blocking=False,
                                prepare_batch=_prepare_batch,
                                output_transform=lambda x, y, y_pred: (y_pred, y,)):
    metrics = metrics or {}
    if device:
        model.to(device)
    def _inference(engine, batch):
        model.eval()
        with torch.no_grad():
            x, y, *z = prepare_batch(batch, device=device, non_blocking=non_blocking)
            y_pred = model(*(x, *z))
            return output_transform(x, y, y_pred)
    engine = Engine(_inference)
    for name, metric in metrics.items():
        metric.attach(engine, name)
    return engine
def create_supervised_evaluator ( model , metrics = None , device = None , non_blocking = False , prepare_batch = _prepare_batch , output_transform = lambda x , y , y_pred : ( y_pred , y , ) ) : metrics = metrics or { } if device : model . to ( device ) def _inference ( engine , batch ) : model . eval ( ) with torch . no_grad ( ) : x , y , * z = prepare_batch ( batch , device = device , non_blocking = non_blocking ) y_pred = model ( * ( x , * z ) ) return output_transform ( x , y , y_pred ) engine = Engine ( _inference ) for name , metric in metrics . items ( ) : metric . attach ( engine , name ) return engine
Factory function for creating an evaluator for supervised models.
Factory function for creating an evaluator for supervised models .
"""
    Factory function for creating an evaluator for supervised models.

    Args:
        model (`torch.nn.Module`): the model to train.
        metrics (dict of str - :class:`~ignite.metrics.Metric`): a map of metric names to Metrics.
        device (str, optional): device type specification (default: None).
            Applies to both model and batches.
        non_blocking (bool, optional): if True and this copy is between CPU and GPU, the copy may occur asynchronously
            with respect to the host. For other cases, this argument has no effect.
        prepare_batch (callable, optional): function that receives `batch`, `device`, `non_blocking` and outputs
            tuple of tensors `(batch_x, batch_y)`.
        output_transform (callable, optional): function that receives 'x', 'y', 'y_pred' and returns value
            to be assigned to engine's state.output after each iteration. Default is returning `(y_pred, y,)` which fits
            output expected by metrics. If you change it you should use `output_transform` in metrics.

    Note: `engine.state.output` for this engine is defind by `output_transform` parameter and is
        a tuple of `(batch_pred, batch_y)` by default.

    Returns:
        Engine: an evaluator engine with supervised inference function.
    """ # z is optional (e.g. task ids)
an evaluator engine with supervised inference function.
an evaluator engine with supervised inference function .
Engine
model
the model to train.
the model to train .
metrics
device
device type specification (default: None).
Applies to both model and batches.
device type specification ( default : None ) . Applies to both model and batches .
non_blocking
if True and this copy is between CPU and GPU, the copy may occur asynchronously
with respect to the host. For other cases, this argument has no effect.
if True and this copy is between CPU and GPU the copy may occur asynchronously with respect to the host . For other cases this argument has no effect .
prepare_batch
function that receives `batch`, `device`, `non_blocking` and outputs
tuple of tensors `(batch_x, batch_y)`.
function that receives ` batch ` ` device ` ` non_blocking ` and outputs tuple of tensors ` ( batch_x batch_y ) ` .
output_transform
function that receives 'x', 'y', 'y_pred' and returns value
to be assigned to engine's state.output after each iteration. Default is returning `(y_pred, y,)` which fits
output expected by metrics. If you change it you should use `output_transform` in metrics.
function that receives ' x ' ' y ' ' y_pred ' and returns value to be assigned to engine ' s state . output after each iteration . Default is returning ` ( y_pred y ) ` which fits output expected by metrics . If you change it you should use ` output_transform ` in metrics .
metrics (dict of str - 
`~ignite.metrics.Metric`): a map of metric names to Metrics.
` ~ignite . metrics . Metric ` ) : a map of metric names to Metrics .