mayonaise1979 commited on
Commit
9b256f0
·
verified ·
1 Parent(s): 7d96a8b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoImageProcessor, AutoModelForImageClassification
3
+ from PIL import Image
4
+ import torch
5
+
6
+
7
+ path = "./"
8
+ model = AutoModelForImageClassification.from_pretrained(path)
9
+ processor = AutoImageProcessor.from_pretrained(path)
10
+
11
+ 알려줌)
12
+ def classify_image(image):
13
+
14
+ inputs = processor(images=image, return_tensors="pt")
15
+
16
+ # 모델 예측
17
+ with torch.no_grad():
18
+ outputs = model(**inputs)
19
+
20
+ # 확률(Softmax) 계산
21
+ probs = torch.nn.functional.softmax(outputs.logits, dim=-1)[0]
22
+
23
+
24
+ labels = model.config.id2label
25
+ result = {labels[i]: float(probs[i]) for i in range(len(labels))}
26
+
27
+ return result
28
+
29
+
30
+ iface = gr.Interface(
31
+ fn=classify_image,
32
+ inputs=gr.Image(type="pil"),
33
+ outputs=gr.Label(num_top_classes=3),
34
+ title="재활용품분류기 🤖",
35
+ description=" precision recall f1-score support
36
+
37
+ 0_Pet 0.85 0.88 0.86 218
38
+ 1_Can 0.95 0.89 0.92 283
39
+ 2_Glass 0.93 0.86 0.89 221
40
+ 3_Paper 0.90 0.98 0.94 315
41
+ 4_Plastic 0.91 0.93 0.92 308
42
+ 5_Vinyl 0.95 0.94 0.94 282
43
+
44
+ accuracy 0.92 1627
45
+ macro avg 0.91 0.91 0.91 1627
46
+ weighted avg 0.92 0.92 0.91 1627
47
+ "
48
+ )
49
+
50
+ # 실행
51
+ iface.launch()