-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.py
More file actions
39 lines (33 loc) · 928 Bytes
/
common.py
File metadata and controls
39 lines (33 loc) · 928 Bytes
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
from abc import ABC, abstractmethod
from typing import Tuple, Optional
import torch
import torch.nn as nn
class Sampleable(ABC):
"""
Distribution which can be sampled from
"""
@abstractmethod
def sample(self, num_samples: int) -> Tuple[torch.Tensor, Optional[torch.Tensor]]:
"""
Args:
- num_samples: the desired number of samples
Returns:
- samples: shape (batch_size, ...)
- labels: shape (batch_size, label_dim)
"""
pass
class ConditionalVectorField(nn.Module, ABC):
"""
MLP-parameterization of the learned vector field u_t^theta(x)
"""
@abstractmethod
def forward(self, x: torch.Tensor, t: torch.Tensor, y: torch.Tensor):
"""
Args:
- x: (bs, c, h, w)
- t: (bs, 1, 1, 1)
- y: (bs,)
Returns:
- u_t^theta(x|y): (bs, c, h, w)
"""
pass