File size: 1,402 Bytes
89f6699 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | import torch
from torch import nn
from typing import Any, Iterable, List
class Model(nn.Module):
"""
Template model for the leaderboard.
Requirements:
- Must be instantiable with no arguments (called by the evaluator).
- Must implement `predict(batch)` which receives an iterable of inputs and
returns a list of predictions (labels).
- Must implement `eval()` to place the model in evaluation mode.
- If you use PyTorch, submit a state_dict to be loaded via `load_state_dict`
"""
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
# Initialize your model here
def eval(self) -> nn.Module:
# Optional: set your model to evaluation mode
return self
def predict(self, batch: Iterable[Any]) -> List[Any]:
"""
Implement your inference here.
Inputs:
batch: Iterable of preprocessed inputs (as produced by your preprocess.py)
Returns:
A list of predictions with the same length as `batch`.
"""
raise NotImplementedError("Implement predict(...) to return a list of labels.")
def get_model() -> Model:
"""
Factory function required by the evaluator.
Returns an uninitialized model instance. The evaluator may optionally load
weights (if provided) before calling predict(...).
"""
return Model()
|