adnankarim commited on
Commit
728b0e2
·
verified ·
1 Parent(s): abd4aca

Upload 6 files

Browse files
Files changed (5) hide show
  1. app.py +42 -0
  2. carrots.jpg +0 -0
  3. model_transfer.pt +3 -0
  4. requirements.txt +5 -0
  5. tissue.jpg +0 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from torchvision import transforms
3
+ import gradio as gr
4
+ import torch
5
+ from efficientnet_pytorch import EfficientNet
6
+
7
+ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
8
+
9
+ model = EfficientNet.from_name('efficientnet-b0')
10
+
11
+ in_features = model._fc.in_features
12
+ model._fc = torch.nn.Linear(in_features, 2)
13
+ model.load_state_dict(torch.load('model_transfer.pt'))
14
+
15
+ model.to(device)
16
+
17
+ model.eval()
18
+
19
+
20
+ labels = ["Organic Waste","Recyclable Waste"]
21
+
22
+ def predict(inp):
23
+ inp = transforms.ToTensor()(inp).unsqueeze(0)
24
+
25
+ inp = inp.to(device)
26
+
27
+ with torch.no_grad():
28
+ prediction = torch.nn.functional.softmax(model(inp)[0], dim=0)
29
+
30
+ confidences = {labels[i]: float(prediction[i]) for i in range(len(prediction))}
31
+
32
+ return confidences
33
+
34
+
35
+ gr.Interface(
36
+ fn=predict,
37
+ inputs=gr.components.Image(type="pil"),
38
+ outputs=gr.components.Label(num_top_classes=2),
39
+ examples=["tissue.jpg", "carrots.jpg"],
40
+ theme="default",
41
+ css=".footer{display:none !important}"
42
+ ).launch()
carrots.jpg ADDED
model_transfer.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:669c0f182354391b318a80f17014f07373dadb7d4f955e23c6632739202433cb
3
+ size 16335318
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ torch
2
+ torchvision
3
+ efficientnet_pytorch
4
+ gradio
5
+ Pillow
tissue.jpg ADDED