0% found this document useful (0 votes)
23 views

Brain Tumor Classification Using CNN on MRI Data: A PyTorch Implementation

The early detection of brain tumors and correct diagnosis are key factors capable of influencing the success of treatment and more importantly patient outcome. In this study, we hypothesize that MRI data set of brain tumors can be classified and detected using a deep learning method of Convolutional Neural Network (CNN) built on PyTorch.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Brain Tumor Classification Using CNN on MRI Data: A PyTorch Implementation

The early detection of brain tumors and correct diagnosis are key factors capable of influencing the success of treatment and more importantly patient outcome. In this study, we hypothesize that MRI data set of brain tumors can be classified and detected using a deep learning method of Convolutional Neural Network (CNN) built on PyTorch.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Volume 10, Issue 1, January – 2025 International Journal of Innovative Science and Research Technology

ISSN No:-2456-2165 https://doi.org/10.5281/zenodo.14621403

Brain Tumor Classification Using CNN on MRI Data:


A PyTorch Implementation
1
Rambarki Sai Akshit; 2Konduru Hema Pushpika; 3Rambarki Sai Aashik;
4
Dr. Ravi Bhramaramba; 5Sayala Manjith; 6 Paladugu Madhav

1,5,6
U.G. Student, Department of Computer Science Engineering, GITAM University, Visakhapatnam, India
2
M.S. Student, Department of Data Science Engineering, University of Maryland Baltimore County, USA
3
M. Tech Graduate, VLSI Design, GITAM University, Visakhapatnam, India
4
Professor, Department of Computer Science Engineering, GITAM University, Visakhapatnam, India

Abstract:- The early detection of brain tumors and The present research paper discusses the application of a
correct diagnosis are key factors capable of influencing CNN designed in PyTorch for identification and classification
the success of treatment and more importantly patient of brain tumors based on MRI data set. The intention of
outcome. In this study, we hypothesize that MRI data set obtaining this model is to train it in a dataset of labeled brain
of brain tumors can be classified and detected using a tumors images to improve the diagnosis in the health sectors.
deep learning method of Convolutional Neural Network The system is able to detect gliomas, meningiomas and
(CNN) built on PyTorch. It utilized a sufficiently large pituitary tumors with high F1 score of all the tested subtypes
Dataset obtained from Kaggle and incorporated various assisting the practical clinical applications. In the end, this aim
techniques of data augmentation in the training of this research work is to provide effective assistance to
procedure to enhance its robust and generalization clinician in regards to brain tumors diagnosis containing an
capability. The architecture of the CNN comprises of outline of the diagnostic process.
several convolutional layers, which allows the model to
recognize complex features present in the MRI data set. Diagnostic imaging and classification of brain tumors
With the network architecture trained using the Adam are vital operations in the realm of neuro-oncology and inform
optimizer, the model could successfully differentiate the patient’s outcome. Existing practices regarding the
between tumor and non-tumor images. Model validation analysis of MRIs are performed through human intervention
metrics such as confusion matrices, accuracy, precision, usually causing bias, time, and error in the outcome. New
recall ratio, F1 and other metrics were used to validate technologies have emerged however, with deep learning
the model. The findings indicated that the tumor and proven to be an ability that can substitute and improve the
healthy images classification is achieved with a high processes for better diagnosis. This study presents a finer,
degree of accuracy with an adequate ability to generalize faster, and more accurate brain tumor identification and
to the validation dataset. typing application based on CNN and PyTorch platform. In
this direction, the research intends to harness deep learning to
Keywords:- CNN, Brain Tumor Detection, Deep Learning, improve the manner in which the diagnosis is performed
Pytorch, Tumor Segmentation. which will aid health organizations in formulating appropriate
treatment for patients in a timely manner.
I. INTRODUCTION
II. METHODOLOGY
In the field of neuro-oncology, one of the most
dangerous pathologies is brain tumors, where correct and This subsection explains the procedures that have been
timely diagnosis is essential in saving a patient’s life. undertaken in constructing and assessing the brain tumor
However, the inspection of MRI scans manually is quite detection model. It explains the process followed in the course
tedious, and so human error often creeps in, which makes it of the model development which includes data collection, data
difficult for radiologists to provide accurate diagnosis preprocessing, and dataset partitioning for training and
consistently. New technologies such as CNN contribute validation. Several methods are used to augment the images in
significantly to medical imaging in different fields that did not order to improve the performance of the model by making it
exist before deep learning came in. Such models have the robust to variations in the input data. The most important
capabilities of learning nontrivial patterns and features from aspect of the methodology is that of the tumor classifier; a
images which comes in handy in differentiating brain tumor type of CNN that utilizes the processed MRI data set to
types. classify the tumor types. The last stage is model training
where the classifier is trained on a learning schedule in order
to optimize performance without overfitting. Every step
explains how the model is capable of performing in real life
without compromising reliability.

