Yenes commited on
Commit
5fa307a
·
verified ·
1 Parent(s): e4972cd

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +42 -0
  2. requirements.txt +4 -0
  3. transfermodel.pth +3 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import torch.nn as nn
3
+ import torchvision
4
+ import gradio as gr
5
+ from PIL import Image
6
+ from torchvision import transforms
7
+
8
+ weights = torchvision.models.DenseNet169_Weights.DEFAULT
9
+ dense_tranform = weights.transforms()
10
+
11
+ transfermodel = torchvision.models.densenet169(weights = weights)
12
+ transfermodel.classifier = nn.Sequential(nn.Linear(1664, 800), nn.ReLU(),
13
+ nn.Linear(800, 400), nn.ReLU(),
14
+ nn.Linear(400, 2))
15
+ transfermodel.load_state_dict(torch.load('transfermodel.pth'))
16
+
17
+ class_names=['NORMAL', 'PNEUMONIA']
18
+
19
+ def predict(img):
20
+ img = dense_tranform(img).unsqueeze(0)
21
+
22
+ transfermodel.eval()
23
+ transfermodel.to("cpu")
24
+ with torch.inference_mode():
25
+ pred_probs = torch.softmax(transfermodel(img), dim=1)
26
+
27
+ pred_labels_and_probs = {class_names[i]: float(pred_probs[0][i]) for i in range(len(class_names))}
28
+ return pred_labels_and_probs
29
+
30
+
31
+ title = "Zatürre Bulucu"
32
+ description = "Gönderilen fotoğrafa göre Sağlıklı mı yoksa Zatürre mi olduğunu tahmin eder."
33
+
34
+ demo = gr.Interface(
35
+ fn=predict,
36
+ inputs=gr.Image(type="pil"),
37
+ outputs=[gr.Label(num_top_classes=2, label="Predictions")],
38
+ title=title,
39
+ description=description
40
+ )
41
+
42
+ demo.launch(debug=False, share=True)
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ torch
2
+ gradio
3
+ torchvision
4
+ pillow
transfermodel.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:955ec03a73eee282488340f1c9c46bbc45721caf93f558babe378f0031fe064c
3
+ size 57555145