In this short article, we will show how TensorFlow can be used to easily classify image data using deep neural networks. We will showcase the method using the Chest XRay image dataset available on Kaggle. Because this is an image based dataset, we will utilise Convolutional Neural Networks , along with _max pooling _to obtain our predictions.

Hopefully, this will serve as a guide that anyone can follow and try themselves to fit the model. The inner model layers can easily be altered (adding or deleting layers, adding dropouts, etc).

Chest XRay Dataset:

The Chest XRay dataset consists of thousands of images of XRays taken. The images are classified either as healthy, (Normal), or unhealthy (Pneumonia). The dataset is large and contains .jpeg files, and thus it is saved in a zipfile. We use the zipfile package to unzip the data, and create the respective training and validation directories.

Load in images:

Once you have downloaded the images, set your working directory to the location they are saved.

import os
import zipfile
local_zip = 'Xrayimage/XrayArchive.zip'
zip_ref = zipfile.ZipFile(local_zip, 'r')
zip_ref.extractall('/Xrayimage')
zip_ref.close()
base_dir = '/XrayImage/chest_xray'
train_dir = os.path.join(base_dir, 'train')
validation_dir = os.path.join(base_dir, 'test')
## Create directorys to store the normal and sick lungs
train_healthy_dir = os.path.join(train_dir, 'NORMAL')
train_sick_dir = os.path.join(train_dir, 'PNEUMONIA')
## We use these as validation i.e we don't train with these.
validation_healthy_dir = os.path.join(validation_dir, 'NORMAL')
validation_sick_dir = os.path.join(validation_dir, 'PNEUMONIA')

#convolutional-network #kaggle #machine-learning #deep-learning #data-science

Using Convolutional Neural Networks in Tensorflow to Analyse Chest XRays
3.55 GEEK