0% found this document useful (0 votes)
24 views23 pages

Requirment Analysis

The document presents a thesis on developing a multimodal machine learning model for COVID-19 detection using MobileNet and clinical data, aiming to enhance diagnostic accuracy and accessibility. It highlights the challenges of traditional diagnostic methods and the advantages of using lightweight CNN architectures for deployment in resource-constrained settings. The project emphasizes the importance of explainability in AI models to foster trust among healthcare professionals and improve clinical decision-making.
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)
24 views23 pages

Requirment Analysis

The document presents a thesis on developing a multimodal machine learning model for COVID-19 detection using MobileNet and clinical data, aiming to enhance diagnostic accuracy and accessibility. It highlights the challenges of traditional diagnostic methods and the advantages of using lightweight CNN architectures for deployment in resource-constrained settings. The project emphasizes the importance of explainability in AI models to foster trust among healthcare professionals and improve clinical decision-making.
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/ 23

Covid 19 Detection using Machine Learning Techniques

Submitted in partial fulfilment of the requirements for the degree of

Bachelor of Technology
In
Computer Science and Engineering

By

Shawray Sinha 21BCE3201

P R Anish Siddhartha 21BCE2233

Priyal Solanki 21BCE3246

Under the guidance of


Dr Anto S.

School of computer science engineering and Engineering


VIT, Vellore

1
CERTIFICATE

This is to certify that the thesis entitled “Covid 19 Detection using Machine Learning
Techniques” submitted by, SCOPE, VIT, for the award of the degree of Bachelor of
Technology in Programme, is a record of bona fide work carried out by him / her under my
supervision during the period, 15.07. 2024 to 18.11.2024, as per the VIT code of academic and
research ethics.

The contents of this report have not been submitted and will not be submitted either in part or
in full, for the award of any other degree or diploma in this institute or any other institute or
university. The thesis fulfills the requirements and regulations of the university, and in my
opinion meets the necessary standards for submission.

Place : Vellore
Date : 18-09-2024 Signature of the Guide

Internal Examiner External Examiner

2
ACKNOWLEDGEMENTS

I would like to express our deepest gratitude to our advisor and mentor, Dr. Anto S., whose expertise,
guidance, and encouragement were invaluable throughout this project. Their insights and suggestions
greatly contributed to the development and refinement of the ideas presented in this paper.
We also wish to acknowledge the support and resources provided by VIT Vellore. The access
to research materials and technical resources was instrumental in the successful completion of
this work.
A special thanks to our colleagues, for their constant support, constructive feedback, and
stimulating discussions that helped shape the direction of this research. Their willingness to
help at every stage of the project is deeply appreciated.

Student Name: Shawray sinha

3
Executive Summary

The COVID-19 pandemic has underscored the urgent need for efficient, accurate, and accessible
diagnostic tools. MobileNet, a lightweight Convolutional Neural Network (CNN) architecture, has
emerged as a promising solution in detecting COVID-19 from chest X-rays, striking a balance
between accuracy and computational efficiency. Unlike traditional CNNs like VGG16 or ResNet,
MobileNet utilizes depthwise separable convolutions, significantly reducing the number of parameters
and computational demands. This makes it exceptionally suited for deployment in resource-
constrained settings such as mobile devices and embedded systems, where quick and reliable
diagnoses are essential.
Leveraging the power of transfer learning, MobileNet can be pre-trained on large datasets like
ImageNet and subsequently fine-tuned on smaller, specific datasets related to COVID-19. This
approach accelerates the training process and enhances accuracy, even with limited data availability.
The model's adaptability to mobile platforms empowers healthcare workers in remote or underserved
areas, where access to conventional diagnostic tools may be limited, facilitating early and widespread
screening.
However, challenges persist, including the need for larger and more diverse datasets to improve model
robustness and mitigate risks like overfitting. Despite these hurdles, MobileNet's efficiency and
scalability offer a compelling solution for rapid COVID-19 screening, potentially revolutionizing
early detection efforts in the ongoing global health crisis.
Recognizing the need for faster clinical testing methods to curb the spread of COVID-19, our study
aims to develop a multimodal machine learning model that integrates MobileNet with additional
clinical data. This approach not only enhances detection accuracy but also provides explainable
insights, which are crucial for decision-making in clinical settings. By combining chest X-ray images
with relevant clinical data, the proposed model seeks to improve the reliability of COVID-19
screening, minimize direct exposure risks for healthcare professionals, and ultimately support more
effective containment and treatment strategies during the pandemic.

