Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 18732

How can my UI application correctly display an image and predict if a person has pneumonia or not?

$
0
0

Im doing a Computer Vision project that uses deep learning for a pneumonia detector. I ran the training part with no issue but when i try to test with my UI , the application closes after i upload a picture to the ui to predict if the person has pneumonia or not. This message returns Process finished with exit code -1073740791 (0xC0000409).

I want the UI to successfully predict if the person does indeed have pneumonia or not. But so far i am stuck with the problem of the model exiting after a picture is uploadedThis is my UI code:import warningsfrom PIL import Image, ImageEnhancewarnings.filterwarnings('ignore')import tensorflow as tffrom keras.models import load_modelfrom keras.applications.vgg16 import preprocess_inputimport numpy as npfrom keras.preprocessing import image

from PyQt5 import QtCore, QtGui, QtWidgetsfrom PyQt5.QtWidgets import QFileDialog, QMessageBoxfrom PyQt5.QtGui import QMovie

from win32com.client import Dispatch

def speak(str1):speak = Dispatch(("SAPI.SpVoice"))speak.Speak(str1)

class Ui_MainWindow(object):def setupUi(self, MainWindow):MainWindow.setObjectName("MainWindow")MainWindow.resize(695, 609)self.centralwidget = QtWidgets.QWidget(MainWindow)self.centralwidget.setObjectName("centralwidget")self.frame = QtWidgets.QFrame(self.centralwidget)self.frame.setGeometry(QtCore.QRect(0, 0, 701, 611))self.frame.setStyleSheet("background-color: #035874;")self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)self.frame.setFrameShadow(QtWidgets.QFrame.Raised)self.frame.setObjectName("frame")self.label = QtWidgets.QLabel(self.frame)self.label.setGeometry(QtCore.QRect(80, -60, 541, 561))self.label.setText("")self.gif = QMovie("picture.gif")self.label.setMovie(self.gif)self.gif.start()self.label.setObjectName("label")self.label_2 = QtWidgets.QLabel(self.frame)self.label_2.setGeometry(QtCore.QRect(80, 430, 591, 41))font = QtGui.QFont()font.setPointSize(24)font.setBold(True)font.setWeight(75)self.label_2.setFont(font)self.label_2.setObjectName("label_2")self.pushButton = QtWidgets.QPushButton(self.frame)self.pushButton.setGeometry(QtCore.QRect(30, 530, 201, 31))font = QtGui.QFont()font.setPointSize(12)font.setBold(True)font.setWeight(75)icon = QtGui.QIcon()icon.addPixmap(QtGui.QPixmap("patient.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)MainWindow.setWindowIcon(icon)self.pushButton.setFont(font)self.pushButton.setStyleSheet("QPushButton{\n""border-radius: 10px;\n"" background-color:#DF582C;\n""}\n""QPushButton:hover {\n"" background-color: #7D93E0;\n""}")self.pushButton.setObjectName("pushButton")self.pushButton_2 = QtWidgets.QPushButton(self.frame)self.pushButton_2.setGeometry(QtCore.QRect(450, 530, 201, 31))font = QtGui.QFont()font.setPointSize(12)font.setBold(True)font.setWeight(75)self.pushButton_2.setFont(font)self.pushButton_2.setStyleSheet("QPushButton{\n""border-radius: 10px;\n"" background-color:#DF582C;\n""}\n""QPushButton:hover {\n"" background-color: #7D93E0;\n""}")self.pushButton_2.setObjectName("pushButton_2")

    # New QLabel to display the uploaded image    self.label_3 = QtWidgets.QLabel(self.frame)    self.label_3.setGeometry(QtCore.QRect(250, 10, 400, 400))    self.label_3.setText("")    self.label_3.setObjectName("label_3")    MainWindow.setCentralWidget(self.centralwidget)    self.retranslateUi(MainWindow)    QtCore.QMetaObject.connectSlotsByName(MainWindow)    self.pushButton.clicked.connect(self.upload_image)    self.pushButton_2.clicked.connect(self.predict_result)def retranslateUi(self, MainWindow):    _translate = QtCore.QCoreApplication.translate    MainWindow.setWindowTitle(_translate("MainWindow", "PNEUMONIA Detection App"))    self.label.setToolTip(_translate("MainWindow", "<html><head/><body><p><img src=\":/newPrefix/picture.gif\"/></p></body></html>"))    self.label_2.setText(_translate("MainWindow", "Chest X-ray PNEUMONIA Detection"))    self.pushButton.setText(_translate("MainWindow", "Upload Image"))    self.pushButton_2.setText(_translate("MainWindow", "Prediction"))def upload_image(self):    filename, _ = QFileDialog.getOpenFileName()    if filename:        path = str(filename)        print(path)        self.img_path = path        self.model = load_model('chest_xray.h5')        # Display the uploaded image        pixmap = QtGui.QPixmap(path)        pixmap = pixmap.scaledToWidth(400)  # Adjust the width as needed        self.label_3.setPixmap(pixmap)def predict_result(self):    if hasattr(self, 'img_path'):        img_file = image.load_img(self.img_path, target_size=(224, 224))        x = image.img_to_array(img_file)        x = np.expand_dims(x, axis=0)        img_data = preprocess_input(x)        result = self.model.predict(img_data)        print(result)        if result[0][0] > 0.5:            print("Result is Normal")            speak("Result is Normal")        else:            print("Affected By PNEUMONIA")            speak("Affected By PNEUMONIA")    else:        QMessageBox.warning(self.frame, 'Warning', 'Please upload an image first.')

if name == "main":import sysapp = QtWidgets.QApplication(sys.argv)MainWindow = QtWidgets.QMainWindow()ui = Ui_MainWindow()ui.setupUi(MainWindow)MainWindow.show()sys.exit(app.exec_())This message returns and the program stops altogether: Process finished with exit code -1073740791 (0xC0000409).


Viewing all articles
Browse latest Browse all 18732

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>