Spidartist commited on
Commit
b44e693
·
1 Parent(s): 1b20ab6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -7
app.py CHANGED
@@ -58,6 +58,14 @@ classes = ['Acanthostichus',
58
  'Zasphinctus']
59
  class_to_idx = {idx: cls for idx, cls in enumerate(classes)}
60
 
 
 
 
 
 
 
 
 
61
  tf = Compose([torchvision.transforms.Resize((64, 64), antialias=True)])
62
 
63
  model = ViTIJEPA(64, 4, 3, 64, 8, 8, len(classes))
@@ -65,16 +73,15 @@ model.load_state_dict(torch.load("vit_ijepa_ant_1.pt", map_location=torch.device
65
 
66
 
67
  def ant_genus_classification(image):
68
- image = torch.Tensor(image)
69
- image = image.unsqueeze(0)
70
- image = rearrange(image, 'b h w c -> b c h w')
71
- image = tf(image)
72
 
73
  print(image.shape)
74
  with torch.no_grad():
75
- prediction = torch.nn.functional.softmax(model(image)[0], dim=0)
76
- # print(prediction.tolist())
77
- confidences = {class_to_idx[i]: float(prediction[i]) for i in range(len(classes))}
 
 
78
  return confidences
79
  # prediction = model(image)[0]
80
  # prediction = prediction.tolist()
 
58
  'Zasphinctus']
59
  class_to_idx = {idx: cls for idx, cls in enumerate(classes)}
60
 
61
+ train_transforms = torchvision.transforms.Compose(
62
+ [
63
+ torchvision.transforms.ToTensor(),
64
+ torchvision.transforms.Resize((TARGET_SIZE[0], TARGET_SIZE[1]), antialias=True),
65
+ CMYKToRGB(),
66
+ ]
67
+ )
68
+
69
  tf = Compose([torchvision.transforms.Resize((64, 64), antialias=True)])
70
 
71
  model = ViTIJEPA(64, 4, 3, 64, 8, 8, len(classes))
 
73
 
74
 
75
  def ant_genus_classification(image):
76
+ image = train_transforms(image).unsqueeze(0)
 
 
 
77
 
78
  print(image.shape)
79
  with torch.no_grad():
80
+ y_hat = model(x)
81
+ y_hat = torch.nn.functional.softmax(y_hat, dim=1)
82
+ preds = torch.argmax(y_hat, dim=1)
83
+
84
+ confidences = {class_to_idx[i]: float(preds[i]) for i in range(len(classes))}
85
  return confidences
86
  # prediction = model(image)[0]
87
  # prediction = prediction.tolist()