IJISRT25JAN041 www.ijisrt.com 103


Volume 10, Issue 1, January – 2025 International Journal of Innovative Science and Research Technology
ISSN No:-2456-2165 https://doi.org/10.5281/zenodo.14621403

A. Brain Tumor Dataset Acquisition and Preprocessing configuration that describes a model that suffers from
Strategies overfitting is avoided. This strategy allows one to attribute the
The data set for brain tumor detection was downloaded model performance on a more clinical level and ensures that
from the internet it consists of MRI scans marked as ‘Brain when deployed the model will be highly accurate.
Tumor’ and ‘Healthy’. The data was arranged in folders and
brought into the system for use. The data was then categorized D. Tumor Classifier
as training and validation data, where it was split 80% into Regarding this research, the design of the tumor
training and 20% into validation. A constant image size was classifier is based on the images gathered from this study,
adopted for all images and pixel wise scaling was done to which is a CNN – Deep Learn model, and is mended in image
count take care of variance. Additionally, all images were segmentation. For this study too, the tumor classifier is more
resized to a uniform dimension, and pixel-wise normalization or less modeled in a CNN in which the emphasis is more
was applied to mitigate the effects of varying brightness and about MRI imagery feature extraction. The architecture
contrast across the MRI scans. Image preprocessing also comprises of four convolutional layers with filters of
involved converting the images into grayscale to reduce successively larger dimensions in order to extract more
complexity while preserving essential features for tumor complex structural elements from the images. Consequences
detection. of this additive procedure is that the model could identify such
things as complex patterns of tumor associations.
B. Methods of Data Augmentation
Data augmentation helps in the increase of the variability Features maps extraction occurs after every convolution
of the training dataset through the use of different changes on operation and this is referred to saturation pooling. It reduces
videos/images. Important methods include performing the burden of processing demands but on the same hand
standardization mean-variance, where subject's video images makes sure that the most important elements remain thus
sizes upon capture are made the same. To add variability in increasing the efficiency of the network. Following the
terms of the orientation of images, random horizontal and processes of convolution and pooling, there are what are
vertical flips (or both) are done while random rotation allows called fully connected layers which are used for classification
adjustment of images using different angles. In addition to of the features formed. The features that are gotten out must
random horizontal and vertical flips, random rotations are belong some class type which in this case belongs to a tumor
applied at varying angles to enhance the model's robustness to or a healthy.
orientation changes. Techniques such as brightness
adjustment and zoom are also incorporated, further simulating ReLU (Rectified Linear Unit) or some of its variants are
real-world variability. These augmentations contribute to introduced in order to capture the nonlinear characteristic of
improved generalization by training the model to perform the model. This option guarantees that some level of
under diverse and unseen conditions. Average Normalization interactions among features is captured without the limitation
shifts the pixel values with its mean and divides the result of linearity. In addition, dropout regularization is also
with a factor equal to the standard deviation for this reason; it included as deployed to improve the generalization
is used to improve the learning process. Such changes are performance of the model.
beneficial for the model to be able to perform effectively as if
those conditions exist. This technique helps in enhancing the E. CNN Architecture Description
model’s performance and stability towards new and rare data. The architecture of the visualized CNN model is aimed
at classification from MRI scans of brain tumors. This
C. Data Preparation and Splitting includes four layers of convolution in order to ensure spatial
To improve model learning where paradigms with and hierarchical features are progressively extracted from the
computerized models are used and to tighten the evaluation of input image as part of the layers' structure. On every layer, the
the model performance, the dataset is split into training and convolution increases on the number of filters used that
testing datasets. For the model building, the division made ranges from 8 to 64, followed by ReLU activation to
sure that 80% of the data is given so that salient features are introduce non-linearity, and MaxPooling layers to reduce
captured by the model. The remaining 20% is saved for dimensionality while keeping the essential patterns captured.
validation purposes and this serves as a way of controlling The MaxPooling operation helps in down sampling and keeps
how models perform as path is trained. This division also the essential features.
minimizes overfitting in that the model is able to perform well
on data it has not seen before. The use of cross-validation Following the convolution layers is the shift in
procedures can also improve on this as they test the model architecture to fully connected layers. The first fully
with various portions thus increasing the reliability of the connected layer had 100 neurons, and the second had 2
model in use. The purpose of stratified sampling when neurons, which are for the output of the binary classification
splitting the dataset is to ensure that both classes—tumor and as either healthy or tumor-affected. The last layer used
healthy—are present and in appropriate proportion to their softmax activation to convert raw output scores into
occurrence. This greatly improves the learning of the model as probabilities, hence letting the model perform binary
every class is better represented, and in turn helps augment the classification. Backpropagation through the Adam optimizer
performance of the model to training and evaluation tasks. is used to get the weights in the architecture to converge
This means that the learning and validation aspects of the faster.
model are well taken care off such that development of a

