Classifying blood cell images with Tensorflow
Hello everyone! In this blog, we will learn how to write a script in Python which can classify blood sample images we take from a Kaggle dataset.
Identifying and categorizing patient blood samples is a standard part of diagnosing blood-based disorders. Methods for detecting and classifying automated blood cell subtypes have substantial medicinal implications.
We will use the dataset taken from:
12,500 augmented pictures of blood cells (JPEG) with cell type labels are included in this dataset (CSV). There are around 3,000 photos for each of the four cell types, which are organized into four folders (according to cell type). Eosinophils, lymphocytes, monocytes, and neutrophils are the four cell types.
Kaggle, Blood Cell Images dataset
First, we will start with importing the required libraries.
We will print our figures in a 20x20 frame to see the pictures beforehand. From the dataset, we input the folder of the training data to the script and store the value in a variable called test_folder
. The for loop will show us five different pictures from the training set.
Here we declare our image width and height and use the function to create two arrays of data, consisting of information about the filenames in the input directories. The function is also used for changing the image types into arrays of float32
and normalizing.
We map different types of blood cells using a dictionary.
{'EOSINOPHIL': 0, 'LYMPHOCYTE': 1, 'MONOCYTE': 2, 'NEUTROPHIL': 3}
We train our Tensorflow Keras model to find the desired figures from the dataset.
We will fit the model using a predefined number of epochs. I used five epochs for this example. You can increase the number of your epochs for increased accuracy.
Here is the entire code.
References
- https://github.com/Shenggan/BCCD_Dataset MIT License
- Khandelwal, R, Loading Custom Image Dataset for Deep Learning Models: Part 1, August 20, 2020, www.towardsdatascience.com