-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathcollate_if.py
More file actions
42 lines (29 loc) · 1.13 KB
/
collate_if.py
File metadata and controls
42 lines (29 loc) · 1.13 KB
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
from abc import ABC, abstractmethod
import torch
from modalities.batch import DatasetBatch
class CollatorIF(ABC):
def __call__(self, batch: list[dict[str, torch.Tensor]]) -> DatasetBatch:
"""
Process a batch of data.
Args:
batch (list[dict[str, torch.Tensor]]): A list of dictionaries containing 1-dim tensors.
Returns:
DatasetBatch: The processed batch of data.
Raises:
NotImplementedError: This abstract method should be implemented in a subclass.
"""
raise NotImplementedError
class CollateFnIF(ABC):
"""CollateFnIF class to define a collate function interface."""
@abstractmethod
def __call__(self, batch: dict[str, torch.Tensor]) -> dict[str, torch.Tensor]:
"""
Process a batch of data.
Args:
batch (list[dict[str, torch.Tensor]]): A list of dictionaries containing tensors.
Returns:
DatasetBatch: The processed batch of data.
Raises:
NotImplementedError: This abstract method should be implemented in a subclass.
"""
raise NotImplementedError