diff options
author | Volpeon <git@volpeon.ink> | 2023-06-22 07:33:29 +0200 |
---|---|---|
committer | Volpeon <git@volpeon.ink> | 2023-06-22 07:33:29 +0200 |
commit | 186a69104530610f8c2b924f79a04f941e5238c8 (patch) | |
tree | f04de211c4f33151c5163be222f7297087edb7d4 /models/convnext | |
parent | Update (diff) | |
download | textual-inversion-diff-186a69104530610f8c2b924f79a04f941e5238c8.tar.gz textual-inversion-diff-186a69104530610f8c2b924f79a04f941e5238c8.tar.bz2 textual-inversion-diff-186a69104530610f8c2b924f79a04f941e5238c8.zip |
Remove convnext
Diffstat (limited to 'models/convnext')
-rw-r--r-- | models/convnext/discriminator.py | 34 |
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 @@ | |||
1 | import torch | ||
2 | from timm.models import ConvNeXt | ||
3 | from timm.data.constants import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD | ||
4 | |||
5 | from torch.nn import functional as F | ||
6 | |||
7 | |||
8 | class 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 | ||