Ejemplo n.º 1
0
    def evaluate_batch(self, batch: Any, model: nn.Module) -> Dict[str, Any]:
        batch = cast(Tuple[TorchData, Dict[str, torch.Tensor]], batch)
        data, labels = batch

        output = model(data)
        error = error_rate(output["digit_predictions"], labels["digit_labels"])

        return {"validation_error": error}
Ejemplo n.º 2
0
    def train_batch(self, batch: TorchData, model: nn.Module, epoch_idx: int,
                    batch_idx: int) -> Dict[str, torch.Tensor]:
        batch = cast(Tuple[torch.Tensor, torch.Tensor], batch)
        data, labels = batch

        output = model(data)
        loss = torch.nn.functional.nll_loss(output, labels)
        error = error_rate(output, labels)
        return {"loss": loss, "train_error": error}
Ejemplo n.º 3
0
    def evaluate_batch(self, batch: TorchData,
                       model: nn.Module) -> Dict[str, Any]:
        batch = cast(Tuple[torch.Tensor, torch.Tensor], batch)
        data, labels = batch

        output = model(data)
        error = error_rate(output, labels)

        return {"validation_error": error}
Ejemplo n.º 4
0
    def train_batch(self, batch: Any, model: nn.Module, epoch_idx: int,
                    batch_idx: int) -> Dict[str, torch.Tensor]:
        batch = cast(Tuple[TorchData, Dict[str, torch.Tensor]], batch)
        data, labels = batch

        output = model(data)
        loss = compute_loss(output, labels)
        error = error_rate(output["digit_predictions"], labels["digit_labels"])

        return {"loss": loss, "classification_error": error}
Ejemplo n.º 5
0
    def evaluate_batch(self, batch: TorchData,
                       model: nn.Module) -> Dict[str, Any]:
        """
        Calculate validation metrics for a batch and return them as a dictionary.
        This method is not necessary if the user overwrites evaluate_full_dataset().
        """
        batch = cast(Tuple[torch.Tensor, torch.Tensor], batch)
        data, labels = batch

        output = model(data)
        error = error_rate(output, labels)
        return {"validation_error": error}