4
CONTENTS Page No.
Acknowledgement 3
Executive Summary 4
Table of Contents 5
Abbreviations 6
Symbols and Notations
1. INTRODUCTION 7-8
1. Objective
2. Motivation
3. Background
2. PROJECT DESCRIPTION AND GOALS 9
3. TECHNICAL SPECIFICATION 11
4. DESIGN APPROACH AND DETAILS 14
5. SCHEDULE, TASKS, AND MILESTONES 20
6. PROJECT DEMONSTRATION 21
7. COST ANALYSIS/RESULT & DISCUSSION (as applicable) . 22
8. SUMMARY 22
9. REFERENCES 23

5
List of Abbreviations

1. CNN - Convolutional Neural Network


2. COVID-19 - Coronavirus Disease 2019
3. CXR - Chest X-ray
4. CT - Computed Tomography
5. ML - Machine Learning
6. VGG - Visual Geometry Group (a type of CNN architecture)
7. ResNet - Residual Network (a type of CNN architecture)
8. MLP - Multilayer Perceptron
9. AI - Artificial Intelligence
10. GPU - Graphics Processing Unit
11. DL - Deep Learning
12. SARS-CoV-2 - Severe Acute Respiratory Syndrome Coronavirus 2
13. IoT - Internet of Things
14. RAM - Random-Access Memory
15. FL - Federated LearningIoT - Internet of Things

6
1. INTRODUCTION
The COVID-19 pandemic has posed unprecedented challenges to global healthcare systems,
necessitating rapid and accurate diagnostic methods to manage and contain the spread of the virus.
Early detection plays a critical role in mitigating transmission, guiding treatment decisions, and
ultimately saving lives. While traditional diagnostic tests, such as RT-PCR, are considered the gold
standard, they often suffer from limitations like long turnaround times, high costs, and the need for
specialized equipment and trained personnel. These limitations are particularly acute in resource-
constrained settings, where access to advanced medical infrastructure is limited.
Imaging techniques, particularly chest X-rays (CXR), have emerged as a valuable tool for the quick
identification of COVID-19-related lung abnormalities. However, the interpretation of these images
can vary significantly among radiologists, leading to inconsistencies in diagnosis. To address this
challenge, artificial intelligence (AI) and deep learning (DL) have been increasingly explored for
automating the diagnostic process, offering the potential for more consistent, accurate, and scalable
solutions.
MobileNet, a lightweight Convolutional Neural Network (CNN) architecture, stands out among deep
learning models due to its efficiency and adaptability for deployment on mobile and embedded
devices. Unlike traditional CNNs such as VGG16 or ResNet, which are computationally demanding,
MobileNet employs depthwise separable convolutions to reduce the number of parameters and
computations required. This makes it ideal for environments where computational resources are
limited, such as remote clinics, mobile health units, and developing regions. Moreover, the use of
transfer learning enables MobileNet to be pre-trained on large datasets and fine-tuned on specific
COVID-19 datasets, enhancing its accuracy even with limited data availability.
Despite the promise of MobileNet and other deep learning models, a significant challenge remains:
the need to incorporate diverse data inputs to improve diagnostic accuracy and provide a holistic view
of the patient’s condition. A multimodal approach that combines imaging data with clinical
information—such as symptoms, demographics, and lab results—can offer a more comprehensive
assessment, leading to better-informed clinical decisions. Furthermore, ensuring that AI models are
interpretable and explainable is crucial for their acceptance and trust by healthcare providers, as these
models are increasingly used in clinical settings.

7
1.1 Objective

The primary objective of this project is to develop an explainable multimodal machine learning
model that integrates chest X-ray images and clinical data to accurately detect COVID-19
infections. This model aims to provide a reliable, rapid, and scalable solution for early
detection, aiding in clinical decision-making and reducing the direct exposure risk to healthcare
professionals.

1.2 Motivation

