In my last blog, I showed you guys how to create a neural network that can predict an NBA player’s performance on any given night. Although it was a very fun project, I was unable to test it on a regular-season due to COVID-19. Considering the global pandemic, I was really hesitant about starting a new project as this year can be considered an outlier in not just sports, but also for financial and sentiment analysis. With this problem, I started searching through Kaggle and came across a data set filled with X-ray images of both normal and non-normal lungs (Pneumonia). This intrigued me, so I continued searching for more databases and found more labeled photos. I was able to combine two datasets into a single folder (no duplicates), totaling to 6,000 images. Using these images, I will show you how to create a Convolutional Neural Network that can predict whether a person has Pneumonia with a ~98% accuracy (test set).
Datasets
Although we see images with color and shapes, in their most basic level they are lists of numbers, each number corresponding to an RGB value which is then processed by your computer to show you the image. Convolutional neural networks have gained traction in image processing because they are able to split the RGB array into (1x1), (2x2), or (3x3) pixels in order to learn patterns within an image
Image Taken From Van Hiep Phung, et. al
All the code shown below can be found on my GitHub*
The dataset with the .csv was too large to upload to my GitHub, so instead, I made it public on my GoogleDrive.
from keras.models import Sequentialfrom keras.layers import Dense, Dropout, Flatten from keras.layers import Conv2D, MaxPooling2D from keras import regularizersfrom sklearn.preprocessing import LabelEncoder, OneHotEncoderfrom keras.preprocessing import image import numpy as np import pandas as pd import matplotlib.pyplot as pltfrom sklearn.model_selection import train_test_splitimport osfrom tensorflow.image import rgb_to_grayscaleimport picklefrom sklearn.metrics import confusion_matrix, accuracy_score, recall_score, precision_score, f1_scorefrom tensorflow.keras.optimizers import Adamimport tensorflow as tf
Package Import
Packages
#aimedicalimaging #machine-learning #medicine #python #ai