An open API service indexing awesome lists of open source software.

https://github.com/r-mahesh45/unlocking-image-insights-cnn-based-classification-of-cifar-dataset

Delving into Image Recognition with CNNs! Project Focus: Building a robust Convolutional Neural Network (CNN) to classify images from the iconic CIFAR dataset into their respective categories. Key Highlights: Preprocessing Magic: Transforming raw images into learning-ready data.
https://github.com/r-mahesh45/unlocking-image-insights-cnn-based-classification-of-cifar-dataset

cnn image-recognition keras tensorflow2

Last synced: 6 months ago
JSON representation

Delving into Image Recognition with CNNs! Project Focus: Building a robust Convolutional Neural Network (CNN) to classify images from the iconic CIFAR dataset into their respective categories. Key Highlights: Preprocessing Magic: Transforming raw images into learning-ready data.

Awesome Lists containing this project

README

          

# Image Recognition with CNNs (CIFAR-10 Dataset)

## Project Overview

This project focuses on building a Convolutional Neural Network (CNN) to classify images from the CIFAR-10 dataset using TensorFlow and Keras.

## Dependencies

Ensure you have the following libraries installed:

```bash
pip install torch tensorflow numpy
```

## Code Snippets

### 1. **Checking PyTorch Version and CUDA Availability**

```python
import torch
print(torch.__version__)
print("CUDA Available: ", torch.cuda.is_available())
```

**Explanation:**
- **`import torch`**: Imports the PyTorch library for deep learning.
- **`torch.__version__`**: Prints the version of PyTorch installed.
- **`torch.cuda.is_available()`**: Checks if a CUDA-enabled GPU is available for faster computations.

**Usage:**
This ensures the PyTorch environment is set up and checks for GPU availability, which is crucial for training large models efficiently.

---

### 2. **Checking TensorFlow Version**

```python
import tensorflow as tf
print(tf.__version__)
```

**Explanation:**
- **`import tensorflow as tf`**: Imports TensorFlow, another popular deep learning library.
- **`tf.__version__`**: Prints the TensorFlow version installed.

**Usage:**
Confirms the TensorFlow environment is configured correctly.

---

### 3. **TensorFlow Import**

```python
import tensorflow as tf
```

**Explanation:**
- Re-imports TensorFlow, though redundant if done earlier.

**Usage:**
Serves as a setup step to ensure TensorFlow is available for subsequent operations.

---

### 4. **Loading CIFAR-10 Dataset**

```python
from tensorflow.keras.datasets import cifar10
(train_images, train_labels), (test_images, test_labels) = cifar10.load_data()
```

**Explanation:**
- **`from tensorflow.keras.datasets import cifar10`**: Imports CIFAR-10 from Keras' built-in datasets.
- **`cifar10.load_data()`**: Downloads and loads the CIFAR-10 dataset. It returns:
- `train_images`, `train_labels`: Training data and labels.
- `test_images`, `test_labels`: Testing data and labels.

**Usage:**
Loads the CIFAR-10 dataset for use in the CNN model. The dataset contains images and their corresponding labels for training and evaluation.

---

### 5. **Data Preprocessing and Augmentation**

```python
from tensorflow.keras.utils import to_categorical
from tensorflow.keras.preprocessing.image import ImageDataGenerator

# Normalize images
train_images = train_images.astype('float32') / 255.0
test_images = test_images.astype('float32') / 255.0

# One-hot encode labels
train_labels = to_categorical(train_labels, 10)
test_labels = to_categorical(test_labels, 10)

# Data augmentation for training data
datagen = ImageDataGenerator(
rotation_range=20, # Random rotations
width_shift_range=0.2, # Random horizontal shifts
height_shift_range=0.2, # Random vertical shifts
shear_range=0.2, # Random shearing
zoom_range=0.2, # Random zoom
horizontal_flip=True, # Random horizontal flips
fill_mode='nearest' # Fill missing pixels
)

# Fit the generator to the training data
datagen.fit(train_images)

# Create generators for training and validation
train_generator = datagen.flow(train_images, train_labels, batch_size=32)
```

**Explanation:**
- **`to_categorical`**: Converts class labels (0-9) into one-hot encoded vectors.
- **Normalization**: Divides pixel values by 255 to scale them to a [0, 1] range, aiding in faster and more stable training.
- **`ImageDataGenerator`**: Performs real-time data augmentation to artificially expand the dataset, improving model generalization.
- `rotation_range`: Random rotations.
- `width_shift_range` and `height_shift_range`: Random shifts along axes.
- `shear_range`, `zoom_range`: Random transformations and zooms.
- `horizontal_flip`: Random horizontal flips.
- `fill_mode`: Fills in missing pixels post-transformation.
- **`datagen.flow`**: Generates batches of augmented images and labels for training.

**Usage:**
Prepares the training data by normalizing, one-hot encoding, and augmenting it. This step ensures the CNN is trained on diverse and well-prepared data.

---

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.