COVID-19 has had a profound global impact, leading to significant mortality, overwhelming
healthcare systems, and causing widespread socio-economic disruption. Despite the development of
vaccines and treatments, early detection remains crucial for effective disease management and
containment. Traditional diagnostic methods like RT-PCR tests, though effective, are time-consuming
and often inaccessible in remote or resource-limited settings. Imaging techniques such as chest X-rays
offer a faster alternative; however, their diagnostic accuracy can be limited by human interpretation
variability.
The motivation behind this project is to harness the computational efficiency of MobileNet, along
with the integration of clinical data, to enhance the diagnostic capability of chest X-rays. By
leveraging lightweight CNN architectures that can be deployed on mobile and embedded devices, we
aim to democratize access to advanced diagnostic tools, particularly in underserved regions. The
inclusion of clinical data alongside imaging aims to improve diagnostic accuracy and provide
explainable outputs, making the technology more trustworthy and actionable in real-world scenarios.

Background

The COVID-19 pandemic has accelerated the need for innovative diagnostic approaches that are both
efficient and accessible. Traditional CNN architectures like VGG16 and ResNet, while powerful, are
computationally intensive and not well-suited for deployment on devices with limited resources.
MobileNet, with its depthwise separable convolutions, offers a compelling alternative by significantly
reducing computational costs without compromising on accuracy. This makes it an ideal candidate
for applications in mobile health (mHealth), where devices need to perform complex tasks under
hardware constraints.

8
Transfer learning has been widely adopted in medical image analysis, allowing models pre-trained on
large datasets to adapt quickly to specific tasks with limited data, such as COVID-19 detection.
However, the variability in disease presentation and the quality of available data pose challenges that
necessitate robust and adaptable models. This project builds upon these foundations, proposing a novel
integration of imaging and clinical data to address the limitations of existing models.

2. Project Description and Goals

This project involves the development of a multimodal machine learning model that combines
MobileNet with clinical data inputs to detect COVID-19 from chest X-rays. The workflow includes:

1. Data Acquisition: collecting and curating a dataset of chest X-ray images and corresponding
clinical data, such as patient demographics, symptoms, and laboratory results.
2. Model Development: Utilizing transfer learning, MobileNet will be fine-tuned on the
COVID-19 dataset. A parallel model will process clinical data inputs, with the outputs from
both models integrated into a multimodal framework.
3. Explainability: Implementing explainability techniques, such as Grad-CAM, to provide
visual insights into the model’s decision-making process, enhancing interpretability for
healthcare professionals.
4. Validation and Testing: The model will be validated against established benchmarks, using
cross-validation and external test datasets to ensure robustness and generalizability.
5. Deployment: Exploring the deployment of the model on mobile and embedded devices,
assessing its performance in real-world scenarios, especially in low-resource settings

Goals
1. Develop a lightweight, accurate model: Create a model that maintains high diagnostic
accuracy while being computationally efficient, suitable for deployment on mobile and
embedded devices.
2. Integrate Multimodal Data: Enhance diagnostic accuracy by integrating clinical data with
imaging, providing a more comprehensive view of the patient’s condition.
3. Improve Explainability: Ensure the model’s outputs are explainable, facilitating trust and
usability among healthcare professionals.
4. Facilitate Rapid Deployment: enable the model’s deployment in resource-constrained
9
environments, providing accessible diagnostic tools to underserved populations.
5. Contribute to Public Health: Support efforts in early detection and containment of COVID-
19, reducing transmission, and aiding in the management of future outbreaks.

2.1 Proposed Solution

The proposed solution involves developing an explainable multimodal machine learning model for
COVID-19 detection using chest X-ray images and clinical data. The core of the solution is based on
MobileNet, a lightweight Convolutional Neural Network (CNN) architecture that is optimized for
performance on resource-constrained devices. This model will leverage transfer learning, utilizing
MobileNet pre-trained on the ImageNet dataset, and fine-tuning it on specific COVID-19 datasets.

The workflow begins with setting up the environment, including the installation of necessary libraries
and dependencies such as TensorFlow and Keras. Data will be loaded and preprocessed, organizing
images into categories (e.g., COVID-19, normal). Preprocessing steps include resizing images,
normalizing pixel values, and applying augmentations to enhance model robustness.

