Yenes commited on
Commit
aab0186
·
verified ·
1 Parent(s): cd60e83

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +63 -0
  2. conv_model.pth +3 -0
  3. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import torch.nn as nn
3
+ import torchvision.transforms as transforms
4
+ import gradio as gr
5
+ from PIL import Image
6
+
7
+ class ConvModel(nn.Module):
8
+ def __init__(self):
9
+ super().__init__()
10
+ self.cnn1 = nn.Sequential(
11
+ nn.Conv2d(3, 16, kernel_size=3, padding=1),
12
+ nn.ReLU(),
13
+ nn.MaxPool2d(2)
14
+ )
15
+ self.cnn2 = nn.Sequential(
16
+ nn.Conv2d(16, 32, kernel_size=3, padding=1),
17
+ nn.ReLU(),
18
+ nn.MaxPool2d(2)
19
+ )
20
+ self.fc = nn.Sequential(
21
+ nn.Flatten(),
22
+ nn.Linear(32 * 56 * 56, 2)
23
+ )
24
+
25
+ def forward(self, x):
26
+ x = self.cnn1(x)
27
+ x = self.cnn2(x)
28
+ x = self.fc(x)
29
+ return x
30
+
31
+ model = ConvModel()
32
+ model.load_state_dict(torch.load("conv_model.pth", map_location="cpu"))
33
+ model.eval()
34
+
35
+ class_names=['NORMAL', 'PNEUMONIA']
36
+
37
+ transform = transforms.Compose([
38
+ transforms.Resize((224, 224)),
39
+ transforms.ToTensor(),
40
+ transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
41
+ ])
42
+
43
+ def predict(img):
44
+ img = transform(img).unsqueeze(0)
45
+ with torch.inference_mode():
46
+ pred_probs = torch.softmax(model(img), dim=1)
47
+
48
+ pred_labels_and_probs = {class_names[i]: float(pred_probs[0][i]) for i in range(len(class_names))}
49
+ return pred_labels_and_probs
50
+
51
+
52
+ title = "Zatürre Bulucu"
53
+ description = "Gönderilen fotoğrafa göre Sağlıklı mı yoksa Zatürre mi olduğunu tahmin eder."
54
+
55
+ demo = gr.Interface(
56
+ fn=predict,
57
+ inputs=gr.Image(type="pil"),
58
+ outputs=[gr.Label(num_top_classes=2, label="Predictions")],
59
+ title=title,
60
+ description=description
61
+ )
62
+
63
+ demo.launch(debug=False, share=True)
conv_model.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e6285af0ba99bb78b83f8bdef57250483b1737d9d3abcc62e1641ef19f0c3fb7
3
+ size 825652
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ torch
2
+ gradio
3
+ torchvision
4
+ pillow