Commit ·
5f73c99
1
Parent(s): 393b535
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,29 @@ from einops import rearrange
|
|
| 5 |
from torchvision.transforms import Compose
|
| 6 |
import torchvision
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
classes = ['Acanthostichus',
|
| 9 |
'Aenictus',
|
| 10 |
'Amblyopone',
|
|
|
|
| 5 |
from torchvision.transforms import Compose
|
| 6 |
import torchvision
|
| 7 |
|
| 8 |
+
class CMYKToRGB(object):
|
| 9 |
+
def __call__(self, img):
|
| 10 |
+
# Ensure that the input is a PIL Image
|
| 11 |
+
if not isinstance(img, torch.Tensor):
|
| 12 |
+
raise TypeError("Input image should be a torch.Tensor")
|
| 13 |
+
|
| 14 |
+
# Ensure that the image has 4 channels (CMYK)
|
| 15 |
+
if img.shape[-3] != 4:
|
| 16 |
+
return img
|
| 17 |
+
|
| 18 |
+
# Extract CMYK channels
|
| 19 |
+
c, m, y, k = img.unbind(-3)
|
| 20 |
+
|
| 21 |
+
# CMYK to RGB transformation
|
| 22 |
+
r = 255 * (1 - c) * (1 - k)
|
| 23 |
+
g = 255 * (1 - m) * (1 - k)
|
| 24 |
+
b = 255 * (1 - y) * (1 - k)
|
| 25 |
+
|
| 26 |
+
# Stack RGB channels
|
| 27 |
+
rgb_img = torch.stack([r, g, b], dim=-3)
|
| 28 |
+
|
| 29 |
+
return rgb_img
|
| 30 |
+
|
| 31 |
classes = ['Acanthostichus',
|
| 32 |
'Aenictus',
|
| 33 |
'Amblyopone',
|