tirendazakademi commited on
Commit
2f49426
1 Parent(s): 6297db0
Files changed (5) hide show
  1. app.py +47 -0
  2. image-1.jpg +0 -0
  3. image-2.jpg +0 -0
  4. model-data_comet-torch-model.pth +3 -0
  5. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from torch import nn
3
+ from torchvision import transforms
4
+ from torchvision.models import resnet50, ResNet50_Weights
5
+ import gradio as gr
6
+
7
+ title = "Cancer Detection"
8
+ description = "Image classification with histopathologic images"
9
+ article = "<p style='text-align: center'><a href='https://github.com/TirendazAcademy'>Github Repo</a></p>"
10
+
11
+ # The model architecture
12
+ class ImageClassifier(nn.Module):
13
+ def __init__(self):
14
+ super().__init__()
15
+ self.pretrain_model = resnet50(weights=ResNet50_Weights.DEFAULT)
16
+ self.pretrain_model.eval()
17
+ for param in self.pretrain_model.parameters():
18
+ param.requires_grad = False
19
+ self.pretrain_model.fc = nn.Sequential(
20
+ nn.Linear(self.pretrain_model.fc.in_features, 1024),
21
+ nn.ReLU(),
22
+ nn.Dropout(),
23
+ nn.Linear(1024,2)
24
+ )
25
+ def forward(self, input):
26
+ output=self.pretrain_model(input)
27
+ return output
28
+
29
+ model = ImageClassifier()
30
+ model.load_state_dict(torch.load('comet-torch-model.pth'))
31
+
32
+ def predict(inp):
33
+ image_transform = transforms.Compose([ transforms.Resize(size=(224,224)), transforms.ToTensor()])
34
+ labels = ['normal', 'cancer']
35
+ inp = image_transform(inp).unsqueeze(dim=0)
36
+ with torch.no_grad():
37
+ prediction = torch.nn.functional.softmax(model(inp))
38
+ confidences = {labels[i]: float(prediction.squeeze()[i]) for i in range(len(labels))}
39
+ return confidences
40
+
41
+ gr.Interface(fn=predict,
42
+ inputs=gr.Image(type="pil"),
43
+ outputs=gr.Label(num_top_classes=2),
44
+ title=title,
45
+ description=description,
46
+ article=article,
47
+ examples=['image-1.jpg', 'image-2.jpg']).launch()
image-1.jpg ADDED
image-2.jpg ADDED
model-data_comet-torch-model.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:470a1b9450a673fe0aaab6d15987ca23800fbfbdd22e8c9cf21d2555b91b1756
3
+ size 102753277
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ torch
2
+ torchvision