Labels will be encoded to prepare them for classification tasks. The MobileNet model will then be
loaded, and its top layers adjusted to suit the COVID-19 detection task. The model will be trained
with a focus on monitoring accuracy and loss metrics across multiple epochs, ensuring the learning
process is optimized for the dataset in use.

Once training is complete, the model will be evaluated using a separate validation dataset, with
performance metrics such as accuracy, precision, recall, and F1 score assessed through confusion
matrix and classification reports. The final step involves testing the model on an independent dataset
to validate its generalizability and robustness in real-world scenarios.

The integration of clinical data alongside image data aims to enhance diagnostic accuracy and provide
a holistic assessment. The model will include explainability features, such as Grad-CAM, to visualize
areas of the images that contributed most to the model's decisions, thereby increasing transparency
and trust among healthcare professionals.

10
2.2 System Architecture

The system architecture for the proposed COVID-19 detection model is designed to be modular and
scalable, consisting of the following key components:

Data Acquisition and Preprocessing Module: This module handles the loading and preprocessing
of input data, including chest X-ray images and clinical information. Images are resized, normalized,
and augmented to improve model performance. Clinical data is cleaned, standardized, and encoded to
integrate seamlessly with image data.

Feature Extraction and Integration Module: MobileNet serves as the backbone for feature
extraction from the chest X-ray images. Pre-trained on ImageNet, MobileNet’s architecture is adjusted
to fine-tune on COVID-19 data. Concurrently, a separate neural network processes clinical data
inputs. The outputs from both the image and clinical data networks are concatenated to form a
comprehensive feature vector that represents the patient's condition.

Classification Module: The integrated feature vector is passed through fully connected layers, which
perform the final classification into categories such as COVID-19 positive, negative, or other
conditions. The classifier is trained to optimize cross-entropy loss and maximize accuracy.

Evaluation and Explainability Module: Post-training, the model’s performance is evaluated using
validation datasets. Key metrics, including accuracy, precision, recall, and F1 score, are computed.
Explainability tools, such as Grad-CAM, are employed to provide visual insights into the model’s
decision-making process, enhancing the transparency and interpretability of results.

Deployment Module: The final model is optimized and packaged for deployment on various
platforms, including mobile and embedded devices, ensuring accessibility in diverse healthcare
settings. The deployment process includes converting the model into formats compatible with edge
devices, such as TensorFlow Lite.

2.2 Security Considerations

11
Security is a critical aspect of deploying AI-based diagnostic tools, particularly in healthcare, where
sensitive patient data is involved. To ensure the secure operation of the COVID-19 detection model,
several key measures will be implemented:

Data Privacy and Encryption: All patient data, including chest X-rays and clinical information, will
be encrypted both in transit and at rest using industry-standard encryption protocols like AES-256.
This ensures that data remains secure from unauthorized access during transmission between the user
interface, server, and storage systems.

Access Control and Authentication: The system will incorporate robust access control mechanisms,
ensuring that only authorized personnel can access patient data and model outputs. Multi-factor
authentication (MFA) and role-based access control (RBAC) will be implemented to manage user
permissions effectively, providing different levels of access based on roles such as doctors,
radiologists, and administrative staff.

Data Anonymization: To further protect patient privacy, data anonymization techniques will be
applied before data is used for training and inference. Identifiers like patient names, addresses, and
other personally identifiable information (PII) will be removed or masked, ensuring that data used
within the system cannot be traced back to individual patients.

Secure Model Deployment: The deployment of the model on mobile and embedded devices will
include security measures such as code obfuscation, secure boot processes, and runtime application
self-protection (RASP). This will protect the model from reverse engineering and unauthorized
modifications.

2.3 Scalability and Future-Proofing

Scalability is essential for ensuring that the COVID-19 detection model can handle varying loads and
adapt to different deployment environments, from small clinics to large healthcare networks. The
design of the system emphasizes both horizontal and vertical scalability. By prioritizing security and
scalability, the proposed COVID-19 detection system aims to provide a robust, flexible, and secure
diagnostic tool that can be widely adopted across different healthcare settings. This ensures that the
system not only meets current needs but is also prepared to evolve and expand as new challenges and
opportunities arise in the ongoing battle against COVID-19 and other emerging health threats.

