Professional Documents
Culture Documents
A PROJECT REPORT
Submitted by
BHARANIDHARAN M 731119205003
BHARANITHARAN B 731119205004
of
BACHELOR OF TECHNOLOGY
IN
INFORMATION TECHNOLOGY
MAY 2023
ANNA UNIVERSITY : CHENNAI 600 025
BONAFIDE CERTIFICATE
and helped us to complete our project successfully. Our whole hearted thanks to
Engineering, Erode, for his constant encouragement and moral support during the
College of Engineering, Erode, for furnishing every essential facility for doing
our project and also for her valuable suggestion and constant guidance
College of Engineering, Erode, for her valuable help and guidance throughout the
project. We thank our class advisor and all other staff members of our department
The accuracy obtained using VGG16, VGG19, and DenseNet201 models was
93.4%, 95.2%, and 94.7%, respectively.The high accuracy achieved by the
proposed approaches demonstrates their potential for accurate and early
detection of these lung diseases. Comparing the three architectures,
DenseNet201 demonstrated the highest performance for all three disease
classifications.
i
TABLE OF CONTENTS
ABSTRACT i
LIST OF FIGURES iv
LIST OF TABLES V
LIST OF ABBREVIATIONS vi
1 INTRODUCTION 1
1.1 LUNG DISEASE CLASSIFICATION 1
1.3 CNN 2
1.5 VGG16 5
1.6 VGG19 5
1.7 DENSENET 5
2 LITERATURE REVIEW 6
2.1 EXISTING SYSTEMS 6
3 REQUIREMENTS SPECIFICATION 8
3.1 HARDWARE REQUIREMENTS 8
3.3.1 PYTHON 8
ii
4 SYSTEM IMPLEMENTATION 11
4.1 PROPOSED SYSTEM DESIGN 11
4.2 MODELS 11
4.2.1 VGG16 11
4.2.2 VGG19 12
4.2.3 DENSENET 14
6 CONCLUSION 25
7 APPENDIX 1 26
8 APPENDIX 2 36
9 REFERENCES 40
iii
LIST OF FIGURES
iv
LIST OF TABLES
v
LIST OF ABBREVIATIONS
DL - DEEP LEARNING
CNN - CONVOLUTIONAL NEURAL NETWORK
vi
CHAPTER 1
INTRODUCTION
The use of deep learning models for lung disease classification has
several advantages, including increased accuracy, reduced human error,
and the ability to automate the process of diagnosis, potentially leading to
faster and more efficient treatment. These models have the potential to
assist medical professionals in making more accurate and timely diagnoses
of lung diseases, leading to better patient outcomes.
1
1.2 DEEP LEARNING
Deep learning (also known as deep structured learning) is part of a
broader family of machine learning methods based on artificial neural
networks with representation learning. Learning can be supervised, semi-
supervised or unsupervised.
Deep-learning architectures such as deep neural networks, deep belief
networks, deep reinforcement learning, recurrent neural networks,
convolutional neural networks and Transformers have been applied to
fields including computer vision, speech recognition, natural language
processing, machine translation, bio informatics, drug design, medical
image analysis, climate science, material inspection and board game
programs, where they have produced results comparable to and in some
cases surpassing human expert performance.
1.3 CNN
2
2. ReLU Layer: This layer applies the rectified linear activation
function element-wise to the output of the convolutional layer. It
introduces non-
linearity into the network and helps in learning
complex representations.
3. Pooling Layer: This layer reduces the spatial dimensions of the
feature maps by applying a downsampling operation. Common types
of pooling are max pooling and average pooling.
4. Fully Connected Layer: This layer connects all the neurons of the
previous layer to the next layer, similar to a traditional neural
network.
It transforms the feature maps into a vector of class scores.
5. Softmax Layer: This layer applies the softmax function to the output
of the last fully connected layer to produce a probability distribution
over the classes.
These layers are typically stacked on top of each other to form a deep
neural network. The CNN architecture can be modified and customized for
specific tasks by varying the number of layers, the filter sizes, the pooling
sizes, and other hyperparameters.
In CNN, there are various architecture models present. From those models
we are using three types of architecture models such as VGG16,VGG19
and DenseNet models.
3
FIGURE 1.1 CNN LAYER
4
1.5 VGG16
1.7 DENSENET
5
CHAPTER 2
LITERATURE REVIEW
The existing system for lung disease classification using chest X-ray
images involves manual interpretation by radiologists, which can be
timeconsuming and subject to human error. Traditional computer-aided
diagnosis systems for lung diseases use handcrafted features and classifiers,
which may not generalize well to different datasets and may require
domain-specific knowledge. Recent advances in deep learning have led to
the development of end-to-end deep neural networks, which can
automatically learn the features and classifiers from raw data, making them
more suitable for lung disease classification tasks.
6
However, deep learning models require a large amount of labeled
data for training, which can be a challenge in the medical domain due to the
limited availability of annotated medical images. Therefore, existing
systems for lung disease classification using deep learning typically rely on
pre-trained models that are fine-tuned on small datasets of medical images.
While these systems have shown promising results, they still face
challenges in terms of generalization to different datasets and
interpretability of the learned features.
Lastly, the existing system for lung disease classification using chest Xray
images is limited to binary or multi-class classification tasks, where the
input image is classified into a single disease category or normal. However,
in reality, patients may have multiple co-existing diseases or require more
detailed diagnoses. Therefore, there is a need for more sophisticated deep
learning models that can perform multi-label or
7
CHAPTER 3
OS : Windows 10
Tool : Jupyter notebook
Language : Python
3.3.1 PYTHON
8
new features such as list comprehensions, cycle-detecting garbage
collection, reference counting, and Unicode support. Python 3.0, released
in 2008, was a major revision that is not completely backward compatible
with earlier versions. Python 2 was discontinued with version 2.7.18 in
2020. Python consistently ranks as one of the most popular programming
languages.
9
• Python can be treated in a procedural way, an object-oriented
way or a functional way.
10
CHAPTER 4
SYSTEM IMPLEMENTATION
4.2 MODELS
4.2.1 VGG16
The VGG16 architecture is characterized by its simplicity and the use of small
filters, which allow for a deeper network while keeping the number of
parameters relatively low. The architecture also uses max pooling layers after
11
each set of convolutional layers, which helps to reduce the spatial
dimensionality of the feature maps and makes the network more robust to small
spatial translations.
VGG16 has been widely used as a pre-trained model for various computer
vision tasks, such as image classification, object detection, and
segmentation. The pre-trained weights are available in many deep learning
libraries, such as TensorFlow, Keras, and PyTorch, which makes it easy to
use VGG16 for transfer learning.
4.2.2 VGG19
12
The use of X-ray pictures to identify specific forms of chest ailments
is demonstrated using a VGG19 followed by a CNN model. The model is
depicted in detail in Fig. 4.2. X-ray chest pictures with a dimension of 224
* 224 * 3 were used as input data for our model. The VGG19 pre-trained
model is followed by three CNN blocks during the feature extraction stage.
VGG19 is designed to provide great accuracy for large-scale image
applications. The feature architecture was used that comprised 19 CNN
with 3 convolution filters and 1 stride. Multiple deep learning models were
merged with the VGG19 to improve picture categorization accuracy. A
convolution layer with a ReLU as an activation function is included in each
CNN block. Following these three CNN blocks, a batch normalization and
a max-pooling layer were applied, which were then followed by a dropout
layer, as indicated in Fig. 4.2.
In the feature extraction step, the output was turned into a one
dimensional data vector, which was then used as an input in the
classification stage after being modified through the flattening layer. The
remaining components of the categorization step are comprised of three
thick layers, each having 512, 256, and 128 neurons. It is a thick layer with
six neurons and the SoftMax activation function that generates the final
classification output. This layer is responsible for classifying the output
image into one of the six chest diseases classes: pneumonia, tuberculosis,
lung cancer, and lung opacity. A total of 24,622,470 model parameters are
span into two categories. First were the trainable parameters (24,622,342),
which were revised throughout the training process. The best value for
these parameters was required to ensure the training accuracy. The second
category was the untrainable parameters (128), which were those that did
not change at the time of training.
13
Figure 4.2 VGG19 Architecture
4.2.3 DENSENET Model
14
input layer
ADVANTAGES
The advantages of our project include real time images can be given
as the input and the deduction accuracy is high with time taken to execute
the code is significantly less compared to the previous existing models.
15
4.3.2 DATA SET
16
Figure 4.6 Covid X-ray image
17
4.3.3 DATASET PRE-PROCESSING
After normalizing each pixel in the image to the interval [0,1], all
images were transformed to array data representation.
The preprocessing steps can vary depending on the type of data and the
specific task. It is important to carefully preprocess the data to ensure that
the neural network can learn from it effectively and make accurate
predictions.
18
CHAPTER 5
5.1.1 ACCURACY
This project proposed a viable deep learning strategy for the lung
disease classification which revealed good performance under various
conditions like light variation, orientation variation and scale variation. The
project introduces CNN which includes improvements in architecture, data
augmentation and refinements in parametrical values. An innovative
customized dataset was obtained in real time for the training and validation
of the submitted CNN model. Besides data augmentation, several
adaptations to the conventional CNN model served as testimonials for the
CNN tactic’s accurate, efficient, fast detection, and learning capability of a
decent amount of lung diseases. The observed performance improvements
were validated by notable reductions in miss rate and false positive rate.
The proffered CNN model outperformed both the Fast R-CNN and Mask
RCNN models in terms of precision, recall and F-measure.
19
Figure 5.1 Accuracy of VGG16
20
ALGORITHM ACCURACY
VGG16 95
VGG19 96
DENSENET 97
21
Epoch Training loss Training Validation loss Validation
Accuracy Accuracy
5.1.2 PRECISION
Precision = TP/TP+FP
5.1.3 RECALL
Recall=TP/TP+FN
22
5.1.4 F1-SCORE
F1-Score=2*(P*R)/(P+R)
PERFORMANCE PARAMETERS
120
95 97 96 98 95 97
100 93 92 93
Pe
rce 80
nta
ge 60
40
20
0
Precision Recall F1-Score
Performance Metrics
23
5.1.5 SENSITIVITY AND SPECIFICITY
24
CHAPTER 6
CONCLUSION
The use of CNN algorithm was best in terms of efficiency and low
latency. The usage of proposed algorithm improves the high level of
identification of the lung diseases from the image this can lead to the
further enhancement of the project with other countries . Diagnosis can be
further enhanced Generally Convolutional Neural Networks are used in
deep learning for most of the image classification projects. There are
various architectures used along with Convolution Neural Networks. CNN
is one of the main sign classification algorithms that detect the using
bounding boxes. By using the CNN algorithm we get the accuracy of 98%
while the SVM algorithm provides 87 percentage in this comparison is
based on the article representation on the analysis of certain literature
survey real time execution may differ.
The scope for this future enhancement is that major other machine
learning and deep learning algorithms can be fused together to provide a
better accuracy with the large amount of data set with low latency better
than our current scenario
25
APPENDIX 1
26
matplotlib.pyplot as mat import argparse import
Augmentor import cv2 import os import pandas as
pd import shutil import random from sklearn.cluster
import KMeans from sklearn import metrics from
scipy.spatial.distance import cdist from imutils
import paths import matplotlib.pyplot as plt import
pandas as pd import numpy as np import random
import shutil import cv2 import os
normal = "E:/lung_52/dataset/train/NORMAL"
PNEUMONIA =
"E:/lung_52/dataset/train/PNEUMONIA" covid =
"E:/lung_52/dataset/train/COVID19" tuberculosis =
"E:/lung_52/dataset/train/TURBERCULOSIS"
# Path list dir_normal = os.listdir(normal)
dir_PNEUMONIA =
os.listdir(PNEUMONIA)
dir_covid = os.listdir(covid)
dir_tubercl =
os.listdir(tuberculosis)
mat.figure(figsize=(16,
12)) for i in range(6):
ran = random.choice((1, 30)) normal1 =
[os.path.join(normal, f) for f in dir_normal[ran : ran + 1]]
rand = random.choice(normal1) mat.subplot(3, 3, i + 1)
img = mat.imread(rand) mat.imshow(img, cmap="gray")
mat.axis(False) mat.title("Normal X-ray images")
mat.show()
27
mat.figure(figsize=(16, 12)) for i in
range(6): ran = random.choice((1, 30))
covid1 =
[os.path.join(covid, f) for f in dir_covid[ran : ran + 1]]
rand = random.choice(covid1) mat.subplot(3, 3, i + 1)
img = mat.imread(rand) mat.imshow(img,
cmap="gray") mat.axis(False) mat.title("Covid X-ray
images") mat.show()
imagePaths =
list(paths.list_images(normal)) data =
28
[] labels = [] for imagePath in
imagePaths: label = 0
# 224x224 pixels while ignoring aspect ratio
image = cv2.imread(imagePath) image =
cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image = cv2.resize(image, (224, 224)) # update
the data and labels lists, respectively
data.append(image) labels.append(label) data =
np.array(data) / 255 labels = np.array(labels)
imagePaths1 =
list(paths.list_images(covid)) data1 = []
labels1 = [] for imagePath in
imagePaths1:
label1 = 1
# 224x224 pixels while ignoring aspect ratio
image = cv2.imread(imagePath) image =
cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image = cv2.resize(image, (224, 224))
data1.append(image) labels1.append(label1)
imagePaths2 =
list(paths.list_images(PNEUMONIA)) data2 =
[] labels2 = [] for imagePath in imagePaths2:
label2 = 2 image = cv2.imread(imagePath) #
image = cv2.cvtColor(image,
29
cv2.COLOR_BGR2RGB) image =
cv2.resize(image,
(224, 224)) data2.append(image)
labels2.append(label2) data2 = np.array(data2) / 255
labels2 = np.array(labels2)
imagePaths2 =
list(paths.list_images(tuberculosis)) data2 =
[] labels2 = [] for imagePath in
imagePaths2:
label2 = 2 image = cv2.imread(imagePath)
image = cv2.cvtColor(image,
cv2.COLOR_BGR2RGB) image = cv2.resize(image,
(224, 224)) data2.append(image)
labels2.append(label2) data3 = np.array(data2) / 255
labels3 = np.array(labels2)
label = to_categorical(label)
label
30
(trainX, valX, trainY, valY) = train_test_split( trainX,
trainY, test_size=0.20,
random_state=42
)
INIT_LR = 1e-3
EPOCHS = 15
BS = 8
# baseModel = VGG16(weights="imagenet",
include_top=False,input_tensor=Input(shape=(224, 224, 3)))
# baseModel = VGG19(weights="imagenet",
include_top=False,input_tensor=Input(shape=(224, 224, 3)))
baseModel = DenseNet201(
weights="imagenet", include_top=False, input_tensor=Input(shape=(224,
224, 3))
)
callbacks = [
EarlyStopping(monitor="val_loss", patience=8),
31
ModelCheckpoint(filepath="best_model.h5", monitor="val_loss",
save_best_only=True),
]
acc = H.history["accuracy"]
loss = H.history["loss"]
val_loss =
H.history["val_loss"] val_acc =
H.history["val_accuracy"]
epochs = range(len(H.epoch))
title1 = "Accuracy vs
Validation Accuracy" leg1 = ["Acc",
"Val_acc"] title2 = "Loss vs Val_loss"
leg2 = ["Loss",
"Val_loss"]
32
def plot(epochs, acc, val_acc, leg, title):
mat.plot(epochs, acc)
mat.plot(epochs, val_acc)
mat.title(title) mat.legend(leg)
mat.xlabel("epochs")
cm = confusion_matrix(testY.argmax(axis=1), predIdxs)
sns.set(font_scale=1) # for label size sns.heatmap(cm,
cmap="Blues", annot=True, annot_kws={"size": 12}) # font siz
plt.ylabel("Actual") plt.xlabel("Predicted") plt.figure(figsize=(16,
12)) total = sum(sum(cm)) acc = (cm[0, 0] + cm[1, 1]) / total
sensitivity = cm[0, 0] / (cm[0, 0] + cm[0, 1]) specificity = cm[1, 1] /
(cm[1, 0] + cm[1, 1])
# show the confusion matrix, accuracy, sensitivity,
and specificity print("acc: {:.4f}".format(acc))
33
print("sensitivity: {:.4f}".format(sensitivity))
print("specificity: {:.4f}".format(specificity))
ypred = model.predict(testX)
total = 0 accurate = 0
accurateindex = []
wrongindex = []
total += 1
print(
"Total-test-data;", total,
"\taccurately-predicted-data:",
accurate,
"\t wrongly-predicted-data: ", total -
accurate,
)
print("Accuracy:", round(accurate / total * 100, 3), "%")
label = {0: "Normal", 1: "Covid", 2:
"Pneumonia"} imidx =
random.sample(accurateindex, k=9) # replace
with 'wrongindex'
34
nrows = 3 ncols = 3 fig, ax = plt.subplots(nrows, ncols,
sharex=True, sharey=True, figsize=(15, 12))
plt.show()
35
APPENDIX 2
36
EPOCHS
37
ACCURACY
OUTPUT
38
39
REFERENCES
1. Chen, H., Li, W. and Yang, X., 2020. A whale optimization algorithm with
chaos mechanism based on quasi-opposition for global optimization
problems. Expert Systems with Applications, 158, p.113612.
2. Tuncer, T., Dogan, S. and Akbal, E., 2019. A novel local senary pattern
based epilepsy diagnosis system using EEG signals. Australasian Physical &
Engineering Sciences in Medicine, 42, pp.939948.
3. Khan, A., Khan, S.H., Saif, M., Batool, A., Sohail, A. and Waleed Khan, M.,
2023. A Survey of Deep Learning Techniques for the Analysis of COVID-
19 and their usability for Detecting Omicron. Journal of Experimental &
Theoretical Artificial Intelligence, pp.1-43.
4. Jackson, P., McIntosh, L., Hofman, M.S., Kong, G. and Hicks, R.J., 2020.
Rapid multiexponential curve fitting algorithm for voxel‐based targeted
radionuclide dosimetry. Medical Physics, 47(9), pp.4332-4339.
5. Li, C., Dong, D., Li, L., Gong, W., Li, X., Bai, Y., Wang, M., Hu, Z., Zha,
Y. and Tian, J., 2020. Classification of severe and critical covid-19 using
deep learning and radiomics. IEEE journal of biomedical and health
informatics, 24(12), pp.3585-3594.
40
6. Shi, J., Yuan, X., Elhoseny, M. and Yuan, X., 2020. Weakly supervised deep
learning for objects detection from images. In Urban Intelligence and
Applications: Proceedings of ICUIA 2019 (pp. 231-242). Springer
International Publishing.
7. Dansana, D., Kumar, R., Bhattacharjee, A., Hemanth, D.J., Gupta, D.,
Khanna, A. and Castillo, O., 2020. Early diagnosis of COVID-19-affected
patients based on X-ray and computed tomography images using deep
learning algorithm. Soft computing, pp.1-9.
8. Ravi, V., Narasimhan, H., Chakraborty, C. and Pham, T.D., 2022. Deep
learning-based metaclassifier approach for COVID-19 classification using
CT scan and chest X-ray images. Multimedia systems, 28(4), pp.1401-1415.
10. Gupta, A., Gupta, S. and Katarya, R., 2021. InstaCovNet-19: A deep
learning classification model for the detection of COVID-19 patients using
Chest X-ray. Applied Soft Computing, 99, p.106859.
11. Thakur, S. and Kumar, A., 2021. X-ray and CT-scan-based automated
detection and classification of covid-19 using convolutional neural networks
(CNN). Biomedical Signal Processing and Control, 69, p.102920.
41
12. Monowar, Khan Fashee, Md Al Mehedi Hasan, and Jungpil Shin. "Lung
opacity classification with convolutional neural networks using chest x-
rays." In 2020 11th International Conference on Electrical and Computer
Engineering (ICECE), pp. 169-172. IEEE, 2020.
42