IJISRT25JAN041 www.ijisrt.com 104


Volume 10, Issue 1, January – 2025 International Journal of Innovative Science and Research Technology
ISSN No:-2456-2165 https://doi.org/10.5281/zenodo.14621403

This model's structure is optimized to capture those very classifier has been validated for accuracy and reliability in
faint differences in brain tumor images, and it captures distinguishing normal cases and tumor cases. The architecture
textures and edges within shapes based on the specifics of the signifies a balance drawn between depth, feature extraction
MRI scans, the fully connected layer which is used classifying and computational efficiency which makes it particularly
those features. The use of data augmentation during training well-suited for medical image analysis, especially for neuro-
helps the model generalize better to unseen data and the oncological diagnoses.
evaluation metrics like confusion matrices ensure that a

Fig. 1. CNN Model

IJISRT25JAN041 www.ijisrt.com 105


Volume 10, Issue 1, January – 2025 International Journal of Innovative Science and Research Technology
ISSN No:-2456-2165 https://doi.org/10.5281/zenodo.14621403

F. Model Training improvements in performance and are used to detect


The model was trained based on an adaptive learning overfitting.
rate strategy, which dynamically changes based on trends
observed in validation losses during optimization of The training framework also enforces saving the best
parameters. This is critical since it can fine-tune the weights parameters of the model in validation. This will be saved
of the model to minimize classification errors over the because it is through that the practical deployment of the
training data. A learning rate is decreased once validation trained model can be ensured and that this classifier will still
performance becomes plateaued; this allows more tuning and perform well in real applications. The iterative nature of this
enhances the ability of the model to converge toward optimal training along with careful monitoring and adjustment of
solutions. parameters are what contributes to the overall robustness and
reliability of the brain tumor detection model. From Figure 2,
The loss function selected is such that it penalizes a lot we can observe that both training and validation losses
for the wrong prediction as compared to a correct one, hence decrease over time, showing that the model learns from the
tending to drive the network more toward improving its data. It is seen that the loss stabilizes, indicating
predictive accuracy. It involves several epochs consisting of convergence. From Figure 3, it is seen that the accuracy
rounds where the model is subjected to exposure to the increases steadily for both training and validation, reaching
training dataset followed by evaluation against the validation above 95%, showing effective learning and generalization of
set based on its performance. Throughout the training the model. The close alignment between training and
process, key metrics such as accuracy and loss determine validation suggests minimal overfitting.