12
3 Technical Specifications
3.1 Development Environment:
● CPU: Quad-core Intel i5 or equivalent AMD processor
● GPU: NVIDIA GTX 1060 or higher (recommended for model training)
● RAM: Minimum 16 GB (32 GB recommended for large datasets)
● Storage: SSD with at least 512 GB for faster data access and processing
● Additional: Internet connection for accessing cloud services and repositories
3.2 Deployment Environment:
● Edge Devices: Smartphones, tablets, or embedded systems with ARM or x86 processors
● Minimum Requirements for Edge Devices:
o CPU: Dual-core processor
o RAM: 4 GB
o Storage: 32 GB (sufficient for the lightweight model and necessary data)
o Additional: Wi-Fi or cellular connectivity for data synchronization
● Cloud/Server Deployment:
o CPU: Multi-core Intel Xeon or AMD EPYC
o GPU: NVIDIA T4, V100, or A100 (for high-performance inference)
o RAM: 64 GB or more, depending on the expected load
o Storage: SSD arrays with scalable cloud storage options (AWS S3, Google Cloud
Storage)
3.3 Software Requirements
3.3.1 Development Environment:
● Operating System: Windows 10/11, macOS, or Linux (Ubuntu 20.04 or later)
● Programming Languages: Python 3.8 or higher
● Frameworks and Libraries:
o TensorFlow 2.x and Keras: For building and training the MobileNet model
o OpenCV: For image preprocessing and augmentation
o Pandas and NumPy: For data handling and numerical operations
o Scikit-learn: For evaluation metrics and additional machine learning utilities
o Matplotlib and Seaborn: For plotting graphs and visualizations (accuracy/loss,

13
confusion matrix)
3.3.2 Deployment Environment:
● Model Serving:
o TensorFlow Serving: For deploying the trained model in a production
environment
o TensorFlow Lite: For optimizing the model for edge device deployment
3.3.3 Development and Deployment Tools
● Version Control: Git with GitHub or GitLab for source code management
● CI/CD Pipeline: Google Collab or GitHub Actions for continuous integration and deployment

4 Design approach and details

The design approach for the COVID-19 detection system combines radiological and clinical data
using advanced machine learning techniques, creating a comprehensive multimodal model. Below
is a detailed breakdown of the approach and the critical elements involved:

4.1 Data Collection and Curation

Objective: To gather diverse, high-quality data that accurately represents COVID-19 cases across
different demographics and clinical presentations.

● Sources: Chest X-rays (CXRs) and clinical data were collected from multiple medical
centers and institutions to ensure diversity in imaging protocols and equipment.

● Curation: Data was anonymized to protect patient privacy and adhere to ethical standards.
The curation process involved verifying data quality, consistency, and completeness,
focusing on including cases with confirmed COVID-19 diagnoses alongside control
samples (e.g., non-COVID-19 respiratory conditions).

4.2 Pre-processing and Feature Extraction

Objective: To prepare and standardize data for model training, extracting relevant features to
distinguish COVID-19 from other respiratory conditions.

Radiological Pre-processing:

● Normalization and Resizing: CXRs were standardized in size and normalized to ensure

14
consistent input for the machine learning models.

● Data Augmentation: Techniques such as rotation, flipping, and brightness adjustment


were applied to increase data variability and reduce overfitting.

● Feature Extraction: Using convolutional neural networks (CNNs), key radiological


features were extracted:

o Bilateral Multifocal Consolidations

o Ground-Glass Opacities

o Small Pleural Effusions

Clinical Data Pre-processing:

● Handling Missing Values: Imputation techniques were employed to fill missing data
points, using mean imputation for numerical data and mode imputation for categorical data.

● Normalization: Numerical data, such as vital signs and lab results, were normalized to a
standard scale.

● Encoding Categorical Variables: One-hot encoding and label encoding were used for
categorical features, like symptoms and comorbidities.

● Feature Engineering: New features were derived from existing data to enhance model
performance, such as combining symptoms into composite indices or categorizing patients
by disease severity.

4.3 Multimodal Fusion

Objective: To integrate radiological and clinical features into a cohesive model that leverages
both data types for enhanced diagnostic accuracy.

● Fusion Strategies:

o Early Fusion: Combines data at the input level, feeding both CXRs and clinical
data directly into the model.

