TangYiJay commited on
Commit
5c030c4
·
verified ·
1 Parent(s): 637a6ad
Files changed (1) hide show
  1. app.py +7 -11
app.py CHANGED
@@ -3,12 +3,10 @@ import gradio as gr
3
  from transformers import AutoModelForImageClassification, AutoImageProcessor
4
  from PIL import Image
5
  import torch
6
- from collections import Counter
7
 
8
  MODEL_LIST = [
9
  "prithivMLmods/Trash-Net",
10
- "yangy50/garbage-classification",
11
- "eunoiawiira/vgg-realwaste-classification"
12
  ]
13
 
14
  models = []
@@ -46,26 +44,24 @@ def classify_image(image: Image.Image):
46
  except Exception as e:
47
  results[model_name] = f"error:{e}"
48
 
49
- # 格式化输出每个模型的结果
50
  results_text = "\n".join([f"{name}: {label}" for name, label in results.items()])
51
 
52
- # 投票法计算最终标签
53
- valid_labels = [lbl for lbl in results.values() if not lbl.startswith("error")]
54
- final_label = Counter(valid_labels).most_common(1)[0][0] if valid_labels else "Unknown"
55
- results_text += f"\n\nFinal Label (voting): {final_label}"
56
  return results_text
57
 
58
  iface = gr.Interface(
59
  fn=classify_image,
60
  inputs=gr.Image(type="pil", label="Upload Image"),
61
  outputs=[gr.Textbox(label="Model Predictions")],
62
- title="Multi-Model Trash Classification",
63
  description=(
64
  "Upload an image, and the following models will classify it:\n"
65
  "1. prithivMLmods/Trash-Net\n"
66
  "2. yangy50/garbage-classification\n"
67
- "3. eunoiawiira/vgg-realwaste-classification\n"
68
- "The final label is determined by majority vote."
69
  )
70
  )
71
 
 
3
  from transformers import AutoModelForImageClassification, AutoImageProcessor
4
  from PIL import Image
5
  import torch
 
6
 
7
  MODEL_LIST = [
8
  "prithivMLmods/Trash-Net",
9
+ "yangy50/garbage-classification"
 
10
  ]
11
 
12
  models = []
 
44
  except Exception as e:
45
  results[model_name] = f"error:{e}"
46
 
47
+ # 输出每个模型的结果
48
  results_text = "\n".join([f"{name}: {label}" for name, label in results.items()])
49
 
50
+ # 以 yangy50/garbage-classification 为最终结果
51
+ final_label = results.get("yangy50/garbage-classification", "Unknown")
52
+ results_text += f"\n\nFinal Label (base yangy50): {final_label}"
 
53
  return results_text
54
 
55
  iface = gr.Interface(
56
  fn=classify_image,
57
  inputs=gr.Image(type="pil", label="Upload Image"),
58
  outputs=[gr.Textbox(label="Model Predictions")],
59
+ title="Trash Classification",
60
  description=(
61
  "Upload an image, and the following models will classify it:\n"
62
  "1. prithivMLmods/Trash-Net\n"
63
  "2. yangy50/garbage-classification\n"
64
+ "The final label is based on yangy50/garbage-classification."
 
65
  )
66
  )
67