(self, x)
| 40 | self.uncond = None |
| 41 | |
| 42 | def preprocess(self, x): |
| 43 | # resize to 224, normalize to [0,1] and re-normalize according to clip |
| 44 | x = torch.nn.functional.interpolate(x, size=(224, 224), mode='bilinear', align_corners=False) |
| 45 | assert x.min() >= -1. and x.max() <= 1. |
| 46 | x = (x + 1.) / 2. |
| 47 | x = (x - self.mean.reshape(1,-1,1,1)) / self.std.reshape(1,-1,1,1) |
| 48 | return x |
| 49 | |
| 50 | def forward(self, x, no_dropout=False): |
| 51 | # x is assumed to be in range [-1,1] |