| 205 | |
| 206 | |
| 207 | class AbsTask(ABC): |
| 208 | # Use @staticmethod, or @classmethod, |
| 209 | # instead of instance method to avoid God classes |
| 210 | |
| 211 | # If you need more than one optimizers, change this value in inheritance |
| 212 | num_optimizers: int = 1 |
| 213 | trainer = Trainer |
| 214 | class_choices_list: List[ClassChoices] = [] |
| 215 | |
| 216 | def __init__(self): |
| 217 | raise RuntimeError("This class can't be instantiated.") |
| 218 | |
| 219 | @classmethod |
| 220 | @abstractmethod |
| 221 | def add_task_arguments(cls, parser: argparse.ArgumentParser): |
| 222 | pass |
| 223 | |
| 224 | @classmethod |
| 225 | @abstractmethod |
| 226 | def build_collate_fn( |
| 227 | cls, args: argparse.Namespace, train: bool |
| 228 | ) -> Callable[[Sequence[Dict[str, np.ndarray]]], Dict[str, torch.Tensor]]: |
| 229 | """Return "collate_fn", which is a callable object and given to DataLoader. |
| 230 | |
| 231 | >>> from torch.utils.data import DataLoader |
| 232 | >>> loader = DataLoader(collate_fn=cls.build_collate_fn(args, train=True), ...) |
| 233 | |
| 234 | In many cases, you can use our common collate_fn. |
| 235 | """ |
| 236 | raise NotImplementedError |
| 237 | |
| 238 | @classmethod |
| 239 | @abstractmethod |
| 240 | def build_preprocess_fn( |
| 241 | cls, args: argparse.Namespace, train: bool |
| 242 | ) -> Optional[Callable[[str, Dict[str, np.array]], Dict[str, np.ndarray]]]: |
| 243 | raise NotImplementedError |
| 244 | |
| 245 | @classmethod |
| 246 | @abstractmethod |
| 247 | def required_data_names( |
| 248 | cls, train: bool = True, inference: bool = False |
| 249 | ) -> Tuple[str, ...]: |
| 250 | """Define the required names by Task |
| 251 | |
| 252 | This function is used by |
| 253 | >>> cls.check_task_requirements() |
| 254 | If your model is defined as following, |
| 255 | |
| 256 | >>> from espnet2.train.abs_espnet_model import AbsESPnetModel |
| 257 | >>> class Model(AbsESPnetModel): |
| 258 | ... def forward(self, input, output, opt=None): pass |
| 259 | |
| 260 | then "required_data_names" should be as |
| 261 | |
| 262 | >>> required_data_names = ('input', 'output') |
| 263 | """ |
| 264 | raise NotImplementedError |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…