skuma11 commited on
Commit
8ac53ea
·
verified ·
1 Parent(s): 8d17e1e

fix 2files

Browse files
Files changed (1) hide show
  1. app.py +4 -15
app.py CHANGED
@@ -26,8 +26,7 @@ class LargeNet(nn.Module):
26
  x = x.squeeze(1) # Flatten to [batch_size]
27
  return x
28
 
29
- ORIGINAL_LABELS = ['battery', 'biological', 'cardboard', 'glass', 'metal', 'paper', 'plastic']
30
- NEW_LABELS = ["paper", "cardboard", "other"]
31
 
32
  # Load best model
33
  net = LargeNet()
@@ -49,25 +48,15 @@ def predict(img):
49
  output = net(img_t)
50
  probs = F.softmax(output[0], dim=0)
51
 
52
- new_probs = [0.0, 0.0, 0.0]
53
- for original_label, prob in zip(ORIGINAL_LABELS, probs):
54
- if original_label == "paper":
55
- new_probs[0] = prob
56
- elif original_label == "cardboard":
57
- new_probs[1] = prob
58
- else:
59
- # Accumulate probabilities if the model do not predict "paper" or "cardboard"
60
- new_probs[2] += prob
61
-
62
- return {label: float(prob) for label, prob in zip(NEW_LABELS, new_probs)}
63
 
64
  # Create interface for uploading image and showing predictions
65
  iface = gr.Interface(
66
  fn=predict,
67
  inputs=gr.Image(type="pil"),
68
- outputs=gr.Label(num_top_classes=3),
69
  title="Garbage Classifier",
70
- description="Classify images into Paper, Cardboard, or Other."
71
  )
72
 
73
  if __name__ == "__main__":
 
26
  x = x.squeeze(1) # Flatten to [batch_size]
27
  return x
28
 
29
+ LABELS = ['battery', 'biological', 'cardboard', 'glass', 'metal', 'paper', 'plastic']
 
30
 
31
  # Load best model
32
  net = LargeNet()
 
48
  output = net(img_t)
49
  probs = F.softmax(output[0], dim=0)
50
 
51
+ return {label: float(prob) for label, prob in zip(LABELS, probs)}
 
 
 
 
 
 
 
 
 
 
52
 
53
  # Create interface for uploading image and showing predictions
54
  iface = gr.Interface(
55
  fn=predict,
56
  inputs=gr.Image(type="pil"),
57
+ outputs=gr.Label(num_top_classes=7),
58
  title="Garbage Classifier",
59
+ description="Classify garbage images into Battery, Biological, Cardboard, Glass', Metal, Paper, or Plastic"
60
  )
61
 
62
  if __name__ == "__main__":