Fig. 2. Loss Graph - Number of epochs (0-60) vs. Loss value (0-0.6)

Fig. 3. Accuracy Graph - Number of epochs (0-60) vs. Accuracy values (0.65-1.00)

IJISRT25JAN041 www.ijisrt.com 106


Volume 10, Issue 1, January – 2025 International Journal of Innovative Science and Research Technology
ISSN No:-2456-2165 https://doi.org/10.5281/zenodo.14621403

III. EVALUATION AND RESULTS

A. Confusion Matrix
A confusion matrix was constructed as shown in (Figure 4), exhibiting a good performance. There are a total of 489 true
positives (correctly identified brain tumors) and 405 true negatives (correctly identified healthy cases) derived from the data set, as
shown in confusion matrix. This is evidence of a model that is not overfit, and generalization has been done to new data.

Fig. 4. Confusion Matrix

B. Performance Analysis management and treatment of the patient. The recall is


A number of metrics including precision, recall, F1- computed as follows –
score, and overall accuracy were computed to evaluate the
performance of the classifier. Learning curves show that 𝑇𝑟𝑢𝑒 𝑃𝑜𝑠𝑖𝑡𝑖𝑣𝑒𝑠
there is an upward trend that both training and validation 𝑅𝑒𝑐𝑎𝑙𝑙 =
𝑇𝑟𝑢𝑒 𝑃𝑜𝑠𝑖𝑡𝑖𝑣𝑒𝑠 + 𝐹𝑎𝑙𝑠𝑒 𝑁𝑒𝑔𝑎𝑡𝑖𝑣𝑒𝑠
accuracies are going up to a point of nearly 99% within 60
epochs (Figure 3). The precision, recall, accuracy and F1-  F1-Score:
Scores for both classes are calculated as described further. Fu and Vijaya (2015) observed that F1 score is the ratio
of twice the product of precision and recall to the addition of
 Precision: precision and recall. F1 encompasses all this by assuming the
Precision is defined as the ratio of true positive harmonic mean of both precision and recall thus enabling the
predictions to all the positive predictions by the model. In over reliance on one metric to be partially overcome. In our
case of the detection of brain tumors, high precision would study, it is especially important in the situation, where there
mean that whenever the model predicts something as being a are more healthy samples than tumor samples. Higher scores
tumor, in most of the cases, it is supposed to be a tumor. In simply imply the score toward the F1 score is near to the
other words, precision is very essential for ensuring minimal value of the model for both detection of the tumor and
false positives that may create unnecessary anxiety and avoidance of false alarm. The score calculation is as follows
subsequent medical procedures for patients. Precision can be –
calculated as follows:
𝑃𝑟𝑒𝑐𝑖𝑠𝑖𝑜𝑛 ∗ 𝑅𝑒𝑐𝑎𝑙𝑙
𝑇𝑟𝑢𝑒 𝑃𝑜𝑠𝑖𝑡𝑖𝑣𝑒𝑠 𝐹1 − 𝑆𝑐𝑜𝑟𝑒 = 2 ∗
𝑃𝑟𝑒𝑐𝑖𝑠𝑖𝑜𝑛 = 𝑃𝑟𝑒𝑐𝑖𝑠𝑖𝑜𝑛 + Recall
𝑇𝑟𝑢𝑒 𝑃𝑜𝑠𝑖𝑡𝑖𝑣𝑒𝑠 + 𝐹𝑎𝑙𝑠𝑒 𝑃𝑜𝑠𝑖𝑡𝑖𝑣𝑒𝑠
 Accuracy:
 Recall: This depicts the absolute performance level of the
