# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# + [markdown] id="2eSUHcQu2pSr"
# **Aim of the Project** Aim of the project is to Detection Of COVID-19 From Chest X-Rays, artificial intelligence in medicine is to provide composite, panoramic views of individuals’ medical data; to improve decision making, avoid errors such as misdiagnosis and unnecessary procedures, help in the ordering and interpretation of appropriate tests, and recommend treatment
#
# **Background** It is a machine learning (ML) algorithm that tries to learn the features by itself. In simple words, ML is a subset of artificial intelligence (AI) and involves the study of computer algorithms that improve automatically using experience. A branch of machine learning, deep learning utilizes multilayer artificial neural networks inspired by the neurons (basic working unit) in the human brain. A deep neural network analyzes data (with learned representations) similar to the ways by which any of us would look at a complex problem..
#
# **Business Requirement** Basically, here we are giving a number of chest x-ray images (examples — training data) to the machine and we inform it whether they indicate that the person is normal/ healthy or do they have possible COVID-19 traits. With more and more examples, the machine learns the relevant features. Now, if we give it a new chest x-ray, it tries to predict whether it is normal or does it have SARS-CoV-2 infection
#
# **Suggested Approach** This model uses 12 layers of a neural network and has the advantage of learning the disease diagnosing features from x-ray images in an automatic manner. Utilizing the right combinations of algorithms and data, this tool is useful in terms of its rapidness and reliability. Moreover, it can further be trained and made available for wider use by the public
#
# **Sources of Input**
# The data available in the public domain was used to develop this tool. This information consisted of the normal chest x-ray features as well as those of other lung diseases such as pneumonia, tuberculosis, and so forth. As of now, there are a few examples (images) that are publically available for COVID-19. The researchers pooled all this data from different sources available on the Internet.
#
# **Disclaimer **
# Use only standard X-ray images.
# It is an AI diagnose CVD-19 detector which works on only chest X-Ray.
# Our model has 2049 distinct images from 1800 distinct patients, 708 COVID-19 images, Heathy patients XRay images, with this information our model is 95% accurate.
# The intention of CVD-19 Detector is to be used as a reference model that can be built upon and enhanced as new data becomes available. We are currently at a research stage and not yet intended as production-ready models. It means we are not saying people to use as a direct clinical diagnosis. We are working continuously to improve our model as new data becomes available. Please do not use this model for self-diagnosis and seek help from your local health authorities.

# + [markdown] id="c17ElSMzd8vy"
# #Mount the Google Drive to Google Colab
#

# + colab={"base_uri": "https://localhost:8080/"} id="zXDJhiwDuQw1" outputId="aa4963df-4589-46b5-c29b-60a0922a2923"
from google.colab import drive
drive.mount("/content/drive")

# + [markdown] id="vl2JdAeYeTbM"
# #Downloading the dataset directly to Google Drive via Google Colab
# Import the required libraries and dataset

# + id="O4F43OYqus80"
import pandas as pd
import os
import numpy as np
import matplotlib.pyplot as plt
# %matplotlib inline
from zipfile import ZipFile
datasetdir = "/content/drive/My Drive/COVID-19 Radiography Database/COVID-19 Radiography Database"
#zf = ZipFile(file_path+'/archive.zip', 'r')
#zf.extractall(file_path+'/COVID-19 Radiography Database')
#zf.close()
#from google.colab import drive
#drive.mount("/content/drive")

# + [markdown] id="pFCmN5VPFGmf"
# ## Preparing data for CNN
# COVID-19 Radiography Database(3 directories, 4 files)
#
#
# **About this directory**
# Database of chest X-ray images for COVID-19 positive cases along with Normal and Viral Pneumonia images.In our current realease, there are 219 COVID-19 positive images, 1341 normal images and 1345 viral pneuomonia images. We will continue to update this database as soon as we have new x-ray images for COVID-19 pneumonia patients. Main objective is to researchers can use this database to produce useful and impactful scholarly work on COVID-19, which can help in tackling this pandemic.

# + colab={"base_uri": "https://localhost:8080/"} id="CcHullX7MBRd" outputId="4e55bd3c-eed5-4211-ef6d-c05970c7c5f3"
os.listdir(datasetdir)

# + [markdown] id="37rVSmhqkVzr"
# Sample “normal” (i.e., not infected) X-ray images from healthy patients

# + colab={"base_uri": "https://localhost:8080/", "height": 293} id="MOGj9d84o80U" outputId="2a9b1d33-370c-4563-e41e-c67ee83d63d6"
import glob
from tensorflow.keras.preprocessing import image
normal_images = []
count = 0

for img_path in glob.glob(datasetdir + "/NORMAL/*"):
    count += 1
    normal_images.append(image.load_img(str(img_path), target_size = (150,150,3)))
    if count > 230:
        break
    
fig = plt.figure()
fig.suptitle("Normal Lungs")
plt.imshow(normal_images[0], cmap="gray")
plt.show()



# + [markdown] id="1WV15XO7ka3U"
# Sample an open source dataset of X-ray images for patients who have tested positive for COVID-19

# + colab={"base_uri": "https://localhost:8080/", "height": 293} id="UKH8Gv_Apl8a" outputId="7f6d491a-3ab9-4367-f2a1-8ee4afa3d390"
covid_images = []
for img_path in glob.glob(datasetdir  + "/COVID-19/*"): 
    covid_images.append(image.load_img(str(img_path), target_size = (150,150,3)))
    
fig = plt.figure()
fig.suptitle("Covid-19 Patient's Lungs ")
plt.imshow(covid_images[0], cmap = "gray")
plt.show()

# + colab={"base_uri": "https://localhost:8080/"} id="05FA5okHIPqH" outputId="93f36219-6690-48fa-f719-c8346e426014"
print(str(len(normal_images))+" normal patient images")
print(str(len(covid_images))+" covid patient images")

StarcoderdataJupyterScriptsDedupFiltered