eyupipler commited on
Commit
ddd78a0
·
verified ·
1 Parent(s): f1b96c8

Update Main Models/Vbai-1.1 Dementia/README.md

Browse files
Files changed (1) hide show
  1. Main Models/Vbai-1.1 Dementia/README.md +186 -184
Main Models/Vbai-1.1 Dementia/README.md CHANGED
@@ -1,185 +1,187 @@
1
- # Vbai-1.1 Dementia (11178564 parametre)
2
-
3
- ## "Vbai-1.1 Dementia" modeli, bir önceki modele göre daha fazla veriyle eğitilmiş olup üzerinde ince ayar yapılmış versiyonudur.
4
-
5
- ## -----------------------------------------------------------------------------------
6
-
7
- # Vbai-1.1 Dementia (11178564 parameters)
8
-
9
- ## The "Vbai-1.1 Dementia" model is a fine-tuned version of the previous model, trained with more data.
10
-
11
- # Kullanım / Usage
12
-
13
- ```python
14
- import torch
15
- import torch.nn as nn
16
- from torchvision import transforms, models
17
- from PIL import Image
18
- import matplotlib.pyplot as plt
19
- import os
20
- from torchsummary import summary
21
-
22
- device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
23
-
24
- model = models.resnet18(pretrained=False)
25
- num_ftrs = model.fc.in_features
26
- model.fc = nn.Linear(num_ftrs, 4)
27
- model.load_state_dict(torch.load('Vbai-1.1 Dementia/path'))
28
- model = model.to(device)
29
- model.eval()
30
- summary(model, (3, 224, 224))
31
-
32
- transform = transforms.Compose([
33
- transforms.Resize((224, 224)),
34
- transforms.ToTensor(),
35
- transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
36
- ])
37
-
38
- class_names = ['No Dementia', 'Mild Dementia', 'Avarage Dementia', 'Very Mild Dementia']
39
-
40
- def predict(image_path, model, transform):
41
- image = Image.open(image_path).convert('RGB')
42
- image = transform(image).unsqueeze(0).to(device)
43
- model.eval()
44
- with torch.no_grad():
45
- outputs = model(image)
46
- probs = torch.nn.functional.softmax(outputs, dim=1)
47
- _, preds = torch.max(outputs, 1)
48
- return preds.item(), probs[0][preds.item()].item()
49
-
50
- def show_image_with_prediction(image_path, prediction, confidence, class_names):
51
- image = Image.open(image_path)
52
- plt.imshow(image)
53
- plt.title(f"Prediction: {class_names[prediction]} (%{confidence * 100:.2f})")
54
- plt.axis('off')
55
- plt.show()
56
-
57
- test_image_path = 'image-path'
58
- prediction, confidence = predict(test_image_path, model, transform)
59
- print(f'Prediction: {class_names[prediction]} (%{confidence * 100})')
60
-
61
- show_image_with_prediction(test_image_path, prediction, confidence, class_names)
62
- ```
63
-
64
- # Uygulama / As App
65
-
66
- ```python
67
- import sys
68
- import torch
69
- import torch.nn as nn
70
- from torchvision import transforms, models
71
- from PIL import Image
72
- import matplotlib.pyplot as plt
73
- from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QLabel, QFileDialog, QVBoxLayout, QMessageBox
74
- from PyQt5.QtGui import QPixmap, QIcon
75
- from PyQt5.QtCore import Qt
76
-
77
- device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
78
-
79
- transform = transforms.Compose([
80
- transforms.Resize((224, 224)),
81
- transforms.ToTensor(),
82
- transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
83
- ])
84
-
85
- class_names = ['No Dementia', 'Mild Dementia', 'Avarage Dementia', 'Very Mild Dementia']
86
-
87
-
88
- class DementiaApp(QWidget):
89
- def __init__(self):
90
- super().__init__()
91
- self.initUI()
92
- self.model = None
93
- self.image_path = None
94
-
95
- def initUI(self):
96
- self.setWindowTitle('Prediction App by Neurazum')
97
- self.setWindowIcon(QIcon('C:/Users/eyupi/PycharmProjects/Neurazum/NeurAI/Assets/neurazumicon.ico'))
98
- self.setGeometry(2500, 300, 400, 200)
99
-
100
- self.loadModelButton = QPushButton('Upload Model', self)
101
- self.loadModelButton.clicked.connect(self.loadModel)
102
-
103
- self.loadImageButton = QPushButton('Upload Image', self)
104
- self.loadImageButton.clicked.connect(self.loadImage)
105
-
106
- self.predictButton = QPushButton('Make a Prediction', self)
107
- self.predictButton.clicked.connect(self.predict)
108
- self.predictButton.setEnabled(False)
109
-
110
- self.resultLabel = QLabel('', self)
111
- self.resultLabel.setAlignment(Qt.AlignCenter)
112
-
113
- self.imageLabel = QLabel('', self)
114
- self.imageLabel.setAlignment(Qt.AlignCenter)
115
-
116
- layout = QVBoxLayout()
117
- layout.addWidget(self.loadModelButton)
118
- layout.addWidget(self.loadImageButton)
119
- layout.addWidget(self.imageLabel)
120
- layout.addWidget(self.predictButton)
121
- layout.addWidget(self.resultLabel)
122
-
123
- self.setLayout(layout)
124
-
125
- def loadModel(self):
126
- options = QFileDialog.Options()
127
- fileName, _ = QFileDialog.getOpenFileName(self, "Choose Model Path", "",
128
- "PyTorch Model Files (*.pt);;All Files (*)", options=options)
129
- if fileName:
130
- self.model = models.resnet18(pretrained=False)
131
- num_ftrs = self.model.fc.in_features
132
- self.model.fc = nn.Linear(num_ftrs, 4)
133
- self.model.load_state_dict(torch.load(fileName, map_location=device))
134
- self.model = self.model.to(device)
135
- self.model.eval()
136
- self.predictButton.setEnabled(True)
137
- QMessageBox.information(self, "Model Uploaded", "Model successfully uploaded!")
138
-
139
- def loadImage(self):
140
- options = QFileDialog.Options()
141
- fileName, _ = QFileDialog.getOpenFileName(self, "Choose Image File", "",
142
- "Image Files (*.jpg *.jpeg *.png);;All Files (*)", options=options)
143
- if fileName:
144
- self.image_path = fileName
145
- pixmap = QPixmap(self.image_path)
146
- self.imageLabel.setPixmap(pixmap.scaled(224, 224, Qt.KeepAspectRatio))
147
-
148
- def predict(self):
149
- if self.model and self.image_path:
150
- prediction, confidence = self.predictImage(self.image_path, self.model, transform)
151
- self.resultLabel.setText(f'Prediction: {class_names[prediction]} (%{confidence * 100:.2f})')
152
- else:
153
- QMessageBox.warning(self, "Missing Information", "Model and picture must be uploaded.")
154
-
155
- def predictImage(self, image_path, model, transform):
156
- image = Image.open(image_path).convert('RGB')
157
- image = transform(image).unsqueeze(0).to(device)
158
- model.eval()
159
- with torch.no_grad():
160
- outputs = model(image)
161
- probs = torch.nn.functional.softmax(outputs, dim=1)
162
- _, preds = torch.max(outputs, 1)
163
- return preds.item(), probs[0][preds.item()].item()
164
-
165
-
166
- if __name__ == '__main__':
167
- app = QApplication(sys.argv)
168
- ex = DementiaApp()
169
- ex.show()
170
- sys.exit(app.exec_())
171
- ```
172
-
173
- # Python Sürümü / Python Version
174
-
175
- ### 3.9 <=> 3.13
176
-
177
- # Modüller / Modules
178
-
179
- ```bash
180
- matplotlib==3.8.0
181
- Pillow==10.0.1
182
- torch==2.3.1
183
- torchsummary==1.5.1
184
- torchvision==0.18.1
 
 
185
  ```
 
1
+ # Vbai-1.1 Dementia (11178564 parametre)
2
+
3
+ ## "Vbai-1.1 Dementia" modeli, bir önceki modele göre daha fazla veriyle eğitilmiş olup üzerinde ince ayar yapılmış versiyonudur.
4
+
5
+ ## -----------------------------------------------------------------------------------
6
+
7
+ # Vbai-1.1 Dementia (11178564 parameters)
8
+
9
+ ## The "Vbai-1.1 Dementia" model is a fine-tuned version of the previous model, trained with more data.
10
+
11
+ [![Vbai-1.1](https://img.youtube.com/vi/qUkId3S9W94/0.jpg)](https://youtu.be/wDfsFwusGQU)
12
+
13
+ # Kullanım / Usage
14
+
15
+ ```python
16
+ import torch
17
+ import torch.nn as nn
18
+ from torchvision import transforms, models
19
+ from PIL import Image
20
+ import matplotlib.pyplot as plt
21
+ import os
22
+ from torchsummary import summary
23
+
24
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
25
+
26
+ model = models.resnet18(pretrained=False)
27
+ num_ftrs = model.fc.in_features
28
+ model.fc = nn.Linear(num_ftrs, 4)
29
+ model.load_state_dict(torch.load('Vbai-1.1 Dementia/path'))
30
+ model = model.to(device)
31
+ model.eval()
32
+ summary(model, (3, 224, 224))
33
+
34
+ transform = transforms.Compose([
35
+ transforms.Resize((224, 224)),
36
+ transforms.ToTensor(),
37
+ transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
38
+ ])
39
+
40
+ class_names = ['No Dementia', 'Mild Dementia', 'Avarage Dementia', 'Very Mild Dementia']
41
+
42
+ def predict(image_path, model, transform):
43
+ image = Image.open(image_path).convert('RGB')
44
+ image = transform(image).unsqueeze(0).to(device)
45
+ model.eval()
46
+ with torch.no_grad():
47
+ outputs = model(image)
48
+ probs = torch.nn.functional.softmax(outputs, dim=1)
49
+ _, preds = torch.max(outputs, 1)
50
+ return preds.item(), probs[0][preds.item()].item()
51
+
52
+ def show_image_with_prediction(image_path, prediction, confidence, class_names):
53
+ image = Image.open(image_path)
54
+ plt.imshow(image)
55
+ plt.title(f"Prediction: {class_names[prediction]} (%{confidence * 100:.2f})")
56
+ plt.axis('off')
57
+ plt.show()
58
+
59
+ test_image_path = 'image-path'
60
+ prediction, confidence = predict(test_image_path, model, transform)
61
+ print(f'Prediction: {class_names[prediction]} (%{confidence * 100})')
62
+
63
+ show_image_with_prediction(test_image_path, prediction, confidence, class_names)
64
+ ```
65
+
66
+ # Uygulama / As App
67
+
68
+ ```python
69
+ import sys
70
+ import torch
71
+ import torch.nn as nn
72
+ from torchvision import transforms, models
73
+ from PIL import Image
74
+ import matplotlib.pyplot as plt
75
+ from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QLabel, QFileDialog, QVBoxLayout, QMessageBox
76
+ from PyQt5.QtGui import QPixmap, QIcon
77
+ from PyQt5.QtCore import Qt
78
+
79
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
80
+
81
+ transform = transforms.Compose([
82
+ transforms.Resize((224, 224)),
83
+ transforms.ToTensor(),
84
+ transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
85
+ ])
86
+
87
+ class_names = ['No Dementia', 'Mild Dementia', 'Avarage Dementia', 'Very Mild Dementia']
88
+
89
+
90
+ class DementiaApp(QWidget):
91
+ def __init__(self):
92
+ super().__init__()
93
+ self.initUI()
94
+ self.model = None
95
+ self.image_path = None
96
+
97
+ def initUI(self):
98
+ self.setWindowTitle('Prediction App by Neurazum')
99
+ self.setWindowIcon(QIcon('C:/Users/eyupi/PycharmProjects/Neurazum/NeurAI/Assets/neurazumicon.ico'))
100
+ self.setGeometry(2500, 300, 400, 200)
101
+
102
+ self.loadModelButton = QPushButton('Upload Model', self)
103
+ self.loadModelButton.clicked.connect(self.loadModel)
104
+
105
+ self.loadImageButton = QPushButton('Upload Image', self)
106
+ self.loadImageButton.clicked.connect(self.loadImage)
107
+
108
+ self.predictButton = QPushButton('Make a Prediction', self)
109
+ self.predictButton.clicked.connect(self.predict)
110
+ self.predictButton.setEnabled(False)
111
+
112
+ self.resultLabel = QLabel('', self)
113
+ self.resultLabel.setAlignment(Qt.AlignCenter)
114
+
115
+ self.imageLabel = QLabel('', self)
116
+ self.imageLabel.setAlignment(Qt.AlignCenter)
117
+
118
+ layout = QVBoxLayout()
119
+ layout.addWidget(self.loadModelButton)
120
+ layout.addWidget(self.loadImageButton)
121
+ layout.addWidget(self.imageLabel)
122
+ layout.addWidget(self.predictButton)
123
+ layout.addWidget(self.resultLabel)
124
+
125
+ self.setLayout(layout)
126
+
127
+ def loadModel(self):
128
+ options = QFileDialog.Options()
129
+ fileName, _ = QFileDialog.getOpenFileName(self, "Choose Model Path", "",
130
+ "PyTorch Model Files (*.pt);;All Files (*)", options=options)
131
+ if fileName:
132
+ self.model = models.resnet18(pretrained=False)
133
+ num_ftrs = self.model.fc.in_features
134
+ self.model.fc = nn.Linear(num_ftrs, 4)
135
+ self.model.load_state_dict(torch.load(fileName, map_location=device))
136
+ self.model = self.model.to(device)
137
+ self.model.eval()
138
+ self.predictButton.setEnabled(True)
139
+ QMessageBox.information(self, "Model Uploaded", "Model successfully uploaded!")
140
+
141
+ def loadImage(self):
142
+ options = QFileDialog.Options()
143
+ fileName, _ = QFileDialog.getOpenFileName(self, "Choose Image File", "",
144
+ "Image Files (*.jpg *.jpeg *.png);;All Files (*)", options=options)
145
+ if fileName:
146
+ self.image_path = fileName
147
+ pixmap = QPixmap(self.image_path)
148
+ self.imageLabel.setPixmap(pixmap.scaled(224, 224, Qt.KeepAspectRatio))
149
+
150
+ def predict(self):
151
+ if self.model and self.image_path:
152
+ prediction, confidence = self.predictImage(self.image_path, self.model, transform)
153
+ self.resultLabel.setText(f'Prediction: {class_names[prediction]} (%{confidence * 100:.2f})')
154
+ else:
155
+ QMessageBox.warning(self, "Missing Information", "Model and picture must be uploaded.")
156
+
157
+ def predictImage(self, image_path, model, transform):
158
+ image = Image.open(image_path).convert('RGB')
159
+ image = transform(image).unsqueeze(0).to(device)
160
+ model.eval()
161
+ with torch.no_grad():
162
+ outputs = model(image)
163
+ probs = torch.nn.functional.softmax(outputs, dim=1)
164
+ _, preds = torch.max(outputs, 1)
165
+ return preds.item(), probs[0][preds.item()].item()
166
+
167
+
168
+ if __name__ == '__main__':
169
+ app = QApplication(sys.argv)
170
+ ex = DementiaApp()
171
+ ex.show()
172
+ sys.exit(app.exec_())
173
+ ```
174
+
175
+ # Python Sürümü / Python Version
176
+
177
+ ### 3.9 <=> 3.13
178
+
179
+ # Modüller / Modules
180
+
181
+ ```bash
182
+ matplotlib==3.8.0
183
+ Pillow==10.0.1
184
+ torch==2.3.1
185
+ torchsummary==1.5.1
186
+ torchvision==0.18.1
187
  ```