SlideShare a Scribd company logo
CADI AYYAD UNIVERSITY
HIGH SCHOOL OF TECHNOLOGY SAFI
COMPUTER SCIENCE
Final REPORT
Lung cancer Detection
Realized by: Tutored by: Supervised by:
ESSADEQ Ayoub GAMAL Mohammed Mr. ALAOUI FDILI Othman
BOUSSARDI Mohammed
AIT BENAISSA Mohamed-hamza
GASSIR Chaimae
YEAR 2020-2021
UCA - SAFI
2
Summary
Abstract............................................................................................................................................................................6
Part 1: Theorical Concepts..............................................................................................................................................7
I. Artificiel intelligence ................................................................................................................................................8
II. Machine learning : ....................................................................................................................................................8
1. Definition:
2. Different types of machine learning
2.1. Supervised machine learning algorithms ..........................................................................................................9
2.2. Unsupervised machine learning algorithms......................................................................................................9
III. Deep Learning:....................................................................................................................................................10
1. Definition
2. Neural Network:
3. The Perceptron:
4. Quantifying Loss:
5. Some types of deep learning algorithms:
IV. Computer vision..................................................................................................................................................16
1. Definition
2. How Does Computer Vision Work? 
V. Object Detection 
1. Difference between Object recognition, Object localization, object detection and object segmentation: 
2. R-CNN Model Family (Object Detection algorithms)
2.1 CNN Part:..........................................................................................................................................................21
2.2 R-CNN:.............................................................................................................................................................23
2.3 Fast R-CNN.......................................................................................................................................................25
2.4 Faster R-CNN ...................................................................................................................................................26
2.5 Comparison between R-CNN, Fast R-CNN and Faster R-CNN ......................................................................27
Part 2: Application of Deep learning in Lung Cancer Detection..............................................................................28
I. Lung cancer.............................................................................................................................................................29
1. Lung nodules
2. Non-small cell lung cancer 
3. Small cell lung cancer
4. Stages of lung cancer 
II. Frameworks and Library’s......................................................................................................................................30
1. OpenCV 
UCA - SAFI
3
2. TensorFlow 
3. Keras 
III. Dataset.................................................................................................................................................................31
1. LUNA16 Labeled 3D - Lung Nodule Analysis Dataset 2016 
2. Kaggle 3D dataset: Data science Bowl 2017 
IV. Lung Cancer Models...........................................................................................................................................32
1. First model 
• Theorical Side .................................................................................................................................................33
1. DataSet
2. Architecture
2.1. Image preprocessing .......................................................................................................................................35
2.2 CNN 1 (Lung vs Colon)..................................................................................................................................35
2.3. CNN 2 (Lung Benign vs. Malignant)..............................................................................................................35
2.4. CNN 4 (Lung SCC vs. ACA)..........................................................................................................................36
3. Comparison between the 3 CNNs...................................................................................................................36
• Practical Side ..................................................................................................................................................37
1. Tools 
- Google Colab ..................................................................................................................................................37
2. Implementation 
2.1. Training...........................................................................................................................................................37
a. Defining the CNNs..........................................................................................................................................37
b. Training function.............................................................................................................................................39
c. The training Results ........................................................................................................................................40
2.2. Predicting
a. Image and Model Loader................................................................................................................................43
b. Image classification.........................................................................................................................................44
c. Model prediction.............................................................................................................................................44
2.3. Model study 
2. Second model
• Theorical Side .................................................................................................................................................47
1. DataSet
2. Architecture
3. How we manage to use VGG16
• Practical Side ..................................................................................................................................................49
• Implementation 
1. Import VGG 16 from Keras
2. model summary
3. Predicting using the saved model
UCA - SAFI
4
4. Model Output
Part 3: Desktop Application. ........................................................................................................................................52
I. Tools .......................................................................................................................................................................53
• Definition
II. Front-end.................................................................................................................................................................53
• Graphic Interface
1. Choose the image type
2. Upload an image 
3. Output 
4. Send Email message
5. Reset button 
III. Back-end .............................................................................................................................................................56
• Model Integration
1. Select -processing button ................................................................................................................................56
2. Send info button: 
Part 4: Project Plan. ......................................................................................................................................................59
Introduction.....................................................................................................................................................................60
I. Gantt chart...............................................................................................................................................................60
II. Project review .........................................................................................................................................................61
Conclusion ......................................................................................................................................................................61
General Conclusion.......................................................................................................................................................61
Figures Table.................................................................................................................................................................62
Bibliography..................................................................................................................................................................64
UCA - SAFI
5
Dedication:
To our dear parents, sisters, brothers, friends and to all teachers who helped us in this project,
For their patience, encouragement and commitment.
Acknowledgement:
We would like to express our sincere gratitude to my supervisor Mr. ALAOUI FDILI Othmane for
providing his valuable guidance, comments and suggestions throughout the course of the project. We would
specially thank Mr. GAMAL Mohamed, to his availability and unconditional patience all the time he has
devoted to the direction of this project. It is thanks to your support that we were able to carry out this work at
term.
My strong gratitude to Ms. MOUNIR Ilham, the manager of the “Computer science” and the professors
who are members of the jury for having accepted to judge this work, I'd like to express my gratitude to
everyone who has helped us finish this project in various ways.
UCA - SAFI
6
Abstract
Humans are quite good at detecting and identifying items in images. With little conscious thought, the
human visual system can accomplish complicated tasks such as distinguishing multiple objects and detecting
impediments. We can now quickly train computers to detect and identify many items inside an image because
to the availability of enormous amounts of data, faster GPUs, and improved algorithms known as object
detection.
Lung cancer is one of the most lethal cancers because it can spread to other parts of the body, causing
damage to them as well. Lung cancer was detected in 225,000 people in the United States alone in 2017. It
resulted in a total health-care expense of $12 billion. One of the most effective ways to fight cancer is to discover
it early. It significantly improves the patient's chances of survival. By studying nodules, a doctor can determine
whether or not this scan is malignant. Humans, on the other hand, can evaluate nodules larger than 7mm in
diameter, and doctors can sometimes have a patient wait to see if the nodule will develop or not, as it will be
a harmless nodule if it does not. And this gives a chance for a nodule to grow more undetected by the human
eye.
In this project, we will explore terms such as object detection, AI, machine learning, deep learning,
loss function for object detection and localization, and finally explores object detection algorithm known as
“Convolutional Neural Network” (CNN) that will help us to distinguish between a lung cancer and a safe lung.
Figure 1: Number of Publications in Object Detection
UCA - SAFI
7
Part 1: Theorical Concepts
UCA - SAFI
8
I. Artificiel intelligence
Artificial intelligence (AI) is an area of computer science that aims to reproduce or imitate human
intelligence in machines so that they can accomplish activities that would normally need human understanding,
such as decision making, language processing, and visual perception. Planning, learning, reasoning, problem
solving, and decision making are some of the programmed tasks of AI systems.
Artificial intelligence systems are powered by algorithms, which include machine learning, deep
learning, and rules, are used to fuel artificial intelligence systems. Machine learning algorithms use statistical
approaches to give computer data to AI systems, allowing them to learn. Machine learning allows AI systems
to improve their performance over time without having to be coded expressly for it.
There are two types of AI:
- Type 1:
• Weak or Narrow AI: Machines aren't very intelligent; they can only perform one task.
• Strong AI: Machines, like humans, can reason and complete tasks independently.
- Type 2:
• Reactive Machines: That machine has no memory and reacts only in the present instant.
• Limited memory: Past experiences can be used by systems to help them make better decisions
in the future.
• Theory of mind: People's emotions can be understood by machines.
• Self-awareness: Machine that is extremely intelligent.
II. Machine learning :
1. Definition:
Machine Learning is a branch of Artificial Intelligence that allows computers to learn and improve on
their own without having to be explicitly programmed. It's worth mentioning that all machine learning
techniques fall under the umbrella of Artificial Intelligence. As a result, machine learning is concerned with
the creation of computer programs that can access data and learn for themselves.
UCA - SAFI
9
The learning process starts with observations or data, such as examples, direct experience, or instruction,
so that we can seek for patterns in data and make better decisions in the future based on the examples we
provide. Machine learning algorithms use historical data as input to predict new output values.
2. Different types of machine learning
There are different types of Machine Learning algorithms. Generally, Machine learning algorithms are
often categorized as supervised or unsupervised.
2.1. Supervised machine learning algorithms
Can use labeled examples to apply what they've learnt in the past fresh data in order to anticipate
future events. As a result, the learning algorithm is already aware of the aim. The learning algorithm creates a
function to generate predictions about the output values based on the study of a known training dataset. After
enough training, the system can provide targets for any new input. The learning algorithm can also compare
its output to the correct and detect faults, allowing the model to be updated as needed.
Examples of Supervised Learning algorithms: Regression, Decision Tree and Random Forest etc.
Supervised learning algorithms are good for the following tasks:
• Binary classification: Dividing data into two categories.
• Multi-class classification: Choosing between more than two types of answers.
• Regression modeling: Predicting continuous values.
- Classification Definition:
Classification is a type of supervised learning problem where the machine tries to predicts the
category or class of the given input data. For example - To classify movie into category like 'Horror', 'Comedy',
'Romantic' or predict whether a person has a particular disease or not.
2.2. Unsupervised machine learning algorithms
Unsupervised algorithms, on the other hand, are utilized when the information used to train is neither
classed nor labeled, or when there is no goal or outcome variable to predict. Unsupervised learning investigates
how computers might infer a function from unlabeled data to describe a hidden structure. The system doesn't
figure out the proper output, but it examines the data and can infer hidden structures from unlabeled data using
datasets. It is commonly used for segmenting clients into separate groups for special action, and it is utilized
for clustering population into separate groups. This method is currently in use in some fields, such as
cybersecurity.
UCA - SAFI
10
Examples of Unsupervised Learning: Apriori algorithm, K-means.
Unsupervised learning algorithms are good for the following tasks:
• Clustering: Splitting the data set into groups based on similarity.
• Anomaly detection: Identifying unusual data points in a dataset.
• Dimensionality Reduction: Reducing the number of variables in a data set.
III. Deep Learning:
1. Definition
Deep learning is an artificial intelligence (AI) function that simulates the human brain's processing
of data and creation of patterns for use in decision-making by utilizing large amounts of data that would
ordinarily take people decades to comprehend and process.
Deep learning is an artificial intelligence subset of machine learning that uses neural networks to learn
unsupervised from unstructured or unlabeled data. Deep neural learning or deep neural network are other
terms for the same thing.
→ Deep learning is based on Neural Networks, which are made up of an interconnected web of nodes
called neurons, with edges connecting them.
2. Neural Network:
Unlike others network like a social network a Neural Network is highly structured and comes in layers:
Figure 2: Neural Network
UCA - SAFI
11
The input layer is the first, the output layer is the last, and any levels in between are known as hidden
layers. The result of spinning classifiers together in a layered web is a neural network. Because every node in
the hidden and output layers has its own classifier, this is the case.
A node in the second layer, for example, receives its input from the input layer and activates its score
before passing it on to the next hidden layer for further activation. Until you get to the output layer, that is.
Figure 3: Neural Network (explanation)
This series of events starting from the input where each activation is sent to the next layer, is known
as forward propagation. Forward Propagation is a neural net’s way of classifying a set of inputs.
3. The Perceptron:
The structure building block of neural network it is much more like single neuron
Figure 4: Perceptron (Forward Propagation)
Information is passed forward through this single neuron. We can define a set of inputs, as shown in
the diagram above. These inputs are sent through a connection to the next node, where they are multiplied
by their respective weights and then added together. We take the single number sigma i=1--> n(Xi*Wi) as
UCA - SAFI
12
the result of that addition and send it through the Non-linear activation function “g” to get the final output y.
We also have a bias term that lets us shift the activation function to the left or right.
During this process (or in training) the weights for each connection will continuously be changing
until we reach optimized weights, as the model continues to learn from data.
We can see that the concept of perceptron written mathematically as a single equation you can actually
rewrite this in terms of linear Algebra matrix multiplication and dot product.
Examples of Activation Function:
Sigmoid function
Figure 5: Sigmoid Function
There are many types of activation functions:
Figure 6: Types of Activation Functions
UCA - SAFI
13
It outputs a number between 0 and 1 regardless of the activation value. Because probability must also
be between 0 and 1, it is suitable for issues and probability.
The Rectified Linear Unit (ReLU) activation function is quite common in modern deep neural
networks because of its simplicity. It is a piecewise linear function that is zero in the negative regime and
strictly the identify function in the positive regime.
Actually, the Purpose of activation function is to introduce non-linearities into the network.
Figure 7: Non-Linearities
Also, it allows us to actually deal with real data. This is really important in real life Because in the
real-world data is almost always non-linear.
Using a neural network with a linear activation function makes the problem really hard because no
matter how deep neural network is, you only be able to produce a single line of decision boundary.
Figure 8: Linear vs Non-Linear function
As you can see non-linearities makes neural nets extraordinary powerful.
As I said before the Perceptron is the main components of A Neural network.
If we want to define A multi Output neural network we can simply add another perceptron.
UCA - SAFI
14
Figure 9: Two Perceptron
Now we have two perceptron and two outputs each one is a normal Perceptron act exactly like single
perceptron. Because all the input are densely connected to all outputs, the layers are called Dense layers or
fully connected layers.
Weights
Weights represent the strength of the connection between the nodes. Each connection between two
nodes has an assigned weight.
How the weights are being optimized.
That’s going to depend on the optimization algorithm or the optimizer that you choose to use for your
model. The most known algorithm is the SGD (Stochastic gradient descent).
The goal of SGD is attempting to set models weight in order to minimize the loss function.
4. Quantifying Loss:
A loss function is used by machines to learn. It's a way of determining how well a certain algorithm
models the data. If the predictions are too far off from the actual findings, the loss function will return a very
large number. Loss function learns to lower prediction error over time with the help of some optimization
function.
The loss is the error or difference between what the network is predicting for the input versus the
desired output, and SGD will try to minimize this error to make our model as accurate as possible in its
predictions. There are many types of loss functions:
1. Quantifying loss:
The loss of our network measures the cost incurred from incorrect predictions
2. The empirical Loss:
The Empirical loss measure the total loss over our entire dataset
3. Binary Cross Entropy Loss:
Cross entropy loss can be used with models that output a probability between 0 and 1
UCA - SAFI
15
4. Mean Squared Error Loss:
Mean squared error loss can be used with regression models that output continuous real
numbers.
5. Some types of deep learning algorithms:
Deep learning models make use of several algorithms. While no one network is considered perfect,
some algorithms are better suited to perform specific tasks. To choose the right ones, it’s good to gain a solid
understanding of all primary algorithms such as:
- Convolutional Neural Networks (CNNs)
- Long Short-Term Memory Networks (LSTMs)
- Recurrent Neural Networks (RNNs)
But in our case, we will talk about the CNN algorithm:
CNN's, also known as ConvNets, consist of multiple layers and are mainly used for image processing
and object detection.
CNNs are widely used to identify satellite images, process medical images, forecast time series, and
detect anomalies.
We will discuss the details of the CNN algorithm in the object detection section, because of the huge
relation between Object detection algorithms and CNN.
Figure 10: DL, ML and AI
UCA - SAFI
16
IV. Computer vision
1. Definition
Computer vision is a branch of computer science that aims to replicate portions of the human vision
system's complexity, Computer vision is a field of artificial intelligence that trains computers to interpret and
understand the visual world.
Using digital images from cameras and videos and deep learning models, machines can accurately
identify and classify objects. One of the driving factors behind the growth of computer vision is the amount of
data we generate today that is then used to train and make computer vision better
Figure 11 : computer vision in Action
2. How Does Computer Vision Work?
The difficulty is that computers see only digital image representations. Humans can understand the
semantic meaning of an image, but machines rarely do. They detect pixels.
Thousands upon thousands of pixels make up an image. Three separate matrices for the three
components that represent the three fundamental colors: red, green, and blue will be contained in a single image
(RGB). A pixel can display other colors to the primary ones by combining different brightness levels of the
different primary colors (from 0 to 255).
A grayscale image, on the other hand, will only have one pixel matrix matching to the brightness of its
black and white colors.
UCA - SAFI
17
Figure 12 : pixels labeled with numbers from 0–255
In point of fact, pixel values are almost universally stored, at the hardware level, in a one-dimensional
array. For example, the data from the image above is stored in a manner similar to this long list of unsigned
chars:
Figure 13 : combinations of RGB values to create RGB images
That’s a lot of memory to require for one image, and a lot of pixels for an algorithm to iterate over. But
to train a model with meaningful accuracy especially when you’re talking about Deep Learning, you’d usually
need tens of thousands of images, and the more the merrier.
These pixel arrays are used by deep learning algorithms in computer vision to apply statistical learning
methods like linear regression, logistic regression, decision trees, and support vector machines (SVM). A
computer vision model can recognize edges, discover patterns, and eventually classify and recognize objects
in an image based on previously learnt patterns by examining the brightness values of a pixel and comparing
them to its nearby pixels. These methods frequently necessitate the model processing, storing values, and
learning patterns of comparable images containing the object of interest to be discovered and tracked in the
current, unknown image.
Computer vision has also been an important part of advances in health-tech. Computer vision
algorithms can help automate tasks such as detecting cancerous moles in skin images or finding symptoms in
x-ray and CT scans.
UCA - SAFI
18
V. Object Detection
Object detection is a computer vision and image processing technique for detecting and localizing objects,
pictures, and videos. To obtain relevant results, object detection algorithms often use machine learning or deep
learning. We can recognize and locate objects of interest in photos or video in a couple of seconds when we
stare at them. The purpose of object detection is to use a computer to imitate this intelligence.
Object detection is a key technology behind advanced driver assistance systems that enable cars to detect
driving lanes, obstacles or human to improve road safety. Object detection is also useful in applications such
as video surveillance or image retrieval systems.
1. Difference between Object recognition, Object localization, object detection
and object segmentation:
Figure 14 : Object recognition with deep learning
Object recognition is a method for identifying objects in photos and videos. It is one of the most
important machine learning and deep learning applications. The goal of this field is to educate machines to
recognize (understand) the content of an image in the same way that humans do.
Image classification takes an image as an input and outputs the classification label of that image
with some probability. For Example: An image of a cat can be classified as a class label “cat” or an image of
Dog can be classified as a class label “dog” with some probability.
Object localization helps us to identify the location of a single object in the given image and
indicate their location with a bounding box.
UCA - SAFI
19
Object Detection algorithms act as a combination of image classification and object
localization. It takes an image as input and generates one or more bounding boxes, each with a class label
attached. These algorithms are capable of dealing with multi-class classification and localisation, as well as
multiple occurrences of objects.
Figure 15 : Review of Deep Learning Algorithms for Object Detection
Object segmentation is a further extension of object detection where instances of recognized
objects are indicated by highlighting the specific pixels of the object instead of using bounding box.
Figure 16 : Object detection VS instance segmentation
Bounding box is an imaginary rectangle that serves as a point of reference for object
detection and creates a collision box for that object.
Conventions used to specify bounding boxes:
There are 2 main conventions followed when representing bounding boxes:
1. Specifying the box with respect to the coordinates of its top left, and the bottom right point.
UCA - SAFI
20
Figure 17 : Specifying the bounding box 1
• (x1, y1): Represents the x and y coordinates of the rectangle's top left corner.
• (x2, y2): Corresponds to the x and y coordinates of the rectangle's bottom right corner.
2. Specifying the box with respect to its center, and its width and height.
Figure 18 : Specifying the bounding box 2
• (xc, yc): Represents the x and y coordinates of the bounding box's center.
• Width: Represents the bounding box's width.
• Height: Represents the bounding box's height
• Confidence: This value shows the likelihood of finding the object in that box. A confidence level of 0.9,
for example, suggests that the object in the box is 90% likely to exist.
UCA - SAFI
21
Converting between the conventions:
Depending on our needs, we can switch between multiple ways of describing the bounding box.
- xc = ( x1 + x2 ) / 2
- yc = ( y1 + y2 ) / 2
- width = ( x2 — x1)
- height = (y2 — y1)
2. R-CNN Model Family (Object Detection algorithms)
A number of popular object detection models belong to the R-CNN family, which may stand for “Regions with
CNN Features” or “Region-Based Convolutional Neural Network”
This includes the techniques R-CNN, Fast R-CNN, and Faster-RCNN designed and demonstrated for
object localization and object recognition.
But before talking about all these techniques let’s talk deeply about CNN (Convolutional neural network)
because all those deep learning–based techniques use CNN.
2.1 CNN Part:
Feature Extraction and Convolution:
In this figure we have two image and in each image 1 represent white and -1 represent black. And We
want to classify the letter “X”.
Figure 19 : Matrix of pixel values of X
We want our model to basically compare images of a piece of an X piece by piece. And the really
important pieces that I should look for are exactly the features.
UCA - SAFI
22
Figure 20 : Feature Extraction
The idea of convolution is actually to preserve the relationship between pixel by learning image
features in small little patches of image data. to do this we need to perform an element multiplication between
the filter image.
Figure 21 : convolution operator
Sliding window is a rectangular region of fixed width and height that “slides” across an image.
For each of these windows, we would normally take the window region and apply an image classifier to
determine if the window has an object that interests us.
CNN Part
Now we’ve gotten the mathematical foundation of convolutions. we can start how to utilize these
operations of convolutions to actually build Neural network for computer vision tasks.
UCA - SAFI
23
CNNs or Convolutional Neural Network designed specifically for the task of image classification. The
goal here is to learn features directly from the image data. There are three main component and operations
that are core to a CNNs.
Figure 22 : CNN for classification
We have seen the future of non-linearity in the activation part.
We use the Pooling Layer to reduce the size of the representation to speed up the computation as well
as make some of the features it detects a bit more robust.
For example:
We have a 4x4 input and we want to apply the Max Pooling and the output will be a 2x2 output. The
way we do that Is simply by taking the 4x4 input and break it into different regions and then the output will
just be the mask from the correspondingly.
Figure 23 : Max pooling
This is the reasoning behind it. Because we're taking a 2x2 region, the Hyperparameters in the image
are just the filter size, f = 2 and s = 2 because we're striping by two.
The main reason people choose max pooling is that it has been proven to function in several studies.
The average can be used in place of the maximum value.
2.2 R-CNN:
R-CNN was proposed by Ross Girshick in 2014. It may have been one of the first large and successful
application of convolutional neural networks to the problem of object localization, detection, and segmentation.
UCA - SAFI
24
It improves the quality of candidate bounding boxes and to take a deep architecture to extract high-level
features.
Figure 24 : R-CNN architecture
As we see in the above figure that RCNN architecture is divided into three modules:
- Regional Proposal Generation: For each image, RCNN generates 2k region proposals using selective
search (Computer vision technique).
- Feature Extractor: Using a deep convolutional neural network, extract features from each candidate
region.
- Classification and localization: The collected features are input into an SVM, which classifies them
into one of several categories.
- Selective Search is an item identification region proposal algorithm. It's made to be quick and have a
high recall rate. It works by generating hierarchical groupings of comparable regions based on color, texture,
size, and form similarity.
Figure 25 : Selective search
Recall and Precision:
UCA - SAFI
25
Figure 26 : Precision & Recall
Precision: a metric that measures how accurate your predictions are. To put it another way, the percentage
of your predictions that are correct.
Recall: Indicates how well you remember all of the positive. In our top K predictions, for example, we
can locate 80% of the possible positive cases.
Here are their mathematically definition:
Figure 27 : precision and recall formula
Limitations of this techniques:
A downside of the approach is that it is slow, requiring a CNN-based feature extraction pass on each
of the candidate regions generated by the region proposal algorithm. This is a problem as the paper describes
the model operating upon approximately 2,000 proposed regions per image at test-time.
2.3 Fast R-CNN
The R-CNN algorithm is comparable to this approach. We feed the CNN the input image instead of the
region proposals to build a convolutional feature map. We take the region of proposals from the convolutional
UCA - SAFI
26
feature map, warp them into squares, and then use a RoI pooling layer to restructure them into a fixed size so
they can be fed into a fully connected layer. To predict the class of the proposed region as well as the bounding
box offset values from the RoI feature vector, we use a SoftMax layer.
The reason “Fast R-CNN” is faster than R-CNN is because you don’t have to feed 2000 region proposals
to the convolutional neural network every time. Instead, the convolution operation is done only once per image
and a feature map is generated from it.
Figure 28 : fast R-CNN architecture
2.4 Faster R-CNN
Both of the above algorithms (R-CNN & Fast R-CNN) uses selective search to find out the region
proposals. But, it’s not the case for the Faster R-CNN algorithm.
Similar to Fast R-CNN, the image is input into a convolutional network, which outputs a convolutional
feature map. Rather than using a selective search approach on the feature map to find region proposals, the
RPN (Region Proposal Network), a Convolutional neural network that suggests regions and the sort of object
to consider in the area, is used to predict region suggestions. After that, a RoI pooling layer is used to categorize
the image within the proposed region and estimate the bounding box offset values, and the projected region
proposals are reshaped.
UCA - SAFI
27
Figure 29 : faster R-CNN architecture
2.5 Comparison between R-CNN, Fast R-CNN and Faster R-CNN
Figure 30 : R-CNN VS Fast R-CNN VS Faster R-CNN
The mean average precision (mAP) is used to evaluate object detection algorithms like R-CNN. mAP is a
common metric for measuring object detection accuracy; it compares the ground-truth bounding box to the
detected box and provides a score. The higher the score, the better the model's detection accuracy.
UCA - SAFI
28
Part 2: Application of Deep learning in Lung
Cancer Detection.
UCA - SAFI
29
I. Lung cancer
The most common types of lung cancer include lung nodules, non-small cell lung cancer and small
cell lung cancer.
1. Lung nodules
Lung nodules are tiny tissue tumors found in the lungs. They could be benign, precancerous, or
metastatic tumors from other parts of the body. A larger nodule has a higher chance of being malignant than
a smaller one.
2. Non-small cell lung cancer
The most frequent type of lung cancer is non-small cell lung cancer. It takes longer to grow and
disseminate than small cell lung cancer. Non-small cell lung cancer is divided into three types based on the
type of cells seen in the tumor:
▪ Adenocarcinoma
▪ Large cell carcinomas
▪ Squamous cell carcinoma
3. Small cell lung cancer
Cigarette smoking is responsible for nearly all occurrences of small cell lung cancer. It is a rapidly
spreading malignancy that spreads more faster than other types of lung cancer. Small cell lung cancer is
divided into two types:
▪ Small cell carcinoma
▪ Combined small cell carcinoma
4. Stages of lung cancer
Cancer stages tell how far the cancer has spread and help guide treatment. Non-small cell lung cancer
for example has four main stages:
▪ Stage 1: Cancer is found in the lung, but it has not spread outside the lung.
▪ Stage 2: Cancer is found in the lung and nearby lymph nodes.
▪ Stage 3: Cancer is in the lung and lymph nodes in the middle of the chest.
▪ Stage 3A: Cancer is found in lymph nodes, but only on the same side of the chest where cancer
first started growing.
UCA - SAFI
30
▪ Stage 3B: Cancer has spread to lymph nodes on the opposite side of the chest or to lymph nodes
above the collarbone.
▪ Stage 4: Cancer has spread to both lungs, into the area around the lungs, or to distant organs.
II. Frameworks and Library’s
In this section, we will quote the most common libraries and frameworks used to detect cancer and
especially lung cancer detection, based on the researches and project referenced in the introduction.
1. OpenCV
OpenCV (Open-Source Computer Vision) is a library of programming functions mainly aimed at real-
time computer vision which is written in C/C++ and has been abstracted to interface with C++, Python and
Java. This is a powerful tool when working with images and has a lot of tools regarding image data
manipulation, features extraction, etc.…
Figure 31 : OpenCV
2. TensorFlow
TensorFlow is an open-source library for numerical computation Created by the Google Brain team
and has been used for research on machine learning and deep Learning. What makes Tensorflow great is its
ability to be flexible to deploy computations on different devices such as CPU’s and GPU’s.
Figure 32 : TensorFlow
3. Keras
Keras is a deep learning framework written in python and built on top of Theano or TensorFlow.
Compared to the other frameworks Keras is more minimalist.
UCA - SAFI
31
Figure 33 : Keras
4. PyTorch
PyTorch is a machine learning library for Python based on the Torch library, used for applications such
as computer vision and natural language processing. The open-source software was developed by the artificial
intelligence teams at FaceBook Inc. in 2016.
PyTorch offers two significant features including tensor computation, as well as functional deep neural
networks.
Figure 34 : PyTorch
III. Dataset
Deep learning requires a huge amount of data in order to build a good model. So, we started searching
for great dataset to build our model even before finding our final algorithm. The majority of dataset that we
are going to give in this chapter are based on projects and research.
1. LUNA16 Labeled 3D - Lung Nodule Analysis Dataset 2016
The LUNA16 dataset is also 3D CT scans of lung cancer labelled by radiologists. The dataset contains
3D images and a CSV file containing annotations. Until this moment the dataset still publicly available. The
format of the 3D image is a 3 dimensions array (height=512, width=512, number of images=200). One of the
advantages of this dataset is that the dataset is divided into 10 subsets which make it easier to work with. After
some researches I noticed that the LUNA16 dataset was drawn from another public dataset LIDC-IDRI.
UCA - SAFI
32
Figure 35 : LUNA16
2. Kaggle 3D dataset: Data science Bowl 2017
This data was used in Kaggle competition data science bowl 2017, but the dataset is no longer publicly
available due to data set usage restrictions. The dataset contains full CT scan images of a patient’s lungs in
the same dimensions of the LUNA16 dataset (height=512, width=512, number of images=200). This dataset
was what the Data scientist originally wanted to work with as the data was labeled as desired and useful for
the project. The only problem in this dataset is the size of all the dataset it’s about 100GB. Preprocessing the
entire dataset would also be too computationally heavy.
Figure 36 : Data science Bowl 2017
IV. Lung Cancer Models
After that we have done some researches in different projects. We inferred that the majority of projects
uses CNN which is a deep learning algorithm. But, the difference between these projects is the architecture.
We may find that the project is using an existing model, or the authors of the projects may build their own
model based on existing one.
UCA - SAFI
33
In this section, each one of us searched 2 projects of lung cancer, to have ideas and knowledge about
this subject. Between these 8 projects we have chosen 2 performed and working project, that we will present
you later.
1. First model
This project treats Lung cancer Detection. The lung cancer diagnosis process requires a doctor to take
multiple steps in consulting lung specialists, and receiving secondary opinions before arriving at a complete
diagnosis.
A user will have and input a histopathological lung image into the model and receive a full diagnosis
of cell type, cancerous status, and type of malignancy if applicable.
Theorical Side
1. DataSet
This project is using a Kaggle dataset. There are 5 classes of data: 2 colon types (benign and malignant:
adenocarcinoma) and 3 lung types (benign, malignant - adenocarcinoma (ACA) and malignant - squamous
cell carcinoma (SCC). Each class contains 250 images, which were pre-augmented to 5,000 of each class.
Figure 37 : first model dataset
This dataset is splitted into three subsets, the first is for training, second is for validation and the third is
for testing. In the training subset the data is divided a second time, in order to train each CNN effectively.
UCA - SAFI
34
2. Architecture
Figure 38 : first Model architecture
UCA - SAFI
35
2.1. Image preprocessing
In this step, they normalized the pixel intensity of the images to the [0,1] range and images were
resized to 224x224 pixels for consistency and to reduce load on our model. Finally, images were transformed
to tensors. In order to be fed into our first CNN in this project.
Figure 39 : Image normalization
2.2 CNN 1 (Lung vs Colon)
In this CNN we use the preprocessing images and distinguishes between lung and other scans. If we
found that is a Lung scan, the image is fed into CNN 2 (we will talk about it later), if it’s not the output will
be a request to insert a histopathological lung image. (We will talk about CNN 2 later)
CNN 1 is composed of 2 Convolution layers with 5x5 Kernel, 2 Max Pool with 4x4 kernel and a
flatten layer at the end for classification.
Figure 40 : Lung VS Other image classification
2.3. CNN 2 (Lung Benign vs. Malignant)
CNN 2 distinguishes between malignant and benign lung cells. And uses the lung scan 224x224 given
by CNN 1.
CNN 2 is composed of 1 Convolution layers with 5x5 Kernel, 2 Max Pool with 2x2 kernel and finally
a flatten layer for classification.
UCA - SAFI
36
Figure 41 : Lung benign VS malignant classification
2.4. CNN 4 (Lung SCC vs. ACA)
CNN 4 is used to classify the type of lung cancer: adenocarcinoma or squamous cell. And uses the
lung scan 224x224 given by CNN 2.
CNN 4 is composed of 1 Convolution layers with 5x5 Kernel, 3 Convolution layers with 4x4 Kernel,
1 Max Pool with 2x2 kernel and finally a flatten layer for classification. All the outputs of these CNNs are
either a zero or a one depending on the classification determined by the model.
Figure 42: Lung malignant ACA VS SCC classification
3. Comparison between the 3 CNNs
Batch
Size
Learning
Rate
# of
Epochs
# of
Convolution
Layers
# of
Pooling
Layers
# of Fully
Connected
Layers
CNN 1: Lung
vs. Colon
256 0.1 5 2 2 2
CNN 2: Lung
Benign vs.
Malignant
256 0.01 6 2 2 2
CNN 4: Lung
SCC vs. ACA
64 0.0065 13 4 1 2
Figure 43 : Comparison between the 3 CNNs
UCA - SAFI
37
Practical Side
1. Tools
During our practical part we used different tools (PyTorch, google Colaboratory, …etc.). These tools
help us to implement easily and effectively our model. We have talked previously about PyTorch FrameWork,
used in this project.
- Google Colab
Colaboratory, or “Colab” for short, is a product from Google Research. Colab allows anybody to write
and execute arbitrary python code through the browser, and is especially well suited to machine learning, data
analysis and education. If you have used Jupyter notebook previously, you would quickly learn to use Google
Colab. To be precise, Colab is a free Jupyter notebook environment that runs entirely in the cloud.
Figure 44 : google colab
2. Implementation
2.1.Training
Before using our model to predict the right outputs for histopathological images, we need first to train
it. So, in this part we will give you some screenshot for important training source code and also the training
results in numbers and in a plot.
a. Defining the CNNs
UCA - SAFI
38
Figure 45 : CNN1 class
This function defines of the first network CNN 1, which distinguish between a lung and other scans.
inputs:
224 x 224 prepossessed lung or colon image
Output:
Lung or colon
Figure 46 : CNN2 class
UCA - SAFI
39
This one defines our second network CNN 2, which distinguish between a benign and malignant lung
scan.
inputs:
224 x 224 prepossessed lung image.
Output:
Lung benign or malignant.
Figure 47 : CNN4 class
Our last network CNN 4, distinguish the type of lung cancer: adenocarcinoma or squamous cell.
Inputs:
224 x 224 prepossessed malignant lung image
Output:
Lung malignant adenocarcinoma (ACA) or malignant - squamous cell carcinoma (SCC).
b. Training function
Used to train the three CNNs (Figure 45,46 and 47), in order to have good results in the testing part.
In this function we will be using Binary cross Entropy (BCE) to calculate the loss, the optimizer will be SGD
with momentum. And at the end of the training the trained CNN will be saved in a checkpoint_file.
UCA - SAFI
40
Figure 48: Training Function
Arguments:
Net: the network (one of the three CNNs)
train_loader : loading the training data.
val_loader : loading the validation data.
Batch_size : number of training examples utilized in one iteration.
Learning_rate : the learning rate used in the optimizer.
Num_epochs : the number times that the algorithm will work through the training dataset.
Return:
The trained network
c. The training Results
UCA - SAFI
41
Figure 49: Training CNNs
This source code (Figure 49) is used to call one of the three CNNs (Figure 45, 46, 47) in order to train
them by using the train_net function (Figure 48).
Cuda means if we are using a GPU or not, because the GPU accelerate the training process in comparison
with CPU.
✓ CNN1
Figure 50: CNN1 training
Training the first CNN took us 21 minutes with GPU, it takes 1 hour when we used the CPU, which
confirms that the GPU accelerate the training process.
These are the training results:
- Training error : 0.017 ; - Validation error : 0.024
- Training loss : 0.043 ; - Validation loss : 0.074
✓ CNN2
UCA - SAFI
42
Figure 51: CNN2 training
Training the Second CNN took us 1 hour with GPU. And 3 hours with CPU
These are the training results:
- Training error : 0.010 ; - Validation error : 0.012
- Training loss : 0.024 ; - Validation loss : 0.027
✓ CNN4
Figure 52: CNN4 training
UCA - SAFI
43
Training the third CNN took us 1 hour 5 minutes with CPU. We didn’t use the GPU because of
Google Colab limitation. Google Colab provides a single 12GB NVIDIA Tesla K80 GPU that can be used
up to 12 hours continuously.
These are the training results:
- Training error : 0.033 ; - Validation error : 0.106
- Training loss : 0.098 ; - Validation loss : 0.355
2.2.Predicting
After that we trained the CNNs and we have got really good results and high accuracy, we saved our
models in checkpoint_files in order to use them for predicting new images.
So, in this section we will be talking about the predicting part of our project, where we will be displaying
some screenshots of source code and the output of prediction.
a. Image and Model Loader
Figure 53 : load model
This function load our model by using the torch.load command.
Arguments:
Net: PyTorch neural network object.
model_path: Give us where the model is located (the Path), in order to load it.
Return:
net: models
Figure 54 : load image
UCA - SAFI
44
Load image and prepares it for model.
Arguments:
image_name: String representing path of image location
Return: image
b. Image classification
Figure 55: Image Classification
Predicts output and classify the given image
Arguments:
CNN1: load the cnn1 model
CNN2: load the cnn2 model
CNN3: load the cnn3 model
CNN4: load the cnn4 model
Image: test image path
Return:
Res: the result of the classification process (prediction of the image)
c. Model prediction
UCA - SAFI
45
Figure 56 : output of the model
inputs:
CNN1: load the cnn1 model from his path
CNN2: load the cnn2 model from his path
CNN4: load the cnn4 model from his path
Image: test image path
Output:
The prediction of the model example: [ lung, malignant, SCC]
2.3.Model study
After that we obtained good results in the training and testing, we started a study in the CNNs who
composes our model by trying to modify the layers of the CNNs.
So, we began by adding a convolution layer in our CNNs (Figure 57) to increase the accuracy of our
model, but unfortunately after training our CNNs (Figure 58), results were not as planned to be we noticed
that the loss (0.66) and the error (0.4) increased in comparison with the normal CNNs (Figure 50, 51 and 52).
UCA - SAFI
46
Figure 57: Modified CNN
Figure 58: Training result (Modified CNN)
As a result, we decided to use the normal CNNs because of the high accuracy and the low loss that we
got during training.
UCA - SAFI
47
2. Second model
This project used VGG16 model to predict if the lung is infected with Pneumonia or not. A user will
have and input an x-ray lung image into the model and receive an output that contains if the lung is infected
or not.
Theorical Side
1. DataSet
For this project we used Kaggle dataset. This dataset is organized into 3 folders (train, test, validation)
and contains subfolders for each image category (Pneumonia/Normal). There are 5863 X-Ray images (JPEG)
and 2 categories (Pneumonia/Normal).
Figure 59 : second model dataset (kaggle)
2. Architecture
We used a simple VGG16 model by changing some parameters. VGG16 is a convolution neural net
(CNN) architecture which was used to win ILSVR (Image net) competition in 2014.
The most unique thing about it is that instead of having a large number of hyper-parameters they focused
on having convolution layer of 3x3 filters with a stride 1 and always used same padding and Max Pooling
layers of 2x2 filter of stride. In The end it has 2 FC (Fully connected layers).
UCA - SAFI
48
Figure 60 : Second Model architect
3. How we manage to use VGG16
As you can see VGG16 predict an output of 1000 category. Basically, in the final output the model tells
us if a person has a pneumonia disease or not (see figure 2).
We firstly need to import VGG16 from Keras library and delete all weight, and also changing some
parameter like the optimizer and at the end we made a change in the Fully connected layers to be able to give
us an array of two dimension (we name it classes in the code).
This array is the final prediction. The first element contains the normal case (if 1 then person is normal
else the person is not normal, automatically the second case it will be 1) and so one.
Figure 61 : Normal lung VS pneumonia
UCA - SAFI
49
Practical Side
• Implementation
1. Import VGG 16 from Keras
Figure 62: Import of libraries and VGG16 from Keras
This part helps us to import all the libraries that we need and also a model, which is VGG16, all this is
imported from keras.
Figure 63: Creating the model
To create our model object, we used the Vgg 16 library as shown below and add preprocessing layer to
the front of VGG, for the output we used the softmax activation function to classify the image.
In our case, we didn’t use a pretrained VGG16. We trained the model from scratch using our the Kaggle
dataset, to get used to detecting cancer.
2. model summary
The image below (see figure 64), present you our model summary or structure:
UCA - SAFI
50
Figure 64: Model Structure
After that we train the model using the training set, we execute the code below to save the trained model
in h5 file.
Figure 65: Save Model
3. Predicting using the saved model
To test the model, we need to load the h5 file (contains the trained model), an image from the testing set
and resize it to 244x244. Then we use the model. Predict method, in order to predict the class of the image (is
it a normal or infected lung).
UCA - SAFI
51
Figure 66: Testing code
4. Model Output
Figure 67: Model output
After that we execute the code in figure 66, the model starts his prediction. When he found the result,
an array shows up containing results (see figure 67). In this case the lung is infected.
UCA - SAFI
52
Part 3: Desktop Application.
UCA - SAFI
53
Object detection has been used in many fields, in our project, we will use it in Radiologist field.
According to a recent study, doctors spend 75% of their time studying x-ray results of each patient, instead of
talking to patients face-to-face to assure them so as not to panic, including working with the electronic medical
records.
The objective is to make a desktop application that takes an input image and do some process to finally
predict a result of whether you have cancer or not. Before you select an image, we need to select, whether we
will use an X-ray image to detect if you have pneumonia or not, or a histopathological image to predict if our
tumor is benign or malignant if it is malignant the application precise the type of malignancy.
In this section we will explain to the user how to use this application, and the tools used to build it. And
finally, some source code to clarify the developing part.
I. Tools
We have used the tkinter framework and that’s due to its simplicity.
• Definition
Tkinter is implemented as a Python wrapper around a complete Tcl interpreter embedded in the Python
interpreter. And is the standard Python interface to the Tk GUI toolkit. Both Tk and tkinter are available on
most UNIX platforms, as well as on Windows systems.
Figure 68: TKinter
II. Front-end
• Graphic Interface
The interface contains many options that we can use:
- upload an image(input).
- Choosing the type of images (x-ray or Histopathological)
- Reset the page
- send information to Gmail and receiving output.
UCA - SAFI
54
Figure 69 : Application desktop of the model
1. Choose the image type
Before selecting and uploading any image in the application we need to choose the type of the image if
is it an x-ray image or a histopathological image, because each image type has its own process. (Figure 70)
If we want to upload an image without choosing type, a warning will appear (Figure 70) saying that we
need to choose the image type first.
Figure 70: Image type and warning popup
2. Upload an image
After clicking the button select images – processing and choosing the image type, a window, that
contains images, opens to select an image from you’re pc. After selecting it, the image will be displayed on
the application.
In the one hand if we choose the first type (x-ray), the message will tell us if we have pneumonia or not.
In the other hand (Histopathological), the message tells us whether we have a benign or malignant cancer, if
it’s malignant the application will specify the type (Adenocarcinoma or Squamous cell carcinoma).
The whole process:
- Click the ‘select image – processing ‘button:
UCA - SAFI
55
Figure 71: Select images button
- Selecting image from your device, here you have 2 types of images:
▪ X-ray
▪ Histopathological
Figure 72 : Upload the image
X-ray images are at your left hand and Histopathological images are at your right hand (Figure 72).
3. Output
Figure 73: Selected image and the test result
After selecting the desired image, you need to wait some time until the image shows up in screen and
also display the message of the result (Figure 73).
At your left there is the x-ray images joint with the adequate result and at your right you will find the
histopathological image and the test result (Figure 73).
Other type of test results:
UCA - SAFI
56
Figure 74 : The model predictions
4. Send Email message
After the output message that tells you if you have cancer or not shows up, we developed our python
script to give us the possibility to send an email message that contain the result.
Figure 75 :Email from the application contains the results
5. Reset button
After that we get the result is displayed and the test is sent to the user email. Now we can use the reset
button, in order to clean the page from old information’s (image, test result). So that we can insert another
image and predict the result.
Figure 76: Reset button
III. Back-end
• Model Integration
1. Select -processing button
UCA - SAFI
57
def open():
root.filename = filedialog.askopenfilename(initialdir='images/',title="sellect file ",filet
ypes=(("png file","*.jpeg"),("all files","*.*")))
global img
global my_image
img = Image.open(root.filename)
img.thumbnail((400,400))
my_image = ImageTk.PhotoImage(img)
my_image_label = Label(root,image=my_image).place(x=400,y=150)
get_path_img(root.filename)
After we click the button, first this function called to get the file path. The initial dir is for opening the
image folder first. File types the model can predict on png image. We create a label to show the image on the
screen after that the path of image is fed into the function to start the process of prediction.
def get_path_img(path):
model = load_model('model_vgg16.h5')
img = image.load_img(str(path),target_size=(244,244))
x = image.img_to_array(img)
x = np.expand_dims(x,axis=0)
classes = model.predict(preprocess_input(x))
v1_normal = round(classes[0][0])
v1_pnemn = round(classes[0][1])
if v1_normal==1:
result_frame = LabelFrame(root,text="TEST - RESULT",bg="#00adb5",fg="#ffffff")
result_frame.place(x=850,y=400)
Label(result_frame,text="I'm so happy for you!,you're test is positive").pack()
elif v1_pnemn == 1:
result_frame = LabelFrame(root,text="TEST - RESULT",bg="#00adb5",fg="#ffffff")
result_frame.place(x=850,y=400)
Label(result_frame,text="I'm sorry. I have some bad news.",bg="#00adb5",fg="#ffffff").pack()
time.sleep(10)
Label(result_frame,text="""You must be shocked at this information,
I know how you feel,
I don't know what to say""",bg="#00adb5",fg="#ffffff").pack()
add_result(v1_normal,v1_pnemn,str(path))
The get_path_img () function load the model and the image in the first two lines, to load the image we
use the image.load_img method that contain the parameter path, and also the target size of our model. We
convert the image into a numpy array by the method img_to_array () function. The method numpy
expand_dims insert a new axis that will appear at the axis position in the expand array shape. We store the
result on classes table and we start making decision based on the result.
UCA - SAFI
58
In the final line we call the add_result (first value is for the normal case, second for infected case, the
path is optional, but just in case we will need it in the future) This method just stores the results in a table.
2. Send info button:
When we click ‘send info’ the code below will be executed. This code check if the information’s name
and mail are entered by the user. After that it check if the list_check_in array contains info of get_path_img ()
resulting. Then passes through conditions of those information to know the right message to send.
The rest of the code is about sending mail by using the secured smtp protocol.
def final_prcss():
name = full_name.get()
mail = e_mail.get()
# phone_number.get()
if (not name) or (not mail) or (not list_check_in[3]):
warning_msg = messagebox.showwarning('lake of information','Please make sure that
all information are fitted,Also image')
else:
warning_msg = messagebox.showinfo('indar','Please make sure that all information a
re correct') #final we will correct our app
#sending email
#define parameter
email_user = 'lungcancerdetection21@gmail.com'
email_password = 'lungcancer21'
email_send = mail
server = smtplib.SMTP('smtp.gmail.com',587)
server.starttls()
server.login(email_user,email_password)
subject = 'PFE-LUNG CANCER DESIEASES'
if len(list_check_in)==1:
message_error = messagebox.showerror('NO INFORMATION TO SEND','Please make sure to
folow the instruction of our app')
else:
if list_check_in[1] == 1:
body = f"Hi Mr {name},nnThank you for using our app . We are so happy for th
e test is positive n n PFE LUNG APP,"
else:
body = f"Hi Mr {name},nnThank you for using our app .nn We are sorry test
has shown negative result.n Make sure to visit doctor as soon as possible n n PFE LUNG
APP"
msg = f'Subject:{subject}nn{body}'
server.sendmail(email_user,email_send,msg)
server.quit()
UCA - SAFI
59
Part 4: Project Plan.
UCA - SAFI
60
Introduction
This chapter details the project plan and reviews the different changes and steps taken within the entire
development lifecycle of the project.
I. Gantt chart
The figures below show how the projects tasks were done using a Gannt Chart. The chart allowed a brief
estimation for the amount of work that had to be done for a task.
Figure 77: Project Plan
Figure 78: Gantt chart
UCA - SAFI
61
II. Project review
The theorical data science tasks took too much time to achieve for the project. Although there is a generous
amount of time allocated for training, testing models and the desktop app development tasks in the project.
The main reason is the time taken to understand data science, and running deep learning models consume
time. This is because data science is a new field for us and we have to assimilate things and don’t rush to have
a solid base, that can help us to go forward. Our lack of experience in training and testing deep neural networks
also impacted our progress.
The desktop app development and integrating it with the model was also a new field for us, because we
used new programing language, which is python, and new techniques like tkinter. Besides all that our
project is working and we succeeded to finish it in time.
Conclusion
This section details how we constructed and planned the tasks for the project. The Gantt chart was heavily
used to estimate the duration of activities and with this tool all the tasks has been achieved.
General Conclusion
In this project we have learned a lot of things that we never studied before, like AI, ML, DL, … etc. We
used these skills in a sensible subject, which is Lung cancer detection, lung cancer is a very dangerous disease
that begins in lung and he is the leading cause of cancer deaths worldwide. Detecting lung cancer by using
deep learning algorithms, will save a lot of time for doctors to look after other patients and also will reduce
the false positives results of doctors, due to fatigue.
During this final project we faced a lot of problems, like finding the best algorithm to predict lung cancer
and even when we found the right one, we faced some problem to train and test the model, because of our lack
of experience in the deep learning fields. But luckily, we achieved our goals and we developed our application
where detect lung cancer and returns the results.
UCA - SAFI
62
Figures Table
Figure 1: Number of Publications in Object Detection ...............................................................................................6
Figure 2: Neural Network ............................................................................................................................................10
Figure 3: Neural Network (explanation).....................................................................................................................11
Figure 4: Perceptron (Forward Propagation)............................................................................................................11
Figure 5: Sigmoid Function..........................................................................................................................................12
Figure 6: Types of Activation Functions.....................................................................................................................12
Figure 7: Non-Linearities.............................................................................................................................................13
Figure 8: Linear vs Non-Linear function....................................................................................................................13
Figure 9: Two Perceptron ............................................................................................................................................14
Figure 10: DL, ML and AI...........................................................................................................................................15
Figure 11 : computer vision in Action.........................................................................................................................16
Figure 12 : pixels labeled with numbers from 0–255................................................................................................17
Figure 13 : combinations of RGB values to create RGB images ..............................................................................17
Figure 14 : Object recognition with deep learning ....................................................................................................18
Figure 15 : Review of Deep Learning Algorithms for Object Detection..................................................................19
Figure 16 : Object detection VS instance segmentation ............................................................................................19
Figure 17 : Specifying the bounding box 1..................................................................................................................20
Figure 18 : Specifying the bounding box 2..................................................................................................................20
Figure 19 : Matrix of pixel values of X........................................................................................................................21
Figure 20 : Feature Extraction .....................................................................................................................................22
Figure 21 : convolution operator.................................................................................................................................22
Figure 22 : CNN for classification ...............................................................................................................................23
Figure 23 : Max pooling................................................................................................................................................23
Figure 24 : R-CNN architecture ..................................................................................................................................24
Figure 25 : Selective search..........................................................................................................................................24
Figure 26 : Precision & Recall .....................................................................................................................................25
Figure 27 : precision and recall formula.....................................................................................................................25
Figure 28 : fast R-CNN architecture...........................................................................................................................26
Figure 29 : faster R-CNN architecture........................................................................................................................27
Figure 30 : R-CNN VS Fast R-CNN VS Faster R-CNN............................................................................................27
Figure 31 : OpenCV......................................................................................................................................................30
Figure 32 : TensorFlow.................................................................................................................................................30
Figure 33 : Keras...........................................................................................................................................................31
Figure 34 : PyTorch......................................................................................................................................................31
Figure 35 : LUNA16......................................................................................................................................................32
Figure 36 : Data science Bowl 2017.............................................................................................................................32
Figure 37 : first model dataset .....................................................................................................................................33
Figure 38 : first Model architecture ............................................................................................................................34
Figure 39 : Image normalization .................................................................................................................................35
Figure 40 : Lung VS Other image classification ........................................................................................................35
Figure 41 : Lung benign VS malignant classification................................................................................................36
UCA - SAFI
63
Figure 42: Lung malignant ACA VS SCC classification...........................................................................................36
Figure 43 : Comparison between the 3 CNNs ............................................................................................................36
Figure 44 : google colab................................................................................................................................................37
Figure 45 : CNN1 class .................................................................................................................................................38
Figure 46 : CNN2 class .................................................................................................................................................38
Figure 47 : CNN4 class .................................................................................................................................................39
Figure 48: Training Function.......................................................................................................................................40
Figure 49: Training CNNs............................................................................................................................................41
Figure 50: CNN1 training.............................................................................................................................................41
Figure 51: CNN2 training.............................................................................................................................................42
Figure 52: CNN4 training.............................................................................................................................................42
Figure 53 : load model ..................................................................................................................................................43
Figure 54 : load image ..................................................................................................................................................43
Figure 55: Image Classification ...................................................................................................................................44
Figure 56 : output of the model....................................................................................................................................45
Figure 57: Modified CNN.............................................................................................................................................46
Figure 58: Training result (Modified CNN) ...............................................................................................................46
Figure 59 : second model dataset (kaggle).................................................................................................................47
Figure 60 : Second Model architect............................................................................................................................48
Figure 61 : Normal lung VS pneumonia .....................................................................................................................48
Figure 62: Import of libraries and VGG16 from Keras............................................................................................49
Figure 63: Creating the model .....................................................................................................................................49
Figure 64: Model Structure..........................................................................................................................................50
Figure 65: Save Model..................................................................................................................................................50
Figure 66: Testing code.................................................................................................................................................51
Figure 67: Model output...............................................................................................................................................51
Figure 68: TKinter........................................................................................................................................................53
Figure 69 : Application desktop of the model.............................................................................................................54
Figure 70: Image type and warning popup ................................................................................................................54
Figure 71: Select images button...................................................................................................................................55
Figure 72 : Upload the image.......................................................................................................................................55
Figure 73: Selected image and the test result .............................................................................................................55
Figure 74 : The model predictions...............................................................................................................................56
Figure 75 :Email from the application contains the results ......................................................................................56
Figure 76: Reset button ................................................................................................................................................56
Figure 77: Project Plan.................................................................................................................................................60
Figure 78: Gantt chart..................................................................................................................................................60
UCA - SAFI
64
Bibliography
➢ Machine Learning - URL: https://searchenterpriseai.techtarget.com/definition/machine-learning-ML
➢ Deep Learning – URL https://www.bpttbrightminds.com/wp-content/uploads/2020/08/Intro-to-Deep-Learning.pdf
➢ Computer Vision – URL https://towardsdatascience.com/everything-you-ever-wanted-to-know-about-computer-
vision-heres-a-look-why-it-s-so-awesome-e8a58dfb641e
➢ Object Detection – component – URL https://www.geeksforgeeks.org/object-detection-vs-object-recognition-vs-
image-segmentation/
➢ Object Detection – bounding box – URL https://medium.com/analytics-vidhya/basics-of-bounding-boxes-
94e583b5e16c
➢ Object Detection – R-CNN family – URL https://machinelearningmastery.com/object-recognition-with-deep-
learning/
➢ First Project – URL https://github.com/krishnaik06/Predicitng-Lungs-Disease-
➢ Second Project – URL https://github.com/justin13601/AICancer/
➢ First Project – Histopathological dataset- URL https://www.kaggle.com/andrewmvd/lung-and-colon-cancer-
histopathological-images
➢ Second Project – X-ray dataset – URL https://www.kaggle.com/paultimothymooney/chest-xray-pneumonia
➢ Second project – VGG16 – URL https://keras.io/api/applications/
➢ Lung Cancer- URL https://www.healthline.com/health/lung-cancer
➢ PyTorch – URL https://deepai.org/machine-learning-glossary-and-terms/pytorch
➢ Tkinter – URL https://docs.python.org/3/library/tkinter.html

More Related Content

What's hot

Rapport de projet de fin d'année
Rapport de projet de fin d'année Rapport de projet de fin d'année
Rapport de projet de fin d'année
kaies Labiedh
 
Reconnaissance faciale
Reconnaissance facialeReconnaissance faciale
Reconnaissance facialeAymen Fodda
 
Rapport PFE
Rapport PFERapport PFE
Rapport PFE
oussama Hafid
 
Rapport de stage d'initiation 2015 Mahmoudi Mohamed Amine
Rapport de stage d'initiation 2015 Mahmoudi Mohamed AmineRapport de stage d'initiation 2015 Mahmoudi Mohamed Amine
Rapport de stage d'initiation 2015 Mahmoudi Mohamed Amine
Mohamed Amine Mahmoudi
 
Deep Learning : Application à la reconnaissance d’objets de classes multiples...
Deep Learning : Application à la reconnaissance d’objets de classes multiples...Deep Learning : Application à la reconnaissance d’objets de classes multiples...
Deep Learning : Application à la reconnaissance d’objets de classes multiples...
Haytam EL YOUSSFI
 
Rapport pfe talan_2018_donia_hammami
Rapport pfe talan_2018_donia_hammamiRapport pfe talan_2018_donia_hammami
Rapport pfe talan_2018_donia_hammami
Donia Hammami
 
Rapport de stage
Rapport de stageRapport de stage
Rapport de stage
Aicha OUALLA
 
Rapport Projet De Fin D'étude de Conception et développement d’une applicatio...
Rapport Projet De Fin D'étude de Conception et développement d’une applicatio...Rapport Projet De Fin D'étude de Conception et développement d’une applicatio...
Rapport Projet De Fin D'étude de Conception et développement d’une applicatio...
mouafekmazia
 
Rapport pfe- Refonte et déploiement d’une solution de messagerie en utilisant...
Rapport pfe- Refonte et déploiement d’une solution de messagerie en utilisant...Rapport pfe- Refonte et déploiement d’une solution de messagerie en utilisant...
Rapport pfe- Refonte et déploiement d’une solution de messagerie en utilisant...
Nawres Farhat
 
Présentation PFE
Présentation PFEPrésentation PFE
Présentation PFE
Semah Mhamdi
 
Conception et développement d'une application de gestion de production et de ...
Conception et développement d'une application de gestion de production et de ...Conception et développement d'une application de gestion de production et de ...
Conception et développement d'une application de gestion de production et de ...
Mohamed Aziz Chetoui
 
Rapport PFE : Développement D'une application de gestion des cartes de fidéli...
Rapport PFE : Développement D'une application de gestion des cartes de fidéli...Rapport PFE : Développement D'une application de gestion des cartes de fidéli...
Rapport PFE : Développement D'une application de gestion des cartes de fidéli...
Riadh K.
 
Rapport de stage PFE - Mémoire master: Développement d'une application Android
Rapport de stage PFE - Mémoire master: Développement d'une application AndroidRapport de stage PFE - Mémoire master: Développement d'une application Android
Rapport de stage PFE - Mémoire master: Développement d'une application Android
BadrElattaoui
 
Rapport de projet de conception et de développement
Rapport de projet de conception et de développementRapport de projet de conception et de développement
Rapport de projet de conception et de développement
Donia Hammami
 
Rapport pfe
Rapport pfeRapport pfe
Rapport pfe
Ahmed rebai
 
Conception et développement d’un système d’alerte et notification d’une tou...
Conception et développement  d’un système d’alerte et notification  d’une tou...Conception et développement  d’un système d’alerte et notification  d’une tou...
Conception et développement d’un système d’alerte et notification d’une tou...
Bilel Khaled ☁
 
Projet réalisé par ameny Khedhira & Arij Mekki
Projet réalisé par  ameny Khedhira & Arij MekkiProjet réalisé par  ameny Khedhira & Arij Mekki
Projet réalisé par ameny Khedhira & Arij Mekki
Ameny Khedhira
 
Mémoire PEF application client server gestion des projet collaborative
Mémoire PEF application client server gestion des projet collaborativeMémoire PEF application client server gestion des projet collaborative
Mémoire PEF application client server gestion des projet collaborative
Messaoud Hatri
 
Conception et Réalisation Application Web Laravel PFE BTS
Conception et Réalisation Application Web Laravel PFE BTSConception et Réalisation Application Web Laravel PFE BTS
Conception et Réalisation Application Web Laravel PFE BTS
FaissoilMkavavo
 
Rapport de stage PFE ( DUT) chez Synthèse Conseil - Jaiti Mohammed
Rapport de stage PFE ( DUT) chez Synthèse Conseil  - Jaiti MohammedRapport de stage PFE ( DUT) chez Synthèse Conseil  - Jaiti Mohammed
Rapport de stage PFE ( DUT) chez Synthèse Conseil - Jaiti Mohammed
Mohammed JAITI
 

What's hot (20)

Rapport de projet de fin d'année
Rapport de projet de fin d'année Rapport de projet de fin d'année
Rapport de projet de fin d'année
 
Reconnaissance faciale
Reconnaissance facialeReconnaissance faciale
Reconnaissance faciale
 
Rapport PFE
Rapport PFERapport PFE
Rapport PFE
 
Rapport de stage d'initiation 2015 Mahmoudi Mohamed Amine
Rapport de stage d'initiation 2015 Mahmoudi Mohamed AmineRapport de stage d'initiation 2015 Mahmoudi Mohamed Amine
Rapport de stage d'initiation 2015 Mahmoudi Mohamed Amine
 
Deep Learning : Application à la reconnaissance d’objets de classes multiples...
Deep Learning : Application à la reconnaissance d’objets de classes multiples...Deep Learning : Application à la reconnaissance d’objets de classes multiples...
Deep Learning : Application à la reconnaissance d’objets de classes multiples...
 
Rapport pfe talan_2018_donia_hammami
Rapport pfe talan_2018_donia_hammamiRapport pfe talan_2018_donia_hammami
Rapport pfe talan_2018_donia_hammami
 
Rapport de stage
Rapport de stageRapport de stage
Rapport de stage
 
Rapport Projet De Fin D'étude de Conception et développement d’une applicatio...
Rapport Projet De Fin D'étude de Conception et développement d’une applicatio...Rapport Projet De Fin D'étude de Conception et développement d’une applicatio...
Rapport Projet De Fin D'étude de Conception et développement d’une applicatio...
 
Rapport pfe- Refonte et déploiement d’une solution de messagerie en utilisant...
Rapport pfe- Refonte et déploiement d’une solution de messagerie en utilisant...Rapport pfe- Refonte et déploiement d’une solution de messagerie en utilisant...
Rapport pfe- Refonte et déploiement d’une solution de messagerie en utilisant...
 
Présentation PFE
Présentation PFEPrésentation PFE
Présentation PFE
 
Conception et développement d'une application de gestion de production et de ...
Conception et développement d'une application de gestion de production et de ...Conception et développement d'une application de gestion de production et de ...
Conception et développement d'une application de gestion de production et de ...
 
Rapport PFE : Développement D'une application de gestion des cartes de fidéli...
Rapport PFE : Développement D'une application de gestion des cartes de fidéli...Rapport PFE : Développement D'une application de gestion des cartes de fidéli...
Rapport PFE : Développement D'une application de gestion des cartes de fidéli...
 
Rapport de stage PFE - Mémoire master: Développement d'une application Android
Rapport de stage PFE - Mémoire master: Développement d'une application AndroidRapport de stage PFE - Mémoire master: Développement d'une application Android
Rapport de stage PFE - Mémoire master: Développement d'une application Android
 
Rapport de projet de conception et de développement
Rapport de projet de conception et de développementRapport de projet de conception et de développement
Rapport de projet de conception et de développement
 
Rapport pfe
Rapport pfeRapport pfe
Rapport pfe
 
Conception et développement d’un système d’alerte et notification d’une tou...
Conception et développement  d’un système d’alerte et notification  d’une tou...Conception et développement  d’un système d’alerte et notification  d’une tou...
Conception et développement d’un système d’alerte et notification d’une tou...
 
Projet réalisé par ameny Khedhira & Arij Mekki
Projet réalisé par  ameny Khedhira & Arij MekkiProjet réalisé par  ameny Khedhira & Arij Mekki
Projet réalisé par ameny Khedhira & Arij Mekki
 
Mémoire PEF application client server gestion des projet collaborative
Mémoire PEF application client server gestion des projet collaborativeMémoire PEF application client server gestion des projet collaborative
Mémoire PEF application client server gestion des projet collaborative
 
Conception et Réalisation Application Web Laravel PFE BTS
Conception et Réalisation Application Web Laravel PFE BTSConception et Réalisation Application Web Laravel PFE BTS
Conception et Réalisation Application Web Laravel PFE BTS
 
Rapport de stage PFE ( DUT) chez Synthèse Conseil - Jaiti Mohammed
Rapport de stage PFE ( DUT) chez Synthèse Conseil  - Jaiti MohammedRapport de stage PFE ( DUT) chez Synthèse Conseil  - Jaiti Mohammed
Rapport de stage PFE ( DUT) chez Synthèse Conseil - Jaiti Mohammed
 

Similar to Rapport PFE Lung Cancer Detection - MOHAMMED BOUSSARDI

HVAC Project. about heating a villa apdf
HVAC Project. about heating a villa apdfHVAC Project. about heating a villa apdf
HVAC Project. about heating a villa apdf
MoudiMalti
 
Phytochemicals-and-Cancer
Phytochemicals-and-CancerPhytochemicals-and-Cancer
Phytochemicals-and-CancerAmr Elshayeb
 
How Touch Screens works
How Touch Screens worksHow Touch Screens works
How Touch Screens works
Mohammad Alsharif
 
Ucu100 1-1[1]
Ucu100 1-1[1]Ucu100 1-1[1]
Ucu100 1-1[1]
kevinikapel
 
Studi Sertifikasi Emergency Floor Path berdasarkan RTCA DO-160E
Studi Sertifikasi Emergency Floor Path berdasarkan RTCA DO-160EStudi Sertifikasi Emergency Floor Path berdasarkan RTCA DO-160E
Studi Sertifikasi Emergency Floor Path berdasarkan RTCA DO-160E
mnfahmi
 
Balladares j eugenios-hidalgoo-galarzab-informefinal2 (1) (1)
Balladares j eugenios-hidalgoo-galarzab-informefinal2 (1) (1)Balladares j eugenios-hidalgoo-galarzab-informefinal2 (1) (1)
Balladares j eugenios-hidalgoo-galarzab-informefinal2 (1) (1)
David CuLcay
 
The role of transnational ethnic on socio economic integration in the horn of...
The role of transnational ethnic on socio economic integration in the horn of...The role of transnational ethnic on socio economic integration in the horn of...
The role of transnational ethnic on socio economic integration in the horn of...
Mohamed Aden Farah
 
Pakistan railway.project copy
Pakistan railway.project  copyPakistan railway.project  copy
Pakistan railway.project copy
Nisar Ahmad
 
INTEGRATED FINANCIAL MANAGEMENT INFORMATION SYSTEM AND FINANCIAL REPORTING EF...
INTEGRATED FINANCIAL MANAGEMENT INFORMATION SYSTEM AND FINANCIAL REPORTING EF...INTEGRATED FINANCIAL MANAGEMENT INFORMATION SYSTEM AND FINANCIAL REPORTING EF...
INTEGRATED FINANCIAL MANAGEMENT INFORMATION SYSTEM AND FINANCIAL REPORTING EF...
Kyambogo University, Kampala-Uganda
 
INTEGRATED FINANCIAL MANAGEMENT INFORMATION SYSTEM AND FINANCIAL REPORTING EF...
INTEGRATED FINANCIAL MANAGEMENT INFORMATION SYSTEM AND FINANCIAL REPORTING EF...INTEGRATED FINANCIAL MANAGEMENT INFORMATION SYSTEM AND FINANCIAL REPORTING EF...
INTEGRATED FINANCIAL MANAGEMENT INFORMATION SYSTEM AND FINANCIAL REPORTING EF...
Kyambogo University, Kampala-Uganda
 
Collective dominance - Karolina Rydman
Collective dominance - Karolina RydmanCollective dominance - Karolina Rydman
Collective dominance - Karolina Rydman
karolinarydman
 
Development of NHPC Accreditation and Licensing System Status 09 08 03
Development of NHPC Accreditation and Licensing System Status 09 08 03Development of NHPC Accreditation and Licensing System Status 09 08 03
Development of NHPC Accreditation and Licensing System Status 09 08 03Ahmed Omer
 
Industrial Attachment on "Texeurop (BD) Ltd."
Industrial Attachment on "Texeurop (BD) Ltd."Industrial Attachment on "Texeurop (BD) Ltd."
Industrial Attachment on "Texeurop (BD) Ltd."
Amanuzzaman Aman
 
A Framework For Organizational Workplace Relocation
A Framework For Organizational Workplace RelocationA Framework For Organizational Workplace Relocation
A Framework For Organizational Workplace Relocation
Kelly Lipiec
 
Purdue University | Fluid Power Vehicle Challenge
Purdue University | Fluid Power Vehicle ChallengePurdue University | Fluid Power Vehicle Challenge
Purdue University | Fluid Power Vehicle Challenge
Chandler Fairfield
 
Eia and the aims of the book
Eia and the aims of the bookEia and the aims of the book
Eia and the aims of the book
Dr. Mohamed Hassan
 
Data Center Proposal (System Network Administration)
Data Center Proposal (System Network Administration)Data Center Proposal (System Network Administration)
Data Center Proposal (System Network Administration)
Muhammad Ahad
 

Similar to Rapport PFE Lung Cancer Detection - MOHAMMED BOUSSARDI (18)

HVAC Project. about heating a villa apdf
HVAC Project. about heating a villa apdfHVAC Project. about heating a villa apdf
HVAC Project. about heating a villa apdf
 
Phytochemicals-and-Cancer
Phytochemicals-and-CancerPhytochemicals-and-Cancer
Phytochemicals-and-Cancer
 
How Touch Screens works
How Touch Screens worksHow Touch Screens works
How Touch Screens works
 
Ucu100 1-1[1]
Ucu100 1-1[1]Ucu100 1-1[1]
Ucu100 1-1[1]
 
Studi Sertifikasi Emergency Floor Path berdasarkan RTCA DO-160E
Studi Sertifikasi Emergency Floor Path berdasarkan RTCA DO-160EStudi Sertifikasi Emergency Floor Path berdasarkan RTCA DO-160E
Studi Sertifikasi Emergency Floor Path berdasarkan RTCA DO-160E
 
Balladares j eugenios-hidalgoo-galarzab-informefinal2 (1) (1)
Balladares j eugenios-hidalgoo-galarzab-informefinal2 (1) (1)Balladares j eugenios-hidalgoo-galarzab-informefinal2 (1) (1)
Balladares j eugenios-hidalgoo-galarzab-informefinal2 (1) (1)
 
The role of transnational ethnic on socio economic integration in the horn of...
The role of transnational ethnic on socio economic integration in the horn of...The role of transnational ethnic on socio economic integration in the horn of...
The role of transnational ethnic on socio economic integration in the horn of...
 
Pakistan railway.project copy
Pakistan railway.project  copyPakistan railway.project  copy
Pakistan railway.project copy
 
INTEGRATED FINANCIAL MANAGEMENT INFORMATION SYSTEM AND FINANCIAL REPORTING EF...
INTEGRATED FINANCIAL MANAGEMENT INFORMATION SYSTEM AND FINANCIAL REPORTING EF...INTEGRATED FINANCIAL MANAGEMENT INFORMATION SYSTEM AND FINANCIAL REPORTING EF...
INTEGRATED FINANCIAL MANAGEMENT INFORMATION SYSTEM AND FINANCIAL REPORTING EF...
 
INTEGRATED FINANCIAL MANAGEMENT INFORMATION SYSTEM AND FINANCIAL REPORTING EF...
INTEGRATED FINANCIAL MANAGEMENT INFORMATION SYSTEM AND FINANCIAL REPORTING EF...INTEGRATED FINANCIAL MANAGEMENT INFORMATION SYSTEM AND FINANCIAL REPORTING EF...
INTEGRATED FINANCIAL MANAGEMENT INFORMATION SYSTEM AND FINANCIAL REPORTING EF...
 
Collective dominance - Karolina Rydman
Collective dominance - Karolina RydmanCollective dominance - Karolina Rydman
Collective dominance - Karolina Rydman
 
Development of NHPC Accreditation and Licensing System Status 09 08 03
Development of NHPC Accreditation and Licensing System Status 09 08 03Development of NHPC Accreditation and Licensing System Status 09 08 03
Development of NHPC Accreditation and Licensing System Status 09 08 03
 
Project Report
Project ReportProject Report
Project Report
 
Industrial Attachment on "Texeurop (BD) Ltd."
Industrial Attachment on "Texeurop (BD) Ltd."Industrial Attachment on "Texeurop (BD) Ltd."
Industrial Attachment on "Texeurop (BD) Ltd."
 
A Framework For Organizational Workplace Relocation
A Framework For Organizational Workplace RelocationA Framework For Organizational Workplace Relocation
A Framework For Organizational Workplace Relocation
 
Purdue University | Fluid Power Vehicle Challenge
Purdue University | Fluid Power Vehicle ChallengePurdue University | Fluid Power Vehicle Challenge
Purdue University | Fluid Power Vehicle Challenge
 
Eia and the aims of the book
Eia and the aims of the bookEia and the aims of the book
Eia and the aims of the book
 
Data Center Proposal (System Network Administration)
Data Center Proposal (System Network Administration)Data Center Proposal (System Network Administration)
Data Center Proposal (System Network Administration)
 

Recently uploaded

一比一原版(QU毕业证)皇后大学毕业证成绩单
一比一原版(QU毕业证)皇后大学毕业证成绩单一比一原版(QU毕业证)皇后大学毕业证成绩单
一比一原版(QU毕业证)皇后大学毕业证成绩单
enxupq
 
一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单
enxupq
 
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
u86oixdj
 
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
vcaxypu
 
一比一原版(NYU毕业证)纽约大学毕业证成绩单
一比一原版(NYU毕业证)纽约大学毕业证成绩单一比一原版(NYU毕业证)纽约大学毕业证成绩单
一比一原版(NYU毕业证)纽约大学毕业证成绩单
ewymefz
 
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
axoqas
 
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
yhkoc
 
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
nscud
 
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
ahzuo
 
一比一原版(BU毕业证)波士顿大学毕业证成绩单
一比一原版(BU毕业证)波士顿大学毕业证成绩单一比一原版(BU毕业证)波士顿大学毕业证成绩单
一比一原版(BU毕业证)波士顿大学毕业证成绩单
ewymefz
 
Influence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business PlanInfluence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business Plan
jerlynmaetalle
 
standardisation of garbhpala offhgfffghh
standardisation of garbhpala offhgfffghhstandardisation of garbhpala offhgfffghh
standardisation of garbhpala offhgfffghh
ArpitMalhotra16
 
The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...
jerlynmaetalle
 
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
ewymefz
 
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
vcaxypu
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
Timothy Spann
 
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
pchutichetpong
 
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
ukgaet
 
一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单
ocavb
 
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdfSample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Linda486226
 

Recently uploaded (20)

一比一原版(QU毕业证)皇后大学毕业证成绩单
一比一原版(QU毕业证)皇后大学毕业证成绩单一比一原版(QU毕业证)皇后大学毕业证成绩单
一比一原版(QU毕业证)皇后大学毕业证成绩单
 
一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单
 
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
 
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
 
一比一原版(NYU毕业证)纽约大学毕业证成绩单
一比一原版(NYU毕业证)纽约大学毕业证成绩单一比一原版(NYU毕业证)纽约大学毕业证成绩单
一比一原版(NYU毕业证)纽约大学毕业证成绩单
 
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
 
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
 
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
 
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
 
一比一原版(BU毕业证)波士顿大学毕业证成绩单
一比一原版(BU毕业证)波士顿大学毕业证成绩单一比一原版(BU毕业证)波士顿大学毕业证成绩单
一比一原版(BU毕业证)波士顿大学毕业证成绩单
 
Influence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business PlanInfluence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business Plan
 
standardisation of garbhpala offhgfffghh
standardisation of garbhpala offhgfffghhstandardisation of garbhpala offhgfffghh
standardisation of garbhpala offhgfffghh
 
The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...
 
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
 
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
 
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
 
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
 
一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单
 
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdfSample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
 

Rapport PFE Lung Cancer Detection - MOHAMMED BOUSSARDI

  • 1. CADI AYYAD UNIVERSITY HIGH SCHOOL OF TECHNOLOGY SAFI COMPUTER SCIENCE Final REPORT Lung cancer Detection Realized by: Tutored by: Supervised by: ESSADEQ Ayoub GAMAL Mohammed Mr. ALAOUI FDILI Othman BOUSSARDI Mohammed AIT BENAISSA Mohamed-hamza GASSIR Chaimae YEAR 2020-2021
  • 2. UCA - SAFI 2 Summary Abstract............................................................................................................................................................................6 Part 1: Theorical Concepts..............................................................................................................................................7 I. Artificiel intelligence ................................................................................................................................................8 II. Machine learning : ....................................................................................................................................................8 1. Definition: 2. Different types of machine learning 2.1. Supervised machine learning algorithms ..........................................................................................................9 2.2. Unsupervised machine learning algorithms......................................................................................................9 III. Deep Learning:....................................................................................................................................................10 1. Definition 2. Neural Network: 3. The Perceptron: 4. Quantifying Loss: 5. Some types of deep learning algorithms: IV. Computer vision..................................................................................................................................................16 1. Definition 2. How Does Computer Vision Work?  V. Object Detection  1. Difference between Object recognition, Object localization, object detection and object segmentation:  2. R-CNN Model Family (Object Detection algorithms) 2.1 CNN Part:..........................................................................................................................................................21 2.2 R-CNN:.............................................................................................................................................................23 2.3 Fast R-CNN.......................................................................................................................................................25 2.4 Faster R-CNN ...................................................................................................................................................26 2.5 Comparison between R-CNN, Fast R-CNN and Faster R-CNN ......................................................................27 Part 2: Application of Deep learning in Lung Cancer Detection..............................................................................28 I. Lung cancer.............................................................................................................................................................29 1. Lung nodules 2. Non-small cell lung cancer  3. Small cell lung cancer 4. Stages of lung cancer  II. Frameworks and Library’s......................................................................................................................................30 1. OpenCV 
  • 3. UCA - SAFI 3 2. TensorFlow  3. Keras  III. Dataset.................................................................................................................................................................31 1. LUNA16 Labeled 3D - Lung Nodule Analysis Dataset 2016  2. Kaggle 3D dataset: Data science Bowl 2017  IV. Lung Cancer Models...........................................................................................................................................32 1. First model  • Theorical Side .................................................................................................................................................33 1. DataSet 2. Architecture 2.1. Image preprocessing .......................................................................................................................................35 2.2 CNN 1 (Lung vs Colon)..................................................................................................................................35 2.3. CNN 2 (Lung Benign vs. Malignant)..............................................................................................................35 2.4. CNN 4 (Lung SCC vs. ACA)..........................................................................................................................36 3. Comparison between the 3 CNNs...................................................................................................................36 • Practical Side ..................................................................................................................................................37 1. Tools  - Google Colab ..................................................................................................................................................37 2. Implementation  2.1. Training...........................................................................................................................................................37 a. Defining the CNNs..........................................................................................................................................37 b. Training function.............................................................................................................................................39 c. The training Results ........................................................................................................................................40 2.2. Predicting a. Image and Model Loader................................................................................................................................43 b. Image classification.........................................................................................................................................44 c. Model prediction.............................................................................................................................................44 2.3. Model study  2. Second model • Theorical Side .................................................................................................................................................47 1. DataSet 2. Architecture 3. How we manage to use VGG16 • Practical Side ..................................................................................................................................................49 • Implementation  1. Import VGG 16 from Keras 2. model summary 3. Predicting using the saved model
  • 4. UCA - SAFI 4 4. Model Output Part 3: Desktop Application. ........................................................................................................................................52 I. Tools .......................................................................................................................................................................53 • Definition II. Front-end.................................................................................................................................................................53 • Graphic Interface 1. Choose the image type 2. Upload an image  3. Output  4. Send Email message 5. Reset button  III. Back-end .............................................................................................................................................................56 • Model Integration 1. Select -processing button ................................................................................................................................56 2. Send info button:  Part 4: Project Plan. ......................................................................................................................................................59 Introduction.....................................................................................................................................................................60 I. Gantt chart...............................................................................................................................................................60 II. Project review .........................................................................................................................................................61 Conclusion ......................................................................................................................................................................61 General Conclusion.......................................................................................................................................................61 Figures Table.................................................................................................................................................................62 Bibliography..................................................................................................................................................................64
  • 5. UCA - SAFI 5 Dedication: To our dear parents, sisters, brothers, friends and to all teachers who helped us in this project, For their patience, encouragement and commitment. Acknowledgement: We would like to express our sincere gratitude to my supervisor Mr. ALAOUI FDILI Othmane for providing his valuable guidance, comments and suggestions throughout the course of the project. We would specially thank Mr. GAMAL Mohamed, to his availability and unconditional patience all the time he has devoted to the direction of this project. It is thanks to your support that we were able to carry out this work at term. My strong gratitude to Ms. MOUNIR Ilham, the manager of the “Computer science” and the professors who are members of the jury for having accepted to judge this work, I'd like to express my gratitude to everyone who has helped us finish this project in various ways.
  • 6. UCA - SAFI 6 Abstract Humans are quite good at detecting and identifying items in images. With little conscious thought, the human visual system can accomplish complicated tasks such as distinguishing multiple objects and detecting impediments. We can now quickly train computers to detect and identify many items inside an image because to the availability of enormous amounts of data, faster GPUs, and improved algorithms known as object detection. Lung cancer is one of the most lethal cancers because it can spread to other parts of the body, causing damage to them as well. Lung cancer was detected in 225,000 people in the United States alone in 2017. It resulted in a total health-care expense of $12 billion. One of the most effective ways to fight cancer is to discover it early. It significantly improves the patient's chances of survival. By studying nodules, a doctor can determine whether or not this scan is malignant. Humans, on the other hand, can evaluate nodules larger than 7mm in diameter, and doctors can sometimes have a patient wait to see if the nodule will develop or not, as it will be a harmless nodule if it does not. And this gives a chance for a nodule to grow more undetected by the human eye. In this project, we will explore terms such as object detection, AI, machine learning, deep learning, loss function for object detection and localization, and finally explores object detection algorithm known as “Convolutional Neural Network” (CNN) that will help us to distinguish between a lung cancer and a safe lung. Figure 1: Number of Publications in Object Detection
  • 7. UCA - SAFI 7 Part 1: Theorical Concepts
  • 8. UCA - SAFI 8 I. Artificiel intelligence Artificial intelligence (AI) is an area of computer science that aims to reproduce or imitate human intelligence in machines so that they can accomplish activities that would normally need human understanding, such as decision making, language processing, and visual perception. Planning, learning, reasoning, problem solving, and decision making are some of the programmed tasks of AI systems. Artificial intelligence systems are powered by algorithms, which include machine learning, deep learning, and rules, are used to fuel artificial intelligence systems. Machine learning algorithms use statistical approaches to give computer data to AI systems, allowing them to learn. Machine learning allows AI systems to improve their performance over time without having to be coded expressly for it. There are two types of AI: - Type 1: • Weak or Narrow AI: Machines aren't very intelligent; they can only perform one task. • Strong AI: Machines, like humans, can reason and complete tasks independently. - Type 2: • Reactive Machines: That machine has no memory and reacts only in the present instant. • Limited memory: Past experiences can be used by systems to help them make better decisions in the future. • Theory of mind: People's emotions can be understood by machines. • Self-awareness: Machine that is extremely intelligent. II. Machine learning : 1. Definition: Machine Learning is a branch of Artificial Intelligence that allows computers to learn and improve on their own without having to be explicitly programmed. It's worth mentioning that all machine learning techniques fall under the umbrella of Artificial Intelligence. As a result, machine learning is concerned with the creation of computer programs that can access data and learn for themselves.
  • 9. UCA - SAFI 9 The learning process starts with observations or data, such as examples, direct experience, or instruction, so that we can seek for patterns in data and make better decisions in the future based on the examples we provide. Machine learning algorithms use historical data as input to predict new output values. 2. Different types of machine learning There are different types of Machine Learning algorithms. Generally, Machine learning algorithms are often categorized as supervised or unsupervised. 2.1. Supervised machine learning algorithms Can use labeled examples to apply what they've learnt in the past fresh data in order to anticipate future events. As a result, the learning algorithm is already aware of the aim. The learning algorithm creates a function to generate predictions about the output values based on the study of a known training dataset. After enough training, the system can provide targets for any new input. The learning algorithm can also compare its output to the correct and detect faults, allowing the model to be updated as needed. Examples of Supervised Learning algorithms: Regression, Decision Tree and Random Forest etc. Supervised learning algorithms are good for the following tasks: • Binary classification: Dividing data into two categories. • Multi-class classification: Choosing between more than two types of answers. • Regression modeling: Predicting continuous values. - Classification Definition: Classification is a type of supervised learning problem where the machine tries to predicts the category or class of the given input data. For example - To classify movie into category like 'Horror', 'Comedy', 'Romantic' or predict whether a person has a particular disease or not. 2.2. Unsupervised machine learning algorithms Unsupervised algorithms, on the other hand, are utilized when the information used to train is neither classed nor labeled, or when there is no goal or outcome variable to predict. Unsupervised learning investigates how computers might infer a function from unlabeled data to describe a hidden structure. The system doesn't figure out the proper output, but it examines the data and can infer hidden structures from unlabeled data using datasets. It is commonly used for segmenting clients into separate groups for special action, and it is utilized for clustering population into separate groups. This method is currently in use in some fields, such as cybersecurity.
  • 10. UCA - SAFI 10 Examples of Unsupervised Learning: Apriori algorithm, K-means. Unsupervised learning algorithms are good for the following tasks: • Clustering: Splitting the data set into groups based on similarity. • Anomaly detection: Identifying unusual data points in a dataset. • Dimensionality Reduction: Reducing the number of variables in a data set. III. Deep Learning: 1. Definition Deep learning is an artificial intelligence (AI) function that simulates the human brain's processing of data and creation of patterns for use in decision-making by utilizing large amounts of data that would ordinarily take people decades to comprehend and process. Deep learning is an artificial intelligence subset of machine learning that uses neural networks to learn unsupervised from unstructured or unlabeled data. Deep neural learning or deep neural network are other terms for the same thing. → Deep learning is based on Neural Networks, which are made up of an interconnected web of nodes called neurons, with edges connecting them. 2. Neural Network: Unlike others network like a social network a Neural Network is highly structured and comes in layers: Figure 2: Neural Network
  • 11. UCA - SAFI 11 The input layer is the first, the output layer is the last, and any levels in between are known as hidden layers. The result of spinning classifiers together in a layered web is a neural network. Because every node in the hidden and output layers has its own classifier, this is the case. A node in the second layer, for example, receives its input from the input layer and activates its score before passing it on to the next hidden layer for further activation. Until you get to the output layer, that is. Figure 3: Neural Network (explanation) This series of events starting from the input where each activation is sent to the next layer, is known as forward propagation. Forward Propagation is a neural net’s way of classifying a set of inputs. 3. The Perceptron: The structure building block of neural network it is much more like single neuron Figure 4: Perceptron (Forward Propagation) Information is passed forward through this single neuron. We can define a set of inputs, as shown in the diagram above. These inputs are sent through a connection to the next node, where they are multiplied by their respective weights and then added together. We take the single number sigma i=1--> n(Xi*Wi) as
  • 12. UCA - SAFI 12 the result of that addition and send it through the Non-linear activation function “g” to get the final output y. We also have a bias term that lets us shift the activation function to the left or right. During this process (or in training) the weights for each connection will continuously be changing until we reach optimized weights, as the model continues to learn from data. We can see that the concept of perceptron written mathematically as a single equation you can actually rewrite this in terms of linear Algebra matrix multiplication and dot product. Examples of Activation Function: Sigmoid function Figure 5: Sigmoid Function There are many types of activation functions: Figure 6: Types of Activation Functions
  • 13. UCA - SAFI 13 It outputs a number between 0 and 1 regardless of the activation value. Because probability must also be between 0 and 1, it is suitable for issues and probability. The Rectified Linear Unit (ReLU) activation function is quite common in modern deep neural networks because of its simplicity. It is a piecewise linear function that is zero in the negative regime and strictly the identify function in the positive regime. Actually, the Purpose of activation function is to introduce non-linearities into the network. Figure 7: Non-Linearities Also, it allows us to actually deal with real data. This is really important in real life Because in the real-world data is almost always non-linear. Using a neural network with a linear activation function makes the problem really hard because no matter how deep neural network is, you only be able to produce a single line of decision boundary. Figure 8: Linear vs Non-Linear function As you can see non-linearities makes neural nets extraordinary powerful. As I said before the Perceptron is the main components of A Neural network. If we want to define A multi Output neural network we can simply add another perceptron.
  • 14. UCA - SAFI 14 Figure 9: Two Perceptron Now we have two perceptron and two outputs each one is a normal Perceptron act exactly like single perceptron. Because all the input are densely connected to all outputs, the layers are called Dense layers or fully connected layers. Weights Weights represent the strength of the connection between the nodes. Each connection between two nodes has an assigned weight. How the weights are being optimized. That’s going to depend on the optimization algorithm or the optimizer that you choose to use for your model. The most known algorithm is the SGD (Stochastic gradient descent). The goal of SGD is attempting to set models weight in order to minimize the loss function. 4. Quantifying Loss: A loss function is used by machines to learn. It's a way of determining how well a certain algorithm models the data. If the predictions are too far off from the actual findings, the loss function will return a very large number. Loss function learns to lower prediction error over time with the help of some optimization function. The loss is the error or difference between what the network is predicting for the input versus the desired output, and SGD will try to minimize this error to make our model as accurate as possible in its predictions. There are many types of loss functions: 1. Quantifying loss: The loss of our network measures the cost incurred from incorrect predictions 2. The empirical Loss: The Empirical loss measure the total loss over our entire dataset 3. Binary Cross Entropy Loss: Cross entropy loss can be used with models that output a probability between 0 and 1
  • 15. UCA - SAFI 15 4. Mean Squared Error Loss: Mean squared error loss can be used with regression models that output continuous real numbers. 5. Some types of deep learning algorithms: Deep learning models make use of several algorithms. While no one network is considered perfect, some algorithms are better suited to perform specific tasks. To choose the right ones, it’s good to gain a solid understanding of all primary algorithms such as: - Convolutional Neural Networks (CNNs) - Long Short-Term Memory Networks (LSTMs) - Recurrent Neural Networks (RNNs) But in our case, we will talk about the CNN algorithm: CNN's, also known as ConvNets, consist of multiple layers and are mainly used for image processing and object detection. CNNs are widely used to identify satellite images, process medical images, forecast time series, and detect anomalies. We will discuss the details of the CNN algorithm in the object detection section, because of the huge relation between Object detection algorithms and CNN. Figure 10: DL, ML and AI
  • 16. UCA - SAFI 16 IV. Computer vision 1. Definition Computer vision is a branch of computer science that aims to replicate portions of the human vision system's complexity, Computer vision is a field of artificial intelligence that trains computers to interpret and understand the visual world. Using digital images from cameras and videos and deep learning models, machines can accurately identify and classify objects. One of the driving factors behind the growth of computer vision is the amount of data we generate today that is then used to train and make computer vision better Figure 11 : computer vision in Action 2. How Does Computer Vision Work? The difficulty is that computers see only digital image representations. Humans can understand the semantic meaning of an image, but machines rarely do. They detect pixels. Thousands upon thousands of pixels make up an image. Three separate matrices for the three components that represent the three fundamental colors: red, green, and blue will be contained in a single image (RGB). A pixel can display other colors to the primary ones by combining different brightness levels of the different primary colors (from 0 to 255). A grayscale image, on the other hand, will only have one pixel matrix matching to the brightness of its black and white colors.
  • 17. UCA - SAFI 17 Figure 12 : pixels labeled with numbers from 0–255 In point of fact, pixel values are almost universally stored, at the hardware level, in a one-dimensional array. For example, the data from the image above is stored in a manner similar to this long list of unsigned chars: Figure 13 : combinations of RGB values to create RGB images That’s a lot of memory to require for one image, and a lot of pixels for an algorithm to iterate over. But to train a model with meaningful accuracy especially when you’re talking about Deep Learning, you’d usually need tens of thousands of images, and the more the merrier. These pixel arrays are used by deep learning algorithms in computer vision to apply statistical learning methods like linear regression, logistic regression, decision trees, and support vector machines (SVM). A computer vision model can recognize edges, discover patterns, and eventually classify and recognize objects in an image based on previously learnt patterns by examining the brightness values of a pixel and comparing them to its nearby pixels. These methods frequently necessitate the model processing, storing values, and learning patterns of comparable images containing the object of interest to be discovered and tracked in the current, unknown image. Computer vision has also been an important part of advances in health-tech. Computer vision algorithms can help automate tasks such as detecting cancerous moles in skin images or finding symptoms in x-ray and CT scans.
  • 18. UCA - SAFI 18 V. Object Detection Object detection is a computer vision and image processing technique for detecting and localizing objects, pictures, and videos. To obtain relevant results, object detection algorithms often use machine learning or deep learning. We can recognize and locate objects of interest in photos or video in a couple of seconds when we stare at them. The purpose of object detection is to use a computer to imitate this intelligence. Object detection is a key technology behind advanced driver assistance systems that enable cars to detect driving lanes, obstacles or human to improve road safety. Object detection is also useful in applications such as video surveillance or image retrieval systems. 1. Difference between Object recognition, Object localization, object detection and object segmentation: Figure 14 : Object recognition with deep learning Object recognition is a method for identifying objects in photos and videos. It is one of the most important machine learning and deep learning applications. The goal of this field is to educate machines to recognize (understand) the content of an image in the same way that humans do. Image classification takes an image as an input and outputs the classification label of that image with some probability. For Example: An image of a cat can be classified as a class label “cat” or an image of Dog can be classified as a class label “dog” with some probability. Object localization helps us to identify the location of a single object in the given image and indicate their location with a bounding box.
  • 19. UCA - SAFI 19 Object Detection algorithms act as a combination of image classification and object localization. It takes an image as input and generates one or more bounding boxes, each with a class label attached. These algorithms are capable of dealing with multi-class classification and localisation, as well as multiple occurrences of objects. Figure 15 : Review of Deep Learning Algorithms for Object Detection Object segmentation is a further extension of object detection where instances of recognized objects are indicated by highlighting the specific pixels of the object instead of using bounding box. Figure 16 : Object detection VS instance segmentation Bounding box is an imaginary rectangle that serves as a point of reference for object detection and creates a collision box for that object. Conventions used to specify bounding boxes: There are 2 main conventions followed when representing bounding boxes: 1. Specifying the box with respect to the coordinates of its top left, and the bottom right point.
  • 20. UCA - SAFI 20 Figure 17 : Specifying the bounding box 1 • (x1, y1): Represents the x and y coordinates of the rectangle's top left corner. • (x2, y2): Corresponds to the x and y coordinates of the rectangle's bottom right corner. 2. Specifying the box with respect to its center, and its width and height. Figure 18 : Specifying the bounding box 2 • (xc, yc): Represents the x and y coordinates of the bounding box's center. • Width: Represents the bounding box's width. • Height: Represents the bounding box's height • Confidence: This value shows the likelihood of finding the object in that box. A confidence level of 0.9, for example, suggests that the object in the box is 90% likely to exist.
  • 21. UCA - SAFI 21 Converting between the conventions: Depending on our needs, we can switch between multiple ways of describing the bounding box. - xc = ( x1 + x2 ) / 2 - yc = ( y1 + y2 ) / 2 - width = ( x2 — x1) - height = (y2 — y1) 2. R-CNN Model Family (Object Detection algorithms) A number of popular object detection models belong to the R-CNN family, which may stand for “Regions with CNN Features” or “Region-Based Convolutional Neural Network” This includes the techniques R-CNN, Fast R-CNN, and Faster-RCNN designed and demonstrated for object localization and object recognition. But before talking about all these techniques let’s talk deeply about CNN (Convolutional neural network) because all those deep learning–based techniques use CNN. 2.1 CNN Part: Feature Extraction and Convolution: In this figure we have two image and in each image 1 represent white and -1 represent black. And We want to classify the letter “X”. Figure 19 : Matrix of pixel values of X We want our model to basically compare images of a piece of an X piece by piece. And the really important pieces that I should look for are exactly the features.
  • 22. UCA - SAFI 22 Figure 20 : Feature Extraction The idea of convolution is actually to preserve the relationship between pixel by learning image features in small little patches of image data. to do this we need to perform an element multiplication between the filter image. Figure 21 : convolution operator Sliding window is a rectangular region of fixed width and height that “slides” across an image. For each of these windows, we would normally take the window region and apply an image classifier to determine if the window has an object that interests us. CNN Part Now we’ve gotten the mathematical foundation of convolutions. we can start how to utilize these operations of convolutions to actually build Neural network for computer vision tasks.
  • 23. UCA - SAFI 23 CNNs or Convolutional Neural Network designed specifically for the task of image classification. The goal here is to learn features directly from the image data. There are three main component and operations that are core to a CNNs. Figure 22 : CNN for classification We have seen the future of non-linearity in the activation part. We use the Pooling Layer to reduce the size of the representation to speed up the computation as well as make some of the features it detects a bit more robust. For example: We have a 4x4 input and we want to apply the Max Pooling and the output will be a 2x2 output. The way we do that Is simply by taking the 4x4 input and break it into different regions and then the output will just be the mask from the correspondingly. Figure 23 : Max pooling This is the reasoning behind it. Because we're taking a 2x2 region, the Hyperparameters in the image are just the filter size, f = 2 and s = 2 because we're striping by two. The main reason people choose max pooling is that it has been proven to function in several studies. The average can be used in place of the maximum value. 2.2 R-CNN: R-CNN was proposed by Ross Girshick in 2014. It may have been one of the first large and successful application of convolutional neural networks to the problem of object localization, detection, and segmentation.
  • 24. UCA - SAFI 24 It improves the quality of candidate bounding boxes and to take a deep architecture to extract high-level features. Figure 24 : R-CNN architecture As we see in the above figure that RCNN architecture is divided into three modules: - Regional Proposal Generation: For each image, RCNN generates 2k region proposals using selective search (Computer vision technique). - Feature Extractor: Using a deep convolutional neural network, extract features from each candidate region. - Classification and localization: The collected features are input into an SVM, which classifies them into one of several categories. - Selective Search is an item identification region proposal algorithm. It's made to be quick and have a high recall rate. It works by generating hierarchical groupings of comparable regions based on color, texture, size, and form similarity. Figure 25 : Selective search Recall and Precision:
  • 25. UCA - SAFI 25 Figure 26 : Precision & Recall Precision: a metric that measures how accurate your predictions are. To put it another way, the percentage of your predictions that are correct. Recall: Indicates how well you remember all of the positive. In our top K predictions, for example, we can locate 80% of the possible positive cases. Here are their mathematically definition: Figure 27 : precision and recall formula Limitations of this techniques: A downside of the approach is that it is slow, requiring a CNN-based feature extraction pass on each of the candidate regions generated by the region proposal algorithm. This is a problem as the paper describes the model operating upon approximately 2,000 proposed regions per image at test-time. 2.3 Fast R-CNN The R-CNN algorithm is comparable to this approach. We feed the CNN the input image instead of the region proposals to build a convolutional feature map. We take the region of proposals from the convolutional
  • 26. UCA - SAFI 26 feature map, warp them into squares, and then use a RoI pooling layer to restructure them into a fixed size so they can be fed into a fully connected layer. To predict the class of the proposed region as well as the bounding box offset values from the RoI feature vector, we use a SoftMax layer. The reason “Fast R-CNN” is faster than R-CNN is because you don’t have to feed 2000 region proposals to the convolutional neural network every time. Instead, the convolution operation is done only once per image and a feature map is generated from it. Figure 28 : fast R-CNN architecture 2.4 Faster R-CNN Both of the above algorithms (R-CNN & Fast R-CNN) uses selective search to find out the region proposals. But, it’s not the case for the Faster R-CNN algorithm. Similar to Fast R-CNN, the image is input into a convolutional network, which outputs a convolutional feature map. Rather than using a selective search approach on the feature map to find region proposals, the RPN (Region Proposal Network), a Convolutional neural network that suggests regions and the sort of object to consider in the area, is used to predict region suggestions. After that, a RoI pooling layer is used to categorize the image within the proposed region and estimate the bounding box offset values, and the projected region proposals are reshaped.
  • 27. UCA - SAFI 27 Figure 29 : faster R-CNN architecture 2.5 Comparison between R-CNN, Fast R-CNN and Faster R-CNN Figure 30 : R-CNN VS Fast R-CNN VS Faster R-CNN The mean average precision (mAP) is used to evaluate object detection algorithms like R-CNN. mAP is a common metric for measuring object detection accuracy; it compares the ground-truth bounding box to the detected box and provides a score. The higher the score, the better the model's detection accuracy.
  • 28. UCA - SAFI 28 Part 2: Application of Deep learning in Lung Cancer Detection.
  • 29. UCA - SAFI 29 I. Lung cancer The most common types of lung cancer include lung nodules, non-small cell lung cancer and small cell lung cancer. 1. Lung nodules Lung nodules are tiny tissue tumors found in the lungs. They could be benign, precancerous, or metastatic tumors from other parts of the body. A larger nodule has a higher chance of being malignant than a smaller one. 2. Non-small cell lung cancer The most frequent type of lung cancer is non-small cell lung cancer. It takes longer to grow and disseminate than small cell lung cancer. Non-small cell lung cancer is divided into three types based on the type of cells seen in the tumor: ▪ Adenocarcinoma ▪ Large cell carcinomas ▪ Squamous cell carcinoma 3. Small cell lung cancer Cigarette smoking is responsible for nearly all occurrences of small cell lung cancer. It is a rapidly spreading malignancy that spreads more faster than other types of lung cancer. Small cell lung cancer is divided into two types: ▪ Small cell carcinoma ▪ Combined small cell carcinoma 4. Stages of lung cancer Cancer stages tell how far the cancer has spread and help guide treatment. Non-small cell lung cancer for example has four main stages: ▪ Stage 1: Cancer is found in the lung, but it has not spread outside the lung. ▪ Stage 2: Cancer is found in the lung and nearby lymph nodes. ▪ Stage 3: Cancer is in the lung and lymph nodes in the middle of the chest. ▪ Stage 3A: Cancer is found in lymph nodes, but only on the same side of the chest where cancer first started growing.
  • 30. UCA - SAFI 30 ▪ Stage 3B: Cancer has spread to lymph nodes on the opposite side of the chest or to lymph nodes above the collarbone. ▪ Stage 4: Cancer has spread to both lungs, into the area around the lungs, or to distant organs. II. Frameworks and Library’s In this section, we will quote the most common libraries and frameworks used to detect cancer and especially lung cancer detection, based on the researches and project referenced in the introduction. 1. OpenCV OpenCV (Open-Source Computer Vision) is a library of programming functions mainly aimed at real- time computer vision which is written in C/C++ and has been abstracted to interface with C++, Python and Java. This is a powerful tool when working with images and has a lot of tools regarding image data manipulation, features extraction, etc.… Figure 31 : OpenCV 2. TensorFlow TensorFlow is an open-source library for numerical computation Created by the Google Brain team and has been used for research on machine learning and deep Learning. What makes Tensorflow great is its ability to be flexible to deploy computations on different devices such as CPU’s and GPU’s. Figure 32 : TensorFlow 3. Keras Keras is a deep learning framework written in python and built on top of Theano or TensorFlow. Compared to the other frameworks Keras is more minimalist.
  • 31. UCA - SAFI 31 Figure 33 : Keras 4. PyTorch PyTorch is a machine learning library for Python based on the Torch library, used for applications such as computer vision and natural language processing. The open-source software was developed by the artificial intelligence teams at FaceBook Inc. in 2016. PyTorch offers two significant features including tensor computation, as well as functional deep neural networks. Figure 34 : PyTorch III. Dataset Deep learning requires a huge amount of data in order to build a good model. So, we started searching for great dataset to build our model even before finding our final algorithm. The majority of dataset that we are going to give in this chapter are based on projects and research. 1. LUNA16 Labeled 3D - Lung Nodule Analysis Dataset 2016 The LUNA16 dataset is also 3D CT scans of lung cancer labelled by radiologists. The dataset contains 3D images and a CSV file containing annotations. Until this moment the dataset still publicly available. The format of the 3D image is a 3 dimensions array (height=512, width=512, number of images=200). One of the advantages of this dataset is that the dataset is divided into 10 subsets which make it easier to work with. After some researches I noticed that the LUNA16 dataset was drawn from another public dataset LIDC-IDRI.
  • 32. UCA - SAFI 32 Figure 35 : LUNA16 2. Kaggle 3D dataset: Data science Bowl 2017 This data was used in Kaggle competition data science bowl 2017, but the dataset is no longer publicly available due to data set usage restrictions. The dataset contains full CT scan images of a patient’s lungs in the same dimensions of the LUNA16 dataset (height=512, width=512, number of images=200). This dataset was what the Data scientist originally wanted to work with as the data was labeled as desired and useful for the project. The only problem in this dataset is the size of all the dataset it’s about 100GB. Preprocessing the entire dataset would also be too computationally heavy. Figure 36 : Data science Bowl 2017 IV. Lung Cancer Models After that we have done some researches in different projects. We inferred that the majority of projects uses CNN which is a deep learning algorithm. But, the difference between these projects is the architecture. We may find that the project is using an existing model, or the authors of the projects may build their own model based on existing one.
  • 33. UCA - SAFI 33 In this section, each one of us searched 2 projects of lung cancer, to have ideas and knowledge about this subject. Between these 8 projects we have chosen 2 performed and working project, that we will present you later. 1. First model This project treats Lung cancer Detection. The lung cancer diagnosis process requires a doctor to take multiple steps in consulting lung specialists, and receiving secondary opinions before arriving at a complete diagnosis. A user will have and input a histopathological lung image into the model and receive a full diagnosis of cell type, cancerous status, and type of malignancy if applicable. Theorical Side 1. DataSet This project is using a Kaggle dataset. There are 5 classes of data: 2 colon types (benign and malignant: adenocarcinoma) and 3 lung types (benign, malignant - adenocarcinoma (ACA) and malignant - squamous cell carcinoma (SCC). Each class contains 250 images, which were pre-augmented to 5,000 of each class. Figure 37 : first model dataset This dataset is splitted into three subsets, the first is for training, second is for validation and the third is for testing. In the training subset the data is divided a second time, in order to train each CNN effectively.
  • 34. UCA - SAFI 34 2. Architecture Figure 38 : first Model architecture
  • 35. UCA - SAFI 35 2.1. Image preprocessing In this step, they normalized the pixel intensity of the images to the [0,1] range and images were resized to 224x224 pixels for consistency and to reduce load on our model. Finally, images were transformed to tensors. In order to be fed into our first CNN in this project. Figure 39 : Image normalization 2.2 CNN 1 (Lung vs Colon) In this CNN we use the preprocessing images and distinguishes between lung and other scans. If we found that is a Lung scan, the image is fed into CNN 2 (we will talk about it later), if it’s not the output will be a request to insert a histopathological lung image. (We will talk about CNN 2 later) CNN 1 is composed of 2 Convolution layers with 5x5 Kernel, 2 Max Pool with 4x4 kernel and a flatten layer at the end for classification. Figure 40 : Lung VS Other image classification 2.3. CNN 2 (Lung Benign vs. Malignant) CNN 2 distinguishes between malignant and benign lung cells. And uses the lung scan 224x224 given by CNN 1. CNN 2 is composed of 1 Convolution layers with 5x5 Kernel, 2 Max Pool with 2x2 kernel and finally a flatten layer for classification.
  • 36. UCA - SAFI 36 Figure 41 : Lung benign VS malignant classification 2.4. CNN 4 (Lung SCC vs. ACA) CNN 4 is used to classify the type of lung cancer: adenocarcinoma or squamous cell. And uses the lung scan 224x224 given by CNN 2. CNN 4 is composed of 1 Convolution layers with 5x5 Kernel, 3 Convolution layers with 4x4 Kernel, 1 Max Pool with 2x2 kernel and finally a flatten layer for classification. All the outputs of these CNNs are either a zero or a one depending on the classification determined by the model. Figure 42: Lung malignant ACA VS SCC classification 3. Comparison between the 3 CNNs Batch Size Learning Rate # of Epochs # of Convolution Layers # of Pooling Layers # of Fully Connected Layers CNN 1: Lung vs. Colon 256 0.1 5 2 2 2 CNN 2: Lung Benign vs. Malignant 256 0.01 6 2 2 2 CNN 4: Lung SCC vs. ACA 64 0.0065 13 4 1 2 Figure 43 : Comparison between the 3 CNNs
  • 37. UCA - SAFI 37 Practical Side 1. Tools During our practical part we used different tools (PyTorch, google Colaboratory, …etc.). These tools help us to implement easily and effectively our model. We have talked previously about PyTorch FrameWork, used in this project. - Google Colab Colaboratory, or “Colab” for short, is a product from Google Research. Colab allows anybody to write and execute arbitrary python code through the browser, and is especially well suited to machine learning, data analysis and education. If you have used Jupyter notebook previously, you would quickly learn to use Google Colab. To be precise, Colab is a free Jupyter notebook environment that runs entirely in the cloud. Figure 44 : google colab 2. Implementation 2.1.Training Before using our model to predict the right outputs for histopathological images, we need first to train it. So, in this part we will give you some screenshot for important training source code and also the training results in numbers and in a plot. a. Defining the CNNs
  • 38. UCA - SAFI 38 Figure 45 : CNN1 class This function defines of the first network CNN 1, which distinguish between a lung and other scans. inputs: 224 x 224 prepossessed lung or colon image Output: Lung or colon Figure 46 : CNN2 class
  • 39. UCA - SAFI 39 This one defines our second network CNN 2, which distinguish between a benign and malignant lung scan. inputs: 224 x 224 prepossessed lung image. Output: Lung benign or malignant. Figure 47 : CNN4 class Our last network CNN 4, distinguish the type of lung cancer: adenocarcinoma or squamous cell. Inputs: 224 x 224 prepossessed malignant lung image Output: Lung malignant adenocarcinoma (ACA) or malignant - squamous cell carcinoma (SCC). b. Training function Used to train the three CNNs (Figure 45,46 and 47), in order to have good results in the testing part. In this function we will be using Binary cross Entropy (BCE) to calculate the loss, the optimizer will be SGD with momentum. And at the end of the training the trained CNN will be saved in a checkpoint_file.
  • 40. UCA - SAFI 40 Figure 48: Training Function Arguments: Net: the network (one of the three CNNs) train_loader : loading the training data. val_loader : loading the validation data. Batch_size : number of training examples utilized in one iteration. Learning_rate : the learning rate used in the optimizer. Num_epochs : the number times that the algorithm will work through the training dataset. Return: The trained network c. The training Results
  • 41. UCA - SAFI 41 Figure 49: Training CNNs This source code (Figure 49) is used to call one of the three CNNs (Figure 45, 46, 47) in order to train them by using the train_net function (Figure 48). Cuda means if we are using a GPU or not, because the GPU accelerate the training process in comparison with CPU. ✓ CNN1 Figure 50: CNN1 training Training the first CNN took us 21 minutes with GPU, it takes 1 hour when we used the CPU, which confirms that the GPU accelerate the training process. These are the training results: - Training error : 0.017 ; - Validation error : 0.024 - Training loss : 0.043 ; - Validation loss : 0.074 ✓ CNN2
  • 42. UCA - SAFI 42 Figure 51: CNN2 training Training the Second CNN took us 1 hour with GPU. And 3 hours with CPU These are the training results: - Training error : 0.010 ; - Validation error : 0.012 - Training loss : 0.024 ; - Validation loss : 0.027 ✓ CNN4 Figure 52: CNN4 training
  • 43. UCA - SAFI 43 Training the third CNN took us 1 hour 5 minutes with CPU. We didn’t use the GPU because of Google Colab limitation. Google Colab provides a single 12GB NVIDIA Tesla K80 GPU that can be used up to 12 hours continuously. These are the training results: - Training error : 0.033 ; - Validation error : 0.106 - Training loss : 0.098 ; - Validation loss : 0.355 2.2.Predicting After that we trained the CNNs and we have got really good results and high accuracy, we saved our models in checkpoint_files in order to use them for predicting new images. So, in this section we will be talking about the predicting part of our project, where we will be displaying some screenshots of source code and the output of prediction. a. Image and Model Loader Figure 53 : load model This function load our model by using the torch.load command. Arguments: Net: PyTorch neural network object. model_path: Give us where the model is located (the Path), in order to load it. Return: net: models Figure 54 : load image
  • 44. UCA - SAFI 44 Load image and prepares it for model. Arguments: image_name: String representing path of image location Return: image b. Image classification Figure 55: Image Classification Predicts output and classify the given image Arguments: CNN1: load the cnn1 model CNN2: load the cnn2 model CNN3: load the cnn3 model CNN4: load the cnn4 model Image: test image path Return: Res: the result of the classification process (prediction of the image) c. Model prediction
  • 45. UCA - SAFI 45 Figure 56 : output of the model inputs: CNN1: load the cnn1 model from his path CNN2: load the cnn2 model from his path CNN4: load the cnn4 model from his path Image: test image path Output: The prediction of the model example: [ lung, malignant, SCC] 2.3.Model study After that we obtained good results in the training and testing, we started a study in the CNNs who composes our model by trying to modify the layers of the CNNs. So, we began by adding a convolution layer in our CNNs (Figure 57) to increase the accuracy of our model, but unfortunately after training our CNNs (Figure 58), results were not as planned to be we noticed that the loss (0.66) and the error (0.4) increased in comparison with the normal CNNs (Figure 50, 51 and 52).
  • 46. UCA - SAFI 46 Figure 57: Modified CNN Figure 58: Training result (Modified CNN) As a result, we decided to use the normal CNNs because of the high accuracy and the low loss that we got during training.
  • 47. UCA - SAFI 47 2. Second model This project used VGG16 model to predict if the lung is infected with Pneumonia or not. A user will have and input an x-ray lung image into the model and receive an output that contains if the lung is infected or not. Theorical Side 1. DataSet For this project we used Kaggle dataset. This dataset is organized into 3 folders (train, test, validation) and contains subfolders for each image category (Pneumonia/Normal). There are 5863 X-Ray images (JPEG) and 2 categories (Pneumonia/Normal). Figure 59 : second model dataset (kaggle) 2. Architecture We used a simple VGG16 model by changing some parameters. VGG16 is a convolution neural net (CNN) architecture which was used to win ILSVR (Image net) competition in 2014. The most unique thing about it is that instead of having a large number of hyper-parameters they focused on having convolution layer of 3x3 filters with a stride 1 and always used same padding and Max Pooling layers of 2x2 filter of stride. In The end it has 2 FC (Fully connected layers).
  • 48. UCA - SAFI 48 Figure 60 : Second Model architect 3. How we manage to use VGG16 As you can see VGG16 predict an output of 1000 category. Basically, in the final output the model tells us if a person has a pneumonia disease or not (see figure 2). We firstly need to import VGG16 from Keras library and delete all weight, and also changing some parameter like the optimizer and at the end we made a change in the Fully connected layers to be able to give us an array of two dimension (we name it classes in the code). This array is the final prediction. The first element contains the normal case (if 1 then person is normal else the person is not normal, automatically the second case it will be 1) and so one. Figure 61 : Normal lung VS pneumonia
  • 49. UCA - SAFI 49 Practical Side • Implementation 1. Import VGG 16 from Keras Figure 62: Import of libraries and VGG16 from Keras This part helps us to import all the libraries that we need and also a model, which is VGG16, all this is imported from keras. Figure 63: Creating the model To create our model object, we used the Vgg 16 library as shown below and add preprocessing layer to the front of VGG, for the output we used the softmax activation function to classify the image. In our case, we didn’t use a pretrained VGG16. We trained the model from scratch using our the Kaggle dataset, to get used to detecting cancer. 2. model summary The image below (see figure 64), present you our model summary or structure:
  • 50. UCA - SAFI 50 Figure 64: Model Structure After that we train the model using the training set, we execute the code below to save the trained model in h5 file. Figure 65: Save Model 3. Predicting using the saved model To test the model, we need to load the h5 file (contains the trained model), an image from the testing set and resize it to 244x244. Then we use the model. Predict method, in order to predict the class of the image (is it a normal or infected lung).
  • 51. UCA - SAFI 51 Figure 66: Testing code 4. Model Output Figure 67: Model output After that we execute the code in figure 66, the model starts his prediction. When he found the result, an array shows up containing results (see figure 67). In this case the lung is infected.
  • 52. UCA - SAFI 52 Part 3: Desktop Application.
  • 53. UCA - SAFI 53 Object detection has been used in many fields, in our project, we will use it in Radiologist field. According to a recent study, doctors spend 75% of their time studying x-ray results of each patient, instead of talking to patients face-to-face to assure them so as not to panic, including working with the electronic medical records. The objective is to make a desktop application that takes an input image and do some process to finally predict a result of whether you have cancer or not. Before you select an image, we need to select, whether we will use an X-ray image to detect if you have pneumonia or not, or a histopathological image to predict if our tumor is benign or malignant if it is malignant the application precise the type of malignancy. In this section we will explain to the user how to use this application, and the tools used to build it. And finally, some source code to clarify the developing part. I. Tools We have used the tkinter framework and that’s due to its simplicity. • Definition Tkinter is implemented as a Python wrapper around a complete Tcl interpreter embedded in the Python interpreter. And is the standard Python interface to the Tk GUI toolkit. Both Tk and tkinter are available on most UNIX platforms, as well as on Windows systems. Figure 68: TKinter II. Front-end • Graphic Interface The interface contains many options that we can use: - upload an image(input). - Choosing the type of images (x-ray or Histopathological) - Reset the page - send information to Gmail and receiving output.
  • 54. UCA - SAFI 54 Figure 69 : Application desktop of the model 1. Choose the image type Before selecting and uploading any image in the application we need to choose the type of the image if is it an x-ray image or a histopathological image, because each image type has its own process. (Figure 70) If we want to upload an image without choosing type, a warning will appear (Figure 70) saying that we need to choose the image type first. Figure 70: Image type and warning popup 2. Upload an image After clicking the button select images – processing and choosing the image type, a window, that contains images, opens to select an image from you’re pc. After selecting it, the image will be displayed on the application. In the one hand if we choose the first type (x-ray), the message will tell us if we have pneumonia or not. In the other hand (Histopathological), the message tells us whether we have a benign or malignant cancer, if it’s malignant the application will specify the type (Adenocarcinoma or Squamous cell carcinoma). The whole process: - Click the ‘select image – processing ‘button:
  • 55. UCA - SAFI 55 Figure 71: Select images button - Selecting image from your device, here you have 2 types of images: ▪ X-ray ▪ Histopathological Figure 72 : Upload the image X-ray images are at your left hand and Histopathological images are at your right hand (Figure 72). 3. Output Figure 73: Selected image and the test result After selecting the desired image, you need to wait some time until the image shows up in screen and also display the message of the result (Figure 73). At your left there is the x-ray images joint with the adequate result and at your right you will find the histopathological image and the test result (Figure 73). Other type of test results:
  • 56. UCA - SAFI 56 Figure 74 : The model predictions 4. Send Email message After the output message that tells you if you have cancer or not shows up, we developed our python script to give us the possibility to send an email message that contain the result. Figure 75 :Email from the application contains the results 5. Reset button After that we get the result is displayed and the test is sent to the user email. Now we can use the reset button, in order to clean the page from old information’s (image, test result). So that we can insert another image and predict the result. Figure 76: Reset button III. Back-end • Model Integration 1. Select -processing button
  • 57. UCA - SAFI 57 def open(): root.filename = filedialog.askopenfilename(initialdir='images/',title="sellect file ",filet ypes=(("png file","*.jpeg"),("all files","*.*"))) global img global my_image img = Image.open(root.filename) img.thumbnail((400,400)) my_image = ImageTk.PhotoImage(img) my_image_label = Label(root,image=my_image).place(x=400,y=150) get_path_img(root.filename) After we click the button, first this function called to get the file path. The initial dir is for opening the image folder first. File types the model can predict on png image. We create a label to show the image on the screen after that the path of image is fed into the function to start the process of prediction. def get_path_img(path): model = load_model('model_vgg16.h5') img = image.load_img(str(path),target_size=(244,244)) x = image.img_to_array(img) x = np.expand_dims(x,axis=0) classes = model.predict(preprocess_input(x)) v1_normal = round(classes[0][0]) v1_pnemn = round(classes[0][1]) if v1_normal==1: result_frame = LabelFrame(root,text="TEST - RESULT",bg="#00adb5",fg="#ffffff") result_frame.place(x=850,y=400) Label(result_frame,text="I'm so happy for you!,you're test is positive").pack() elif v1_pnemn == 1: result_frame = LabelFrame(root,text="TEST - RESULT",bg="#00adb5",fg="#ffffff") result_frame.place(x=850,y=400) Label(result_frame,text="I'm sorry. I have some bad news.",bg="#00adb5",fg="#ffffff").pack() time.sleep(10) Label(result_frame,text="""You must be shocked at this information, I know how you feel, I don't know what to say""",bg="#00adb5",fg="#ffffff").pack() add_result(v1_normal,v1_pnemn,str(path)) The get_path_img () function load the model and the image in the first two lines, to load the image we use the image.load_img method that contain the parameter path, and also the target size of our model. We convert the image into a numpy array by the method img_to_array () function. The method numpy expand_dims insert a new axis that will appear at the axis position in the expand array shape. We store the result on classes table and we start making decision based on the result.
  • 58. UCA - SAFI 58 In the final line we call the add_result (first value is for the normal case, second for infected case, the path is optional, but just in case we will need it in the future) This method just stores the results in a table. 2. Send info button: When we click ‘send info’ the code below will be executed. This code check if the information’s name and mail are entered by the user. After that it check if the list_check_in array contains info of get_path_img () resulting. Then passes through conditions of those information to know the right message to send. The rest of the code is about sending mail by using the secured smtp protocol. def final_prcss(): name = full_name.get() mail = e_mail.get() # phone_number.get() if (not name) or (not mail) or (not list_check_in[3]): warning_msg = messagebox.showwarning('lake of information','Please make sure that all information are fitted,Also image') else: warning_msg = messagebox.showinfo('indar','Please make sure that all information a re correct') #final we will correct our app #sending email #define parameter email_user = 'lungcancerdetection21@gmail.com' email_password = 'lungcancer21' email_send = mail server = smtplib.SMTP('smtp.gmail.com',587) server.starttls() server.login(email_user,email_password) subject = 'PFE-LUNG CANCER DESIEASES' if len(list_check_in)==1: message_error = messagebox.showerror('NO INFORMATION TO SEND','Please make sure to folow the instruction of our app') else: if list_check_in[1] == 1: body = f"Hi Mr {name},nnThank you for using our app . We are so happy for th e test is positive n n PFE LUNG APP," else: body = f"Hi Mr {name},nnThank you for using our app .nn We are sorry test has shown negative result.n Make sure to visit doctor as soon as possible n n PFE LUNG APP" msg = f'Subject:{subject}nn{body}' server.sendmail(email_user,email_send,msg) server.quit()
  • 59. UCA - SAFI 59 Part 4: Project Plan.
  • 60. UCA - SAFI 60 Introduction This chapter details the project plan and reviews the different changes and steps taken within the entire development lifecycle of the project. I. Gantt chart The figures below show how the projects tasks were done using a Gannt Chart. The chart allowed a brief estimation for the amount of work that had to be done for a task. Figure 77: Project Plan Figure 78: Gantt chart
  • 61. UCA - SAFI 61 II. Project review The theorical data science tasks took too much time to achieve for the project. Although there is a generous amount of time allocated for training, testing models and the desktop app development tasks in the project. The main reason is the time taken to understand data science, and running deep learning models consume time. This is because data science is a new field for us and we have to assimilate things and don’t rush to have a solid base, that can help us to go forward. Our lack of experience in training and testing deep neural networks also impacted our progress. The desktop app development and integrating it with the model was also a new field for us, because we used new programing language, which is python, and new techniques like tkinter. Besides all that our project is working and we succeeded to finish it in time. Conclusion This section details how we constructed and planned the tasks for the project. The Gantt chart was heavily used to estimate the duration of activities and with this tool all the tasks has been achieved. General Conclusion In this project we have learned a lot of things that we never studied before, like AI, ML, DL, … etc. We used these skills in a sensible subject, which is Lung cancer detection, lung cancer is a very dangerous disease that begins in lung and he is the leading cause of cancer deaths worldwide. Detecting lung cancer by using deep learning algorithms, will save a lot of time for doctors to look after other patients and also will reduce the false positives results of doctors, due to fatigue. During this final project we faced a lot of problems, like finding the best algorithm to predict lung cancer and even when we found the right one, we faced some problem to train and test the model, because of our lack of experience in the deep learning fields. But luckily, we achieved our goals and we developed our application where detect lung cancer and returns the results.
  • 62. UCA - SAFI 62 Figures Table Figure 1: Number of Publications in Object Detection ...............................................................................................6 Figure 2: Neural Network ............................................................................................................................................10 Figure 3: Neural Network (explanation).....................................................................................................................11 Figure 4: Perceptron (Forward Propagation)............................................................................................................11 Figure 5: Sigmoid Function..........................................................................................................................................12 Figure 6: Types of Activation Functions.....................................................................................................................12 Figure 7: Non-Linearities.............................................................................................................................................13 Figure 8: Linear vs Non-Linear function....................................................................................................................13 Figure 9: Two Perceptron ............................................................................................................................................14 Figure 10: DL, ML and AI...........................................................................................................................................15 Figure 11 : computer vision in Action.........................................................................................................................16 Figure 12 : pixels labeled with numbers from 0–255................................................................................................17 Figure 13 : combinations of RGB values to create RGB images ..............................................................................17 Figure 14 : Object recognition with deep learning ....................................................................................................18 Figure 15 : Review of Deep Learning Algorithms for Object Detection..................................................................19 Figure 16 : Object detection VS instance segmentation ............................................................................................19 Figure 17 : Specifying the bounding box 1..................................................................................................................20 Figure 18 : Specifying the bounding box 2..................................................................................................................20 Figure 19 : Matrix of pixel values of X........................................................................................................................21 Figure 20 : Feature Extraction .....................................................................................................................................22 Figure 21 : convolution operator.................................................................................................................................22 Figure 22 : CNN for classification ...............................................................................................................................23 Figure 23 : Max pooling................................................................................................................................................23 Figure 24 : R-CNN architecture ..................................................................................................................................24 Figure 25 : Selective search..........................................................................................................................................24 Figure 26 : Precision & Recall .....................................................................................................................................25 Figure 27 : precision and recall formula.....................................................................................................................25 Figure 28 : fast R-CNN architecture...........................................................................................................................26 Figure 29 : faster R-CNN architecture........................................................................................................................27 Figure 30 : R-CNN VS Fast R-CNN VS Faster R-CNN............................................................................................27 Figure 31 : OpenCV......................................................................................................................................................30 Figure 32 : TensorFlow.................................................................................................................................................30 Figure 33 : Keras...........................................................................................................................................................31 Figure 34 : PyTorch......................................................................................................................................................31 Figure 35 : LUNA16......................................................................................................................................................32 Figure 36 : Data science Bowl 2017.............................................................................................................................32 Figure 37 : first model dataset .....................................................................................................................................33 Figure 38 : first Model architecture ............................................................................................................................34 Figure 39 : Image normalization .................................................................................................................................35 Figure 40 : Lung VS Other image classification ........................................................................................................35 Figure 41 : Lung benign VS malignant classification................................................................................................36
  • 63. UCA - SAFI 63 Figure 42: Lung malignant ACA VS SCC classification...........................................................................................36 Figure 43 : Comparison between the 3 CNNs ............................................................................................................36 Figure 44 : google colab................................................................................................................................................37 Figure 45 : CNN1 class .................................................................................................................................................38 Figure 46 : CNN2 class .................................................................................................................................................38 Figure 47 : CNN4 class .................................................................................................................................................39 Figure 48: Training Function.......................................................................................................................................40 Figure 49: Training CNNs............................................................................................................................................41 Figure 50: CNN1 training.............................................................................................................................................41 Figure 51: CNN2 training.............................................................................................................................................42 Figure 52: CNN4 training.............................................................................................................................................42 Figure 53 : load model ..................................................................................................................................................43 Figure 54 : load image ..................................................................................................................................................43 Figure 55: Image Classification ...................................................................................................................................44 Figure 56 : output of the model....................................................................................................................................45 Figure 57: Modified CNN.............................................................................................................................................46 Figure 58: Training result (Modified CNN) ...............................................................................................................46 Figure 59 : second model dataset (kaggle).................................................................................................................47 Figure 60 : Second Model architect............................................................................................................................48 Figure 61 : Normal lung VS pneumonia .....................................................................................................................48 Figure 62: Import of libraries and VGG16 from Keras............................................................................................49 Figure 63: Creating the model .....................................................................................................................................49 Figure 64: Model Structure..........................................................................................................................................50 Figure 65: Save Model..................................................................................................................................................50 Figure 66: Testing code.................................................................................................................................................51 Figure 67: Model output...............................................................................................................................................51 Figure 68: TKinter........................................................................................................................................................53 Figure 69 : Application desktop of the model.............................................................................................................54 Figure 70: Image type and warning popup ................................................................................................................54 Figure 71: Select images button...................................................................................................................................55 Figure 72 : Upload the image.......................................................................................................................................55 Figure 73: Selected image and the test result .............................................................................................................55 Figure 74 : The model predictions...............................................................................................................................56 Figure 75 :Email from the application contains the results ......................................................................................56 Figure 76: Reset button ................................................................................................................................................56 Figure 77: Project Plan.................................................................................................................................................60 Figure 78: Gantt chart..................................................................................................................................................60
  • 64. UCA - SAFI 64 Bibliography ➢ Machine Learning - URL: https://searchenterpriseai.techtarget.com/definition/machine-learning-ML ➢ Deep Learning – URL https://www.bpttbrightminds.com/wp-content/uploads/2020/08/Intro-to-Deep-Learning.pdf ➢ Computer Vision – URL https://towardsdatascience.com/everything-you-ever-wanted-to-know-about-computer- vision-heres-a-look-why-it-s-so-awesome-e8a58dfb641e ➢ Object Detection – component – URL https://www.geeksforgeeks.org/object-detection-vs-object-recognition-vs- image-segmentation/ ➢ Object Detection – bounding box – URL https://medium.com/analytics-vidhya/basics-of-bounding-boxes- 94e583b5e16c ➢ Object Detection – R-CNN family – URL https://machinelearningmastery.com/object-recognition-with-deep- learning/ ➢ First Project – URL https://github.com/krishnaik06/Predicitng-Lungs-Disease- ➢ Second Project – URL https://github.com/justin13601/AICancer/ ➢ First Project – Histopathological dataset- URL https://www.kaggle.com/andrewmvd/lung-and-colon-cancer- histopathological-images ➢ Second Project – X-ray dataset – URL https://www.kaggle.com/paultimothymooney/chest-xray-pneumonia ➢ Second project – VGG16 – URL https://keras.io/api/applications/ ➢ Lung Cancer- URL https://www.healthline.com/health/lung-cancer ➢ PyTorch – URL https://deepai.org/machine-learning-glossary-and-terms/pytorch ➢ Tkinter – URL https://docs.python.org/3/library/tkinter.html