Skip to content

This Python script implements a Convolutional Neural Network (CNN) using TensorFlow and Keras for classifying images into different categories. The model is designed to process images of various densities, specifically for distinguishing between benign and malignant cases in a medical imaging context.

Notifications You must be signed in to change notification settings

ayax537/Convolutional-Neural-Network-CNN-for-Image-Classification

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Convolutional-Neural-Network-CNN-for-Image-Classification

Description

This Python script implements a Convolutional Neural Network (CNN) using TensorFlow and Keras for classifying images into different categories. The model is designed to process images of various densities, specifically for distinguishing between benign and malignant cases in a medical imaging context.

Key Features

  1. Data Preparation Image Loading: The script utilizes TensorFlow's image_dataset_from_directory function to load training and testing datasets from specified directories. Images are resized to 224x224 pixels, and batches of 32 are created for efficient processing. Class Names: The classes are defined as different density categories, including both benign and malignant labels.
  2. CNN Architecture Convolutional Layers: The model begins with convolutional layers that extract features from the input images. The architecture includes multiple convolutional layers with ReLU activation functions for non-linear transformations. Pooling Layers: Max pooling layers are added to reduce the spatial dimensions of the feature maps, which helps in retaining essential features while decreasing the computational load. Flattening: After feature extraction, the model flattens the 2D feature maps into a 1D array to prepare for the fully connected layers. Fully Connected Layers: Dense layers are used to learn complex representations, with dropout layers to prevent overfitting. Output Layer: The final layer uses a softmax activation function to classify the images into one of the eight defined categories.
  3. Model Compilation and Training The CNN is compiled with the Adam optimizer and sparse categorical crossentropy loss function, suitable for multi-class classification. The model is trained on the training dataset for 15 epochs, with validation on the test dataset to monitor performance.
  4. Model Evaluation After training, the model is evaluated on the test dataset to assess its accuracy and performance metrics.
  5. Prediction and Visualization The script includes functionality to predict classifications on new images stored in a specified directory. Results are visualized using Matplotlib, displaying the predicted class alongside the actual label for comparison.

Conclusion

This script serves as a robust implementation of a CNN for image classification tasks, particularly in the medical imaging field. It showcases the use of deep learning techniques for feature extraction and classification, providing a framework that can be adapted for various image datasets and classification challenges. The model's architecture can be further fine-tuned to improve accuracy based on specific requirements or additional data.

About

This Python script implements a Convolutional Neural Network (CNN) using TensorFlow and Keras for classifying images into different categories. The model is designed to process images of various densities, specifically for distinguishing between benign and malignant cases in a medical imaging context.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages