summaryrefslogtreecommitdiffstats
path: root/models/convnext
diff options
context:
space:
mode:
Diffstat (limited to 'models/convnext')
-rw-r--r--models/convnext/discriminator.py34
1 files changed, 0 insertions, 34 deletions
diff --git a/models/convnext/discriminator.py b/models/convnext/discriminator.py
deleted file mode 100644
index 5798bcf..0000000
--- a/models/convnext/discriminator.py
+++ /dev/null
@@ -1,34 +0,0 @@
1import torch
2from timm.models import ConvNeXt
3from timm.data.constants import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD
4
5from torch.nn import functional as F
6
7
8class ConvNeXtDiscriminator:
9 def __init__(self, model: ConvNeXt, input_size: int) -> None:
10 self.net = model
11
12 self.input_size = input_size
13
14 self.img_mean = torch.tensor(IMAGENET_DEFAULT_MEAN).view(1, -1, 1, 1)
15 self.img_std = torch.tensor(IMAGENET_DEFAULT_STD).view(1, -1, 1, 1)
16
17 def get_score(self, img):
18 pred = self.get_all(img)
19 return torch.softmax(pred, dim=-1)[:, 1]
20
21 def get_all(self, img):
22 img_mean = self.img_mean.to(device=img.device, dtype=img.dtype)
23 img_std = self.img_std.to(device=img.device, dtype=img.dtype)
24
25 img = ((img + 1.0) / 2.0).sub(img_mean).div(img_std)
26
27 img = F.interpolate(
28 img,
29 size=(self.input_size, self.input_size),
30 mode="bicubic",
31 align_corners=True,
32 )
33 pred = self.net(img)
34 return pred