Assignment Overview
In this assignment, you will build and train two deep learning models: a Convolutional Neural Network (CNN) for image classification and a Recurrent Neural Network (RNN) for text sentiment analysis. This comprehensive project requires you to apply ALL concepts from Module 3: neural network fundamentals, CNN architecture, RNN architecture, training techniques, and model evaluation.
pip install tensorflow. No other deep learning frameworks allowed.
CNN for Images (3.2)
Convolutional layers, pooling, feature extraction, image classification
RNN for Text (3.3)
Recurrent layers, sequence processing, sentiment analysis, text classification
Training & Evaluation
Optimization, regularization, metrics, model analysis, performance comparison
The Scenario
TechVision AI Solutions
You have been hired as a Machine Learning Engineer at TechVision AI Solutions, a company that provides AI-powered solutions for businesses. The company has received two projects:
"We need an image classification system to automatically categorize product photos for our e-commerce client, and a sentiment analysis tool to analyze customer reviews for our marketing team. Can you build these using deep learning?"
Your Task
Create a Jupyter Notebook called deep_learning_models.ipynb that implements both CNN and RNN models.
Your code must load datasets, build architectures, train models, evaluate performance, and generate comprehensive reports.
The Datasets
You will work with TWO datasets. Use TensorFlow/Keras built-in datasets for consistency:
Dataset 1: Fashion MNIST (Image Classification)
from tensorflow.keras.datasets import fashion_mnist
(X_train, y_train), (X_test, y_test) = fashion_mnist.load_data()
# Classes: T-shirt/top, Trouser, Pullover, Dress, Coat, Sandal, Shirt, Sneaker, Bag, Ankle boot
# Images: 28x28 grayscale, 60,000 training, 10,000 test samples
Dataset 2: IMDB Movie Reviews (Sentiment Analysis)
from tensorflow.keras.datasets import imdb
(X_train, y_train), (X_test, y_test) = imdb.load_data(num_words=10000)
# Reviews: Pre-tokenized sequences of word indices
# Labels: 0 (negative), 1 (positive)
# Vocabulary: Top 10,000 words, 25,000 training, 25,000 test samples
Data Preprocessing Requirements
- Fashion MNIST: Normalize pixel values to [0,1], reshape for CNN input, one-hot encode labels
- IMDB: Pad sequences to fixed length, convert to numpy arrays
- Use
train_test_splitfrom sklearn to create validation sets (20% of training data)
Requirements
Your deep_learning_models.ipynb must implement ALL of the following functions.
Each function is mandatory and will be tested individually.
Load and Preprocess Fashion MNIST
Create a function load_fashion_mnist() that:
- Loads Fashion MNIST using TensorFlow datasets
- Normalizes pixel values to [0,1] range
- Reshapes images for CNN input (add channel dimension)
- One-hot encodes labels using
to_categorical - Splits training data into train/validation (80/20)
- Returns:
(X_train, X_val, X_test, y_train, y_val, y_test)
Load and Preprocess IMDB Reviews
Create a function load_imdb_reviews() that:
- Loads IMDB dataset with top 10,000 words
- Pads sequences to maximum length of 500
- Converts to numpy arrays
- Splits training data into train/validation (80/20)
- Returns:
(X_train, X_val, X_test, y_train, y_val, y_test)
Build CNN Model
Create a function build_cnn_model() that:
- Creates a Sequential CNN model
- Includes at least 2 Conv2D layers with ReLU activation
- Includes MaxPooling2D layers
- Includes Dropout layers for regularization
- Ends with Dense layers for classification
- Uses appropriate input shape for Fashion MNIST
- Compiles with Adam optimizer and categorical crossentropy
Build RNN Model
Create a function build_rnn_model() that:
- Creates a Sequential RNN model
- Includes an Embedding layer (vocab_size=10000, embedding_dim=128)
- Includes LSTM or GRU layers
- Includes Dropout for regularization
- Ends with Dense layer with sigmoid for binary classification
- Uses appropriate input shape for padded sequences
- Compiles with Adam optimizer and binary crossentropy
Train CNN Model
Create a function train_cnn_model(model, X_train, y_train, X_val, y_val) that:
- Trains the model for at least 10 epochs
- Uses batch size of 32
- Includes validation data
- Uses EarlyStopping callback to prevent overfitting
- Uses ModelCheckpoint to save best model
- Plots training history (accuracy and loss)
- Returns training history
Train RNN Model
Create a function train_rnn_model(model, X_train, y_train, X_val, y_val) that:
- Similar requirements as CNN training
- Appropriate for text classification task
Evaluate Models
Create functions evaluate_cnn_model(model, X_test, y_test) and evaluate_rnn_model(model, X_test, y_test) that:
- Generate predictions on test set
- Calculate accuracy, precision, recall, F1-score
- Display classification report
- Plot confusion matrix
- Return evaluation metrics as dictionary
Generate Performance Report
Create a function generate_performance_report(cnn_metrics, rnn_metrics, filename) that:
- Writes a text report comparing both models
- Includes training time, final accuracy, best epoch
- Analyzes overfitting/underfitting
- Provides recommendations for improvement
Main Program
Create a main() function that:
- Loads and preprocesses both datasets
- Builds both models
- Trains both models
- Evaluates both models
- Generates performance report
- Saves trained models
- Uses the
if __name__ == "__main__":pattern
Submission
Create a public GitHub repository with the exact name shown below:
Required Repository Name
techvision-deep-learning
Required Files
techvision-deep-learning/
├── deep_learning_models.ipynb # Your Jupyter Notebook with ALL functions
├── cnn_model.h5 # Saved CNN model weights
├── rnn_model.h5 # Saved RNN model weights
├── performance_report.txt # Generated performance report
├── training_history_cnn.png # CNN training history plot
├── training_history_rnn.png # RNN training history plot
├── confusion_matrix_cnn.png # CNN confusion matrix
├── confusion_matrix_rnn.png # RNN confusion matrix
└── README.md # REQUIRED - see contents below
README.md Must Include:
- Your full name and submission date
- Brief description of your model architectures
- Training results and performance metrics
- Any challenges faced and how you solved them
- Instructions to run your notebook
Do Include
- All functions implemented and working
- Proper model architectures with regularization
- Training plots and evaluation metrics
- Saved model files and performance report
- README.md with all required sections
Do Not Include
- PyTorch or other frameworks (ONLY TensorFlow/Keras)
- Custom datasets (use provided TensorFlow datasets)
- Models without proper evaluation
- Notebooks that don't run without errors
- Hardcoded results (we will retrain your models)
Enter your GitHub username - we'll verify your repository automatically
Grading Rubric
Your assignment will be graded on the following criteria:
| Criteria | Points | Description |
|---|---|---|
| Data Preprocessing | 40 | Correct loading, normalization, reshaping, and splitting of both datasets |
| CNN Architecture | 50 | Proper CNN model with convolutional, pooling, and dense layers |
| RNN Architecture | 50 | Proper RNN model with embedding, recurrent, and dense layers |
| Training Implementation | 40 | Correct training loops with callbacks, validation, and history tracking |
| Model Evaluation | 40 | Comprehensive evaluation with metrics, plots, and analysis |
| Code Quality | 30 | Docstrings, comments, organization, and error handling |
| Total | 250 |
Ready to Submit?
Make sure you have completed all requirements and reviewed the grading rubric above.
Submit Your AssignmentWhat You Will Practice
CNN Architecture (3.2)
Building convolutional neural networks with proper layers, activations, and regularization techniques
RNN Implementation (3.3)
Implementing recurrent neural networks for sequence processing and text classification tasks
Model Training & Optimization
Training deep learning models with proper optimization, callbacks, and performance monitoring
Model Evaluation & Analysis
Evaluating model performance with comprehensive metrics, visualization, and comparative analysis
Pro Tips
TensorFlow Best Practices
- Use
SequentialAPI for simple models - Always normalize input data
- Use appropriate activation functions
- Monitor training with callbacks
Deep Learning Tips
- Start with simple architectures
- Use dropout to prevent overfitting
- Monitor validation metrics closely
- Experiment with different optimizers
Training Optimization
- Use GPU if available for faster training
- Start with small batch sizes
- Use early stopping to save time
- Save model checkpoints regularly
Common Mistakes
- Forgetting to compile the model
- Not preprocessing data properly
- Using wrong loss functions
- Overfitting to training data