o Late Fusion: Processes radiological and clinical data separately, combining the
outputs at a later stage (e.g., combining logits or decision layers).

15
o Hybrid Fusion: Incorporates elements of both early and late fusion, allowing
certain features to interact early while maintaining separate pathways for others.

● Model Architectures:

o Radiological Data: CNNs were used for extracting spatial features from CXRs.

o Clinical Data: Machine learning models such as Random Forests, SVMs, and
Gradient Boosting Machines were employed to handle structured clinical data.

o Integration: Neural networks, including feedforward and recurrent layers, were


used to combine the features from both modalities, creating a single output for
COVID-19 detection.

4.4 Model Training and Evaluation

Objective: To train the integrated model, optimize performance, and ensure generalizability across
different data distributions.

● Data Splitting: The dataset was divided into training (70%), validation (15%), and testing
(15%) sets. Cross-validation was used to validate model robustness.

● Training Process: The model was trained using Adam or SGD optimizers with a learning
rate schedule to adjust learning rates during training. Loss functions such as categorical
cross-entropy were used.

● Performance Metrics: Evaluation focused on:

o Accuracy

o Sensitivity (Recall)

o Specificity

o AUC-ROC Curve

● Techniques: Cross-validation and bootstrapping were used to assess performance


variability and ensure the model performs well across unseen data.

4.5 Interpretability and Explainability

Objective: To provide insights into model decisions, enhancing trust and transparency for clinical

16
use.

● Visual Explanations: Grad-CAM was used to highlight areas of the CXRs that contributed
most to the model's decisions.

● Feature Importance Analysis: Techniques like SHAP and LIME were employed to
identify the most influential clinical features, providing clinicians with understandable and
actionable insights.

4.6 Validation and Comparison

Objective: To validate the proposed multimodal approach against existing models, ensuring its
effectiveness and superiority.

● External Validation: The model was tested on external datasets not used during training
to confirm its generalizability.

● Comparative Analysis: The performance was compared against single-modality models


(e.g., CXR-only or clinical data-only models) to demonstrate improvements in accuracy,
sensitivity, and specificity.

4.7 Ethical Considerations

Objective: To ensure that the research and application adhere to ethical standards, protecting
patient rights and privacy.

● Patient Consent and Anonymity: All data was anonymized, and patient consent was
obtained where applicable.

● Compliance: The approach followed data protection regulations such as GDPR and
HIPAA, ensuring responsible handling of sensitive health information.

5 Schedule, Tasks, and Milestones


To ensure the successful development and deployment of the COVID-19 detection system using a
multimodal ML model, the project has been divided into several key phases. Each phase includes
specific tasks and milestones that mark the progress of the project. Below is the detailed schedule,
tasks, and milestones for the project:

17
Phase 1: Project Initialization and Environment Setup
Timeline: Week 1
● Tasks:
o Set up the project environment, including the installation of necessary libraries
(TensorFlow, Keras, Scikit-learn, etc.).
o Configure hardware requirements (e.g., GPUs) and set up cloud resources if
required.
o Define the initial project scope and requirements.
● Milestones:
o Complete environment setup.
o Finalize project requirements and scope.

Phase 2: Data Collection and Pre-processing


Timeline: Weeks 2-3
● Tasks:
o Collect CXR images and corresponding clinical data from various medical sources.
o Perform data cleaning, including handling missing values and ensuring data
consistency.
o Pre-process CXR images (resizing, normalization, augmentation) and clinical data
(encoding, normalization).
o Extract radiological features from CXRs and perform initial clinical feature
engineering.
● Milestones:
o Complete data collection and ensure data quality.
o Complete data pre-processing and feature extraction.

Phase 3: Model Development and Multimodal Fusion


Timeline: Weeks 4-6
● Tasks:
o Develop individual models for CXRs and clinical data using CNNs and machine

18
learning algorithms, respectively.
o Experiment with different fusion strategies (early, late, hybrid) to integrate CXRs
and clinical data.
o Optimize model architectures and select the best-performing fusion strategy.
● Milestones:
o Develop and test initial models for CXRs and clinical data.
o Integrate the multimodal model and complete initial fusion strategy testing.

