spuun commited on
Commit
bdcbadf
·
verified ·
1 Parent(s): 402e450

fix: maybe

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -34,7 +34,7 @@ class WasteClassifier:
34
  img_tensor = self.transform(image).unsqueeze(0).to(self.device)
35
 
36
  with torch.no_grad():
37
- outputs, seg_mask = self.model(img_tensor) # Handle both outputs
38
  probabilities = torch.nn.functional.softmax(outputs, dim=1)
39
 
40
  probs = probabilities[0].cpu().numpy()
@@ -42,9 +42,11 @@ class WasteClassifier:
42
  confidence = np.max(probs)
43
 
44
  # Process segmentation mask
 
45
  seg_mask = (
46
- torch.sigmoid(seg_mask)[0, 0].cpu().numpy().astype(np.float32)
47
- ) # Get first image, first channel
 
48
  # seg_mask = (seg_mask >= 0.2).astype(np.float32) # Threshold at 0.2
49
 
50
  # Resize mask back to original image size
@@ -77,7 +79,7 @@ def interface(classifier):
77
  mask = results["segmentation_mask"]
78
 
79
  overlay = image_np.copy()
80
- overlay[mask < 0.5] = overlay[mask < 0.5] * 0
81
 
82
  output_str = f"Predicted Class: {results['predicted_class']}\n"
83
  output_str += f"Confidence: {results['confidence']*100:.2f}%\n\n"
 
34
  img_tensor = self.transform(image).unsqueeze(0).to(self.device)
35
 
36
  with torch.no_grad():
37
+ outputs, seg_mask_logits = self.model(img_tensor) # Handle both outputs
38
  probabilities = torch.nn.functional.softmax(outputs, dim=1)
39
 
40
  probs = probabilities[0].cpu().numpy()
 
42
  confidence = np.max(probs)
43
 
44
  # Process segmentation mask
45
+ seg_mask_probs = torch.sigmoid(seg_mask_logits)
46
  seg_mask = (
47
+ seg_mask_probs[0, 0].cpu().numpy().astype(np.float32)
48
+ )
49
+ # Get first image, first channel
50
  # seg_mask = (seg_mask >= 0.2).astype(np.float32) # Threshold at 0.2
51
 
52
  # Resize mask back to original image size
 
79
  mask = results["segmentation_mask"]
80
 
81
  overlay = image_np.copy()
82
+ overlay[mask < 0.2] = overlay[mask < 0.2] * 0
83
 
84
  output_str = f"Predicted Class: {results['predicted_class']}\n"
85
  output_str += f"Confidence: {results['confidence']*100:.2f}%\n\n"