Also called as sensitivity, recall may also be evaluated model, describing the ratio of correct prediction instances to
in terms of the ability of the model to correctly identify all actual instances-prediction of true positives as well as true
the actual positive cases. In the context of our study, a high negatives. In our model for brain tumor detection, high
recall indicates that the model is able to evaluate most of the accuracy means that the system identifies healthy vs. tumor-
tumors present in the MRI data set. This is quite important affected MRIs precisely, which would serve as a significant
because a failure to diagnose a tumor can adversely affect the

IJISRT25JAN041 www.ijisrt.com 107


Volume 10, Issue 1, January – 2025 International Journal of Innovative Science and Research Technology
ISSN No:-2456-2165 https://doi.org/10.5281/zenodo.14621403

basis for practical application in clinical situations. Accuracy can be calculated thus –

𝑇𝑟𝑢𝑒 𝑃𝑜𝑠𝑖𝑡𝑖𝑣𝑒𝑠 + 𝑇𝑟𝑢𝑒 𝑁𝑒𝑔𝑎𝑡𝑖𝑣𝑒𝑠


𝐴𝑐𝑐𝑢𝑟𝑎𝑐𝑦 =
𝑇𝑜𝑡𝑎𝑙 𝑆𝑎𝑚𝑝𝑙𝑒𝑠

Table 1 Performance metrics


Class Precision Recall F1-Score
0.0 (Healthy) 0.98 0.97 0.98
1.0 (Tumor) 0.97 0.98 0.97
Accuracy - - 0.98