Implementation :
import psutil
def get_size(bytes, suffix="B"):
factor = 1024
for unit in ["", "K", "M", "G", "T", "P"]:
if bytes < factor:
return f"{bytes:.2f}{unit}{suffix}"
bytes /= factor
print("="*40, "Memory Information", "="*40)
svmem = psutil.virtual_memory()
print(f"Total: {get_size(svmem.total)}") ; print(f"Available:
{get_size(svmem.available)}")
print(f"Used: {get_size(svmem.used)}") ; print(f"Percentage:
{svmem.percent}%")
from google.colab import drive
drive.mount('/gdrive')
%cd /gdrive
from imutils import paths
import matplotlib.pyplot as plt
import numpy as np
import argparse
import cv2
import os
import time
!pip install tensorflow
!pip install keras
import tensorflow as tf
import keras
from sklearn.model_selection import train_test_split
from tensorflow.keras.preprocessing.image import ImageDataGenerator,
img_to_array, load_img
from keras.applications import VGG16
from keras.layers import AveragePooling2D, Dropout, Flatten, Dense, Input
from keras.models import Model, Sequential
from keras.optimizers import Adam
from keras.callbacks import ModelCheckpoint, EarlyStopping,

19
ReduceLROnPlateau
from sklearn.datasets import load_files
from sklearn.preprocessing import LabelBinarizer
from sklearn.metrics import classification_report, confusion_matrix
#The path of our data on drive
data_dir = r'/gdrive/My Drive/X-Ray'
#Loading Data
data = load_files(data_dir)
folders=os.listdir("/gdrive/My Drive/X-Ray")
print(folders)
#Convert the data and labels to Numpy arrays
X = np.array(data['filenames'])
y = np.array(data['target'])
labels = np.array(data['target_names'])
# How the arrays look like?
print('Data files - ',X[0])
print('Target labels - ',y[0])
print('Number of training files : ', X.shape[0])
print('Number of training targets : ', y.shape[0])
def convert_img_to_arr(file_path_list):
arr = []
img_width, img_height = 150,150
#Loop over the image paths
for file_path in file_path_list:
"""
Load the image, swap color channels, and resize it to be a fixed
150*150 pixels while ignoring aspect ratio
"""
img = load_img(file_path, target_size = (img_width, img_height))
img = img_to_array(img)
#update the data
arr.append(img)
return arr
# Here our data is updated and it's stocked in the X array again !
X = np.array(convert_img_to_arr(X))
# The Data Shape
print(X.shape)
print('First training item : ',X[0])
#Let's look at first 5 training data.
fig = plt.figure(figsize = (16,9))
for i in range(5):
ax = fig.add_subplot(1,5,i+1,xticks=[],yticks=[])
ax.imshow((X[i].astype(np.uint8)))
plt.title(folders[y[i]])
"""
After that data is converted into Numpy array, Now,
Let's scale the pixel intenties to the range[0,255]
"""
X = X.astype('float32')/255
# Let's confirm the number of classes :)
no_of_classes = len(np.unique(y))

20
no_of_classes
!pip install keras
"""
let's converts a class vector (integers) to binary class matrix by
performing the
one-hot encoding on the labels
"""
y = np.array(keras.utils.to_categorical(y,no_of_classes))
y[0]
# let's splite the data into subsets and explore their shapes !
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.2)
print('The train Data Shape ', X_train.shape[0])
X_test, X_valid, y_test, y_valid = train_test_split(X_test,y_test,
test_size = 0.5)
print('The validation Data Shape ', X_valid.shape[0])
print('The test Data Shape ', X_test.shape[0])
# Required libraries
import keras
from keras.models import Sequential
from keras.layers import Conv2D, MaxPool2D, Dense, Flatten, Dropout
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from keras.callbacks import ReduceLROnPlateau
from tensorflow.keras.optimizers import RMSprop
optimizer =RMSprop(learning_rate=0.001, rho=0.9, epsilon=1e-08, decay=0.0)
model.compile(optimizer, loss='categorical_crossentropy',
metrics=['accuracy'])
learning_rate_reduction=ReduceLROnPlateau(monitor='val_accuracy', patience
= 3, verbose = 1, factor = 0.5, minlr = 0.00001). What does this code do?.Where can i run it with dataset
to see the outputimport psutil
def get_size(bytes, suffix="B"):
factor = 1024
for unit in ["", "K", "M", "G", "T", "P"]:
if bytes < factor:
return f"{bytes:.2f}{unit}{suffix}"
bytes /= factor
print("="*40, "Memory Information", "="*40)
svmem = psutil.virtual_memory()
print(f"Total: {get_size(svmem.total)}") ; print(f"Available:
{get_size(svmem.available)}")
print(f"Used: {get_size(svmem.used)}") ; print(f"Percentage:
{svmem.percent}%")
from google.colab import drive
drive.mount('/gdrive')
%cd /gdrive
from imutils import paths
import matplotlib.pyplot as plt
import numpy as np
import argparse
import cv2
import os
import time

21
!pip install tensorflow
!pip install keras
import tensorflow as tf
import keras
from sklearn.model_selection import train_test_split
from tensorflow.keras.preprocessing.image import ImageDataGenerator,
img_to_array, load_img
from keras.applications import VGG16
from keras.layers import AveragePooling2D, Dropout, Flatten, Dense, Input
from keras.models import Model, Sequential
from keras.optimizers import Adam
from keras.callbacks import ModelCheckpoint, EarlyStopping,
ReduceLROnPlateau
from sklearn.datasets import load_files
from sklearn.preprocessing import LabelBinarizer
from sklearn.metrics import classification_report, confusion_matrix
#The path of our data on drive
data_dir = r'/gdrive/My Drive/X-Ray'
#Loading Data
data = load_files(data_dir)
folders=os.listdir("/gdrive/My Drive/X-Ray")
print(folders)
#Convert the data and labels to Numpy arrays
X = np.array(data['filenames'])
y = np.array(data['target'])
labels = np.array(data['target_names'])
# How the arrays look like?
print('Data files - ',X[0])
print('Target labels - ',y[0])
print('Number of training files : ', X.shape[0])
print('Number of training targets : ', y.shape[0])
def convert_img_to_arr(file_path_list):
arr = []
img_width, img_height = 150,150
#Loop over the image paths
for file_path in file_path_list:
"""
Load the image, swap color channels, and resize it to be a fixed
150*150 pixels while ignoring aspect ratio
"""
img = load_img(file_path, target_size = (img_width, img_height))
img = img_to_array(img)
#update the data
arr.append(img)
return arr
# Here our data is updated and it's stocked in the X array again !
X = np.array(convert_img_to_arr(X))
# The Data Shape
print(X.shape)
print('First training item : ',X[0])
#Let's look at first 5 training data.

22
fig = plt.figure(figsize = (16,9))
for i in range(5):
ax = fig.add_subplot(1,5,i+1,xticks=[],yticks=[])
ax.imshow((X[i].astype(np.uint8)))
plt.title(folders[y[i]])
"""
After that data is converted into Numpy array, Now,
Let's scale the pixel intenties to the range[0,255]
"""
X = X.astype('float32')/255
# Let's confirm the number of classes :)
no_of_classes = len(np.unique(y))
no_of_classes
!pip install keras
"""
let's converts a class vector (integers) to binary class matrix by
performing the
one-hot encoding on the labels
"""
y = np.array(keras.utils.to_categorical(y,no_of_classes))
y[0]
# let's splite the data into subsets and explore their shapes !
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.2)
print('The train Data Shape ', X_train.shape[0])
X_test, X_valid, y_test, y_valid = train_test_split(X_test,y_test,
test_size = 0.5)
print('The validation Data Shape ', X_valid.shape[0])
print('The test Data Shape ', X_test.shape[0])
# Required libraries
import keras
from keras.models import Sequential
from keras.layers import Conv2D, MaxPool2D, Dense, Flatten, Dropout
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from keras.callbacks import ReduceLROnPlateau
from tensorflow.keras.optimizers import RMSprop
optimizer =RMSprop(learning_rate=0.001, rho=0.9, epsilon=1e-08, decay=0.0)
model.compile(optimizer, loss='categorical_crossentropy',
metrics=['accuracy'])
learning_rate_reduction=ReduceLROnPlateau(monitor='val_accuracy', patience
= 3, verbose = 1, factor = 0.5, minlr = 0.00001). What does this code do?.Where can i run it with dataset
to see the output

23

You might also like