samfhy commited on
Commit
abffa49
·
verified ·
1 Parent(s): a34be86

Update app.py

Browse files

experiment on dropping TTA

Files changed (1) hide show
  1. app.py +11 -10
app.py CHANGED
@@ -81,13 +81,13 @@ transform = v2.Compose([
81
  v2.Normalize(mean=[0.6007, 0.5679, 0.5206], std=[0.2411, 0.2392, 0.2479])
82
  ])
83
 
84
- tta_transform = v2.Compose([
85
- v2.ToImage(),
86
- v2.Resize((IMAGE_SIZE, IMAGE_SIZE)),
87
- v2.RandomHorizontalFlip(p=1.0),
88
- v2.ToDtype(torch.float32, scale=True),
89
- v2.Normalize(mean=[0.6007, 0.5679, 0.5206], std=[0.2411, 0.2392, 0.2479]),
90
- ])
91
 
92
  efficientnet = models.efficientnet_v2_l(weights='EfficientNet_V2_L_Weights.DEFAULT')
93
  efficientnet.classifier = new_layers
@@ -100,13 +100,14 @@ def predict(img, use_optimized_threshold):
100
  img = img.convert('RGB')
101
 
102
  base_input = transform(img).unsqueeze(0).to(device)
103
- flipped_input = tta_transform(img).unsqueeze(0).to(device)
104
 
105
  with torch.no_grad():
106
  base_probs = torch.sigmoid(efficientnet(base_input))
107
- flipped_probs = torch.sigmoid(efficientnet(flipped_input))
108
 
109
- predicted_probs = ((base_probs + flipped_probs) / 2.0).cpu().flatten().tolist()
 
110
 
111
  prediction_dict = {}
112
  for i, label in enumerate(labels):
 
81
  v2.Normalize(mean=[0.6007, 0.5679, 0.5206], std=[0.2411, 0.2392, 0.2479])
82
  ])
83
 
84
+ # tta_transform = v2.Compose([
85
+ # v2.ToImage(),
86
+ # v2.Resize((IMAGE_SIZE, IMAGE_SIZE)),
87
+ # v2.RandomHorizontalFlip(p=1.0),
88
+ # v2.ToDtype(torch.float32, scale=True),
89
+ # v2.Normalize(mean=[0.6007, 0.5679, 0.5206], std=[0.2411, 0.2392, 0.2479]),
90
+ # ])
91
 
92
  efficientnet = models.efficientnet_v2_l(weights='EfficientNet_V2_L_Weights.DEFAULT')
93
  efficientnet.classifier = new_layers
 
100
  img = img.convert('RGB')
101
 
102
  base_input = transform(img).unsqueeze(0).to(device)
103
+ # flipped_input = tta_transform(img).unsqueeze(0).to(device)
104
 
105
  with torch.no_grad():
106
  base_probs = torch.sigmoid(efficientnet(base_input))
107
+ # flipped_probs = torch.sigmoid(efficientnet(flipped_input))
108
 
109
+ predicted_probs = base_probs.cpu().flatten().tolist()
110
+ # predicted_probs = ((base_probs + flipped_probs) / 2.0).cpu().flatten().tolist()
111
 
112
  prediction_dict = {}
113
  for i, label in enumerate(labels):