Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,6 +21,23 @@ from transformers import (
|
|
| 21 |
logging,
|
| 22 |
)
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
class VisionTextDualEncoderModel(nn.Module):
|
| 26 |
def __init__(self, num_classes):
|
|
|
|
| 21 |
logging,
|
| 22 |
)
|
| 23 |
|
| 24 |
+
class Transform(torch.nn.Module):
|
| 25 |
+
def __init__(self, image_size, mean, std):
|
| 26 |
+
super().__init__()
|
| 27 |
+
self.transforms = torch.nn.Sequential(
|
| 28 |
+
Resize([image_size], interpolation=InterpolationMode.BICUBIC),
|
| 29 |
+
CenterCrop(image_size),
|
| 30 |
+
ConvertImageDtype(torch.float),
|
| 31 |
+
Normalize(mean, std),
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
def forward(self, x) -> torch.Tensor:
|
| 35 |
+
"""`x` should be an instance of `PIL.Image.Image`"""
|
| 36 |
+
with torch.no_grad():
|
| 37 |
+
x = self.transforms(x)
|
| 38 |
+
return x
|
| 39 |
+
|
| 40 |
+
|
| 41 |
|
| 42 |
class VisionTextDualEncoderModel(nn.Module):
|
| 43 |
def __init__(self, num_classes):
|