-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
60 lines (52 loc) · 1.97 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import sys
from PyQt5 import uic
from PyQt5.QtWidgets import QMainWindow, QApplication, QDialog, QFileDialog
from keras.models import load_model
from keras_preprocessing import image
from PyQt5.QtGui import QPixmap
from PyQt5.QtCore import Qt
import numpy as np
class Diagnotica(QMainWindow):
def __init__(self):
super().__init__()
text = "Diagnotica X"
self.setWindowTitle(text)
self.setFixedSize(898, 797)
uic.loadUi("gui_app.ui", self)
self.btnDiagnosis.clicked.connect(lambda: self.loadModel(self.txtPath.text()))
self.btnBrowser.clicked.connect(self.browseFIle)
def loadModel(self, file):
# Cargar el modelo
modelo_cargado = load_model('model/model_densenet201.h5')
#print("El modelo se ha cargado: ", modelo_cargado)
img_a_predecir = image.load_img(file, target_size=(224, 224))
test_image = image.img_to_array(img_a_predecir)
test_image = np.expand_dims(test_image, axis=0)
test_image = test_image.astype('float32')
test_image /= 255
result = modelo_cargado.predict(test_image)[0][0]
prediccion = 1 if (result >= 0.5) else 0
CLASSES = ['Normal', 'Covid19+']
ClassPred = CLASSES[prediccion]
ClassProb = result * 100
# Mostrar los resultados en las etiquetas
self.lblClass.setText(ClassPred)
self.lblScore.setText(format(ClassProb, '.2f'))
global path
def browseFIle(self):
filename = QFileDialog.getOpenFileName(self, 'Open file', 'C:', '*.jpg')
self.txtPath.setText(filename[0])
path = filename[0]
self.showX(path)
# Mostrar la imagen en el cuadro
# Show the image in the box
def showX(self, path):
pixmap = QPixmap(path)
pixmap_resized = pixmap.scaled(481, 431)
self.xray.setPixmap(pixmap_resized)
if __name__ == '__main__':
#Iniciar app
app = QApplication(sys.argv)
GUI = Diagnotica()
GUI.show()
sys.exit(app.exec())