Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Rename Serializer to Output and move to flash.core.data.io.output #927

Merged
merged 22 commits into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add deprecation
  • Loading branch information
ethanwharris committed Nov 5, 2021
commit bba6cfa5eee9e2f45fd58c7cff96ccabaa24c602
2 changes: 1 addition & 1 deletion flash/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from flash.core.data.data_source import DataSource
from flash.core.data.datasets import FlashDataset, FlashIterableDataset
from flash.core.data.input_transform import InputTransform
from flash.core.data.io.output import Output
from flash.core.data.io.output import Output, Serializer # noqa: F401
from flash.core.data.process import Postprocess, Preprocess
from flash.core.model import Task # noqa: E402
from flash.core.trainer import Trainer # noqa: E402
Expand Down
25 changes: 25 additions & 0 deletions flash/core/data/io/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from typing import Any, Mapping

import torch
from deprecate import deprecated

import flash
from flash.core.data.properties import Properties
Expand Down Expand Up @@ -54,6 +55,30 @@ def __call__(self, sample: Any) -> Any:
return sample


class Serializer(Output):
"""Deprecated.

Use ``Output`` instead.
"""

@deprecated(Output, "0.6.0", "0.7.0")
def __init__(self):
super().__init__()
self._is_enabled = True

@staticmethod
@deprecated(Output.transform, "0.6.0", "0.7.0")
def serialize(sample: Any) -> Any:
"""Deprecated.

Use ``Output.transform`` instead.
"""
return sample

def transform(self, sample: Any) -> Any:
return self.serialize(sample)


class OutputMapping(Output):
"""If the model output is a dictionary, then the :class:`.OutputMapping` enables each entry in the dictionary
to be passed to it's own :class:`.Output`."""
Expand Down
17 changes: 17 additions & 0 deletions flash/core/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import pytorch_lightning as pl
import torch
import torchmetrics
from deprecate import deprecated
from pytorch_lightning import LightningModule, Trainer
from pytorch_lightning.callbacks import Callback
from pytorch_lightning.trainer.optimizers import _get_default_scheduler_config
Expand Down Expand Up @@ -633,6 +634,22 @@ def output(self, output: Union[Output, Mapping[str, Output]]):
output = OutputMapping(output)
self._output = output

@torch.jit.unused
@property
@deprecated(None, "0.6.0", "0.7.0")
def serializer(self) -> Optional[Output]:
"""Deprecated.

Use ``Task.output`` instead.
"""
return self.output

@torch.jit.unused
@serializer.setter
@deprecated(None, "0.6.0", "0.7.0")
def serializer(self, serializer: Union[Output, Mapping[str, Output]]):
self.output = serializer

def build_data_pipeline(
self,
data_source: Optional[str] = None,
Expand Down