Hence, with the calculation methods as specified for the [2]. Kevin P. Murphy. 2012. Machine Learning: A
parameters under study – Precision, Recall, F1-Score, Probabilistic Perspective. The MIT Press.
Accuracy, it is observed that the accuracy is recorded at 97%. [3]. S. Shanjida, M. S. Islam and M. Mohiuddin, "Hybrid
The precision, recall and F1 scores for both classes are at model-based Brain Tumor Detection and Classification
nearly 0.97 which is a good indicator in evaluating the using Deep CNN-SVM," 2024 6th International
performance distribution among the classes. Conference on Electrical Engineering and Information
& Communication Technology (ICEEICT), Dhaka,
IV. CONCLUSION Bangladesh, 2024, pp. 1467-1472, doi:
10.1109/ICEEICT62016.2024.10534376.
The present study introduces a vast methodology in the [4]. A. Pashaei, H. Sajedi and N. Jazayeri, "Brain Tumor
development of a machine learning-based brain tumor Classification via Convolutional Neural Network and
detection system using CNN. Thus, the approach begins with Extreme Learning Machines", Proceedings of the 2018
the selection of the appropriate labeled MRI dataset followed 8th International Conference on Computer and
by splitting the same into training and validation sets to Knowledge Engineering (ICCKE), pp. 314-319, 25–26
ensure reliability in the proposed model. The model is trained October 2018.Prokop, Emily. 2018. The Story Behind.
for generalization well through various conditions prevailing Mango Publishing Group. Florida, USA.
in images using different types of image augmentation [5]. H. Mohsen, E.-S.A. El-Dahshan, E.-S.M. El-Horbaty
techniques like resizing, flipping, and normalization. and A.-B.M. Salem, "Classification using deep
learning neural networks for brain tumors", Future
The CNN showed good performance on the F1 score as Comput. Inform. J, vol. 3, pp. 68-71, 2018.Brian K.
0.9784, meaning it has been accurate for the brain tumors Reid. 1980. A high-level approach to computer
with the least number of false positives and false negatives. document formatting. In Proceedings of the 7th Annual
This is an important thing concerning the clinical setting, as a Symposium on Principles of Programming Languages.
misdiagnosis made will have a devastating effect on patient ACM, New York, 24–31.
care. Thus, the results reflect not only the ability of the https://doi.org/10.1145/567446.567449
proposed system to be accurate but also to help in achieving [6]. GeÌ ron, A. (2019). Hands-on machine learning with
early diagnosis-an essential factor in improving the patient Scikit-Learn, Keras and TensorFlow: concepts, tools,
outcome. and techniques to build intelligent systems (2nd ed.).
O'Reilly.
This study goes beyond mere classification; it hints at [7]. Russell, Stuart J. (Stuart Jonathan), 1962-. Artificial
the possibility of inducting artificial intelligence in medical Intelligence: a Modern Approach. Upper Saddle River,
diagnostics. Further studies shall continue to look at ways of N.J. :Prentice Hall, 2010.
improving the size of the dataset and the architecture of the [8]. Andrew Trask. 2019. Grokking Deep Learning (1st.
model. Then, there should be validation studies through ed.). Manning Publications Co., USA.
clinical trials attesting that the system is functional. In a [9]. A. Wulandari, R. Sigit and M. M. Bachtiar, "Brain
nutshell, this effort provides a basis for application of Tumor Segmentation to Calculate Percentage Tumor
advanced AI techniques in oncology towards a venue for Using MRI," 2018 International Electronics
diagnostic accuracy and better patient management into the Symposium on Knowledge Creation and Intelligent
context of brain tumors. Computing (IES-KCIC), Bali, Indonesia, 2018, pp.
292-296, doi: 10.1109/KCIC.2018.8628591. keywords:
REFERENCES {Tumors;Brain;Magnetic resonance imaging;Image
segmentation;Filtering;Image color
[1]. Mahmoud Khaled Abd-Ellah, Ali Ismail Awad, Ashraf analysis;Bones;Thresholding;Segmentation;Brain
A. M. Khalaf and Hesham F. A. Hamed, "Two-phase Tumors;MRI Image},
multi-model automatic brain tumour diagnosis system
from magnetic resonance images using convolutional
neural networks", in Eurasip Journal on Image and
Video Processing, 2018.

IJISRT25JAN041 www.ijisrt.com 108


Volume 10, Issue 1, January – 2025 International Journal of Innovative Science and Research Technology
ISSN No:-2456-2165 https://doi.org/10.5281/zenodo.14621403

[10]. Abd El Kader Isselmou, Guizhi Xu, Shuai Zhang, Sani


Saminu, and Imran Javaid. 2019. Deep Learning
Algorithm for Brain Tumor Detection and Analysis
Using MR Brain Images. In Proceedings of the 2019
International Conference on Intelligent Medicine and
Health (ICIMH 2019). Association for Computing
Machinery, New York, NY, USA, 28–32.
https://doi.org/10.1145/3348416.3348421
[11]. T. P. Pries, R. Jahan and P. Suman, "Review of Brain
Tumor Segmentation, Detection and Classification
Algorithms in fMRI Images," 2018 International
Conference on Computational and Characterization
Techniques in Engineering & Sciences (CCTES),
Lucknow, India, 2018, pp. 300-303, doi:
10.1109/CCTES.2018.8674150. keywords:
{Tumors;Feature extraction;Image
segmentation;Classification algorithms;Functional
magnetic resonance imaging;Support vector
machines;Clustering algorithms;fMRI;brain
tumor;machine learning},
[12]. Mahmoud Al-Ayyoub, Ghaith Husari, Omar Darwish,
and Ahmad Alabed-alaziz. 2012. Machine learning
approach for brain tumor detection. In Proceedings of
the 3rd International Conference on Information and
Communication Systems (ICICS '12). Association for
Computing Machinery, New York, NY, USA, Article
23, 1–4. https://doi.org/10.1145/2222444.2222467
[13]. A. Goswami and M. Dixit, "An Analysis of Image
Segmentation Methods for Brain Tumour Detection on
MRI Images," 2020 IEEE 9th International Conference
on Communication Systems and Network
Technologies (CSNT), Gwalior, India, 2020, pp. 318-
322, doi: 10.1109/CSNT48778.2020.9115791.
keywords: {Image processing;MRI images;Brain
Tumour;Image Segmentation;Image Segmentation
Techniques;Brain Tumour Detection},

IJISRT25JAN041 www.ijisrt.com 109

You might also like