Skip to content

added keras tuner and updated readme #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions Model Tuning/Keras Tuner/assignment.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 📝 Assignment: Hyperparameter Tuning with Keras Tuner\n",
"\n",
"### Objective:\n",
"Learn how to use *Keras Tuner* to optimize the hyperparameters of a simple Convolutional Neural Network (CNN) on the MNIST dataset.\n",
"\n",
"---\n",
"\n",
"### 🚀 Tasks:\n",
"\n",
"1. *Install Keras Tuner* \n",
" - Ensure you have keras-tuner installed using: \n",
" \n",
" !pip install keras-tuner\n",
" \n",
" \n",
"2. *Load and Normalize MNIST Dataset* \n",
" - Load the MNIST dataset using keras.datasets.mnist.load_data(). \n",
" - Normalize pixel values between 0 and 1. \n",
" - Expand dimensions to match CNN input format.\n",
"\n",
"3. *Define a CNN Model for Hyperparameter Tuning* \n",
" - Use keras.Sequential() to define a CNN. \n",
" - Add two Conv2D layers with tunable filter sizes (hp.Choice()).\n",
" - Add a Dropout layer with a tunable dropout rate.\n",
" - Compile the model with a tunable learning rate.\n",
"\n",
"4. *Use Keras Tuner to Find the Best Hyperparameters* \n",
" - Use kt.RandomSearch to optimize hyperparameters. \n",
" - Run the search for 3 trials to save time. \n",
" - Set epochs=2 during tuning.\n",
"\n",
"5. *Train the Best Model* \n",
" - Retrieve the best hyperparameters using tuner.get_best_hyperparameters(num_trials=1). \n",
" - Train the best model on the dataset for 3 epochs. \n",
"\n",
"6. *Compare Results Before and After Tuning* \n",
" - Print the *accuracy* before and after tuning. \n",
" - Plot the loss curves using matplotlib.\n",
"\n",
"---\n",
"\n",
"### 📌 Bonus Challenge:\n",
"- Try using *Hyperband Tuner* instead of RandomSearch and compare results.\n",
"- Adjust max_trials and executions_per_trial to see how it impacts training time.\n",
"\n",
"---\n",
"\n",
"💡 *Hint:* Refer to the main notebook for code structure. Modify parameters and observe the impact on model accuracy! 🎯"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading