The article I wrote earlier primarily focused on learning the process of creating an AI application, so I didn't emphasize much on image recognition accuracy. However, as someone claiming to be a machine learning engineer, pursuing accuracy is essential. In this article, I will discuss the efforts made to improve the accuracy, referencing a popular page from the "Discussion" section of a dataset containing MRI brain images.
The page referred to for improving accuracy can be found here:
https://www.kaggle.com/code/ruslankl/brain-tumor-detection-v1-0-cnn-vgg-16
Steps taken to improve accuracy:
1. Removing unnecessary parts of the images
The provided dataset contained images with varying sizes and irregular areas of black space around the brain, as depicted in the following image:
To maintain consistency and avoid introducing anomalies during training, unnecessary portions around the brain were removed. The process involved four steps, including converting the images to grayscale, obtaining contours, and extracting the outermost points to create a rectangle that encompasses the brain.
# Code snippet for removing unnecessary parts of the images
# (Refer to the original article for the complete code)
def crop_imgs(set_name, add_pixels_value=0):
# Implementation details...
return np.array(set_new)
After removing unnecessary portions, the images displayed a more uniform appearance:
2. Image augmentation
Due to the limited number of images in the dataset (100-200), data augmentation was performed to increase the dataset size. Augmentation techniques included rotation, shifting, flipping, and adjusting brightness.
# Code snippet for image augmentation
# (Refer to the original article for the complete code)
train_datagen = ImageDataGenerator(
rotation_range=15,
width_shift_range=0.1,
height_shift_range=0.1,
shear_range=0.1,
brightness_range=[0.5, 1.5],
horizontal_flip=True,
vertical_flip=True,
preprocessing_function=preprocess_input
)
The augmented images introduced subtle variations:
Results of accuracy improvement:
The model's accuracy improved progressively with the increase in epochs, reaching close to 90% in the end:
However, in medical image classification, the emphasis is often on avoiding false negatives, as misdiagnosing a condition could have serious consequences. The confusion matrix is used to evaluate the model's performance in such cases.
# Code snippet for creating and displaying a confusion matrix
# (Refer to the original article for the complete code)
confusion_mtx = confusion_matrix(y_val, predictions)
cm = plot_confusion_matrix(confusion_mtx, classes=list(labels.items()), normalize=False)
The confusion matrix visually represents the model's performance:
Conclusion:
While the article borrowed code from a provided source, the author expressed a desire to incorporate original ideas in future work to further enhance accuracy.
Top comments (0)