...

How to classify monkeys images using convolutional neural network , Keras tuner hyper parameters , and transfer learning ? (part1)

Basics of CNN in Deep Learning

🎥 Image Classification Tutorial Series: Five Parts 🐵 – Python Image Dataset Visualization

Welcome to our comprehensive image classification tutorial series! In this tutorial playlist, consisting of five informative videos, we will guide you through the entire process of classifying monkey species in images.

Each video focuses on a specific aspect of the process, providing you with a well-rounded understanding of the subject matter. Join us as we cover data preparation, classic CNN classification, hyperparameter tuning with Keras Tuner, fine-tuning a pretrained model (VGG16), and exploring the outcome of deep neural network layers. Get ready to dive into the world of monkey species classification and enhance your knowledge with practical examples and expert tips.

Video 1: Data Preparation Tutorial:

In the first video of our series, we will walk you through the essential steps of data preparation for monkey species classification. Discover how to download the necessary image data and explore its characteristics. Learn how to preprocess and format the data to ensure it is ready for the subsequent phases of the classification process. By the end of this tutorial, you will have a well-prepared dataset, laying the foundation for accurate and efficient classification.

Link for more info : https://eranfeit.net/how-to-classify-monkeys-images-using-convolutional-neural-network-keras-tuner-hyper-parameters-and-transfer-learning-part1/


Video 2: CNN Classification Tutorial:

Our second video focuses on the fundamental method of classifying monkey species using a Convolutional Neural Network (CNN). Join us as we guide you through the process of writing a CNN model, training it using the prepared dataset, and evaluating its performance. Gain insights into the inner workings of CNNs and witness their effectiveness in accurately classifying monkey species based on image data.

Link for more info : https://eranfeit.net/how-to-classify-monkeys-images-using-convolutional-neural-network-keras-tuner-hyper-parameters-and-transfer-learning-part2/


Video 3: Enhancing Classification with Keras Tuner:

In the third video, we take the CNN classification tutorial to the next level by incorporating Keras Tuner. Discover how to optimize the performance of your CNN model by automatically searching for the best hyperparameters. Learn how to leverage the power of Keras Tuner to fine-tune your model and achieve even more accurate results in classifying monkey species.

Link for more info : https://eranfeit.net/how-to-classify-monkeys-images-using-convolutional-neural-network-keras-tuner-hyper-parameters-and-transfer-learning-part3/

Video 4: Fine-tuning with Pretrained VGG16:

In the fourth video, we explore an alternative approach to image classification by utilizing a pretrained model, specifically VGG16. Join us as we guide you through the process of fine-tuning the VGG16 model for the task of monkey species classification. Learn how to adapt a powerful pretrained model to accurately classify monkey species and leverage its advanced features for improved results

Link for more info : https://eranfeit.net/how-to-classify-monkeys-images-using-convolutional-neural-network-keras-tuner-hyper-parameters-and-transfer-learning-part4/

Video 5: Visualizing Deep Neural Network Layers:

In our fifth and final video, we delve into the fascinating world of model interpretability by exploring the outcome of deep neural network layers. Witness what a trained network “sees” as we dissect the layers and visualize their outputs for a specific class. Gain a deeper understanding of how the network processes and interprets images, providing valuable insights into the classification process.

Link for more info : https://eranfeit.net/what-actually-sees-a-cnn-deep-neural-network-model/


Data Preparation Tutorial:

Link for the tutorial is here : https://youtu.be/ycEzhwiAXjY&list=UULFTiWJJhaH6BviSWKLJUM9sg

You can find the full code here : https://ko-fi.com/s/8fbd4679f6

You can more tutorials here : https://eranfeit.net/blog/


part 1 – Python Image Dataset Visualization: Explore the 10-Monkey Species

Introduction

This tutorial shows how to load, inspect, and visualize an image dataset in Python.
You will verify the folder structure, parse the label file into a clean table, and map technical labels to human-friendly names.
Finally, you will render an at-a-glance gallery of random images per class using Matplotlib to speed up dataset quality checks.

In this tutorial we will download the dataset , make some data discovery , and prepare the images for the next phase of building the CNN model.

Data Setup and Folder Verification

We import core libraries, define training and validation paths, and verify that the dataset folders contain the expected number of class directories and images.
A small helper prints a concise summary of folders and .jpg files so you can catch path mistakes early.

### Import glob to search for files and folders using wildcard patterns. import glob ### Import os for path joins and directory listings. import os   ### Print a clear start banner so the notebook or console shows progress. print ("Start prepare the data :") ### Print a visual separator for readability in logs. print ("========================")  ### Define the absolute path to the training images folder. trainMyImagesFolder = "C:/Python-cannot-upload-to-GitHub/10-Monkey-Species/training/training" ### Define the absolute path to the validation images folder. testMyImagesFolder = "C:/Python-cannot-upload-to-GitHub/10-Monkey-Species/validation/validation"  ### Create a small utility to count subfolders (classes) and .jpg files in a directory tree. def checkMyDir(dir):     ### Count immediate subfolders under the given directory (each should represent a class).     folders = len(glob.glob(dir + '/*'))     ### Count all .jpg files one level deeper to estimate image quantity.     image_files = len(glob.glob(dir + '/*/*.jpg'))     ### Print a concise summary with folder and file counts for quick verification.     print ("--->>> The Data folder : {} contains {} folders and {} images.".format(dir,folders,image_files))  ### Print training directory stats (the function prints its own message and returns None). print(checkMyDir(trainMyImagesFolder)) ### Print validation directory stats (the function prints its own message and returns None). print(checkMyDir(testMyImagesFolder)) 

You can find the full code here : https://ko-fi.com/s/8fbd4679f6

This section ensures your paths are correct and that the dataset layout matches expectations before you proceed.
Catching path and structure issues here saves time later when reading labels or plotting images.


Label File Parsing and Friendly Names

We load the label file into a Pandas DataFrame, strip unwanted whitespace and tab characters, and set the class label as the index.
Then we extract a convenient dictionary that maps label codes to common names for human-readable titles in plots.

### Define the expected columns in the label file so Pandas assigns names on read. columns = ["Label","Latin Name","Common Name","Train Images","Validation Images"]  ### Import Pandas for data manipulation and cleaning. import pandas as pd  ### Read the label text file with headers supplied and skip the original header row. df = pd.read_csv("C:/Python-cannot-upload-to-GitHub/10-Monkey-Species/monkey_labels.txt",names=columns,skiprows=1)  ### Trim whitespace from the Label column to avoid mismatches like 'n0 ' vs 'n0'. df['Label'] = df['Label'].str.strip() ### Remove stray tab characters from the Latin Name column. df['Latin Name'] = df['Latin Name'].replace("\t","") ### Trim whitespace from the Latin Name column to standardize text. df['Latin Name'] = df['Latin Name'].str.strip() ### Trim whitespace from the Common Name column for clean display later. df['Common Name'] = df['Common Name'].str.strip()  ### Use the Label column as the DataFrame index for easy lookups by label code. df= df.set_index("Label")  ### Print the cleaned DataFrame to verify that all fields look correct. print(df)  ### Extract a Series mapping label code to Common Name for quick title rendering. monkeyDic = df["Common Name"] ### Print the mapping to confirm the availability of friendly names per label. print(monkeyDic)  ### Demonstrate a direct lookup: print the common name for label 'n0'. print(monkeyDic['n0']) 

You can find the full code here : https://ko-fi.com/s/8fbd4679f6

You now have a clean mapping from technical labels to human-friendly names.
This makes visualizations readable and helps you validate class identities at a glance.


Random Image Gallery by Class

We loop through each class directory, sample six random images, and render them in a grid.
Each row corresponds to a class, and each subplot shows one random image labeled with a shortened friendly name.
This is extremely useful for quick dataset QA and visual inspection.

### Import Matplotlib's pyplot interface for plotting images. import matplotlib.pyplot as plt  ### Import random to sample different images each run for better coverage. import random  ### Define a utility to render a class-wise gallery from the given directory. def displayDirectory(dir):     ### Get all class folders under the directory and sort for consistent row order.     folderList = os.listdir(dir)     ### Sort the folder list to stabilize row order in the plot.     folderList.sort()      ### Count how many classes will be displayed.     numOfClasses = len(folderList)     ### Fix the number of images per class column-wise for a balanced grid.     columnForDisplay = 6      ### Create a figure with rows per class and six columns per row.     fig , ax = plt.subplots(numOfClasses, columnForDisplay, figsize=(3*columnForDisplay , 3*numOfClasses)) # space for the images      ### Iterate over classes with a row index so each class occupies one row.     for countRow , folderClassItem in enumerate(folderList):         ### Build the path to the current class folder.         path = os.path.join(dir,folderClassItem)         ### List all filenames inside the class folder.         subDirList = os.listdir(path)         ### For each column in the row, pick a random image to visualize.         for i in range(columnForDisplay): # 0 to 5             ### Choose a random filename from the class files.             randomImageFile = random.choice(subDirList)             ### Build the full path to the randomly selected image.             imageFilePath = os.path.join(path,randomImageFile)             ### Read the image as an array for display in Matplotlib.             img = plt.imread(imageFilePath)             ### Map the label folder name to a human-friendly common name.             monkeyLabel = monkeyDic[folderClassItem]             ### Shorten the label to the first 10 characters to keep titles compact.             monkeyLabel = monkeyLabel[:10] # get only first 10 characters             ### Set the subplot title to the (shortened) common name for quick recognition.             ax[countRow,i].set_title(monkeyLabel)             ### Show the image in the subplot.             ax[countRow,i].imshow(img)             ### Hide axes for a cleaner gallery look.             ax[countRow,i].axis('off')      ### Render the full gallery figure.     plt.show()  ### Call the utility on the training dataset to preview random samples by class. displayDirectory(trainMyImagesFolder) 

You can find the full code here : https://ko-fi.com/s/8fbd4679f6

You now have a simple yet powerful visual QA tool to scan class balance and image variety in seconds.
Rerunning will sample different images to broaden your mental model of the dataset.


Connect :

☕ Buy me a coffee — https://ko-fi.com/eranfeit

🖥️ Email : feitgemel@gmail.com

🌐 https://eranfeit.net

🤝 Fiverr : https://www.fiverr.com/s/mB3Pbb

Enjoy,

Eran

error: Content is protected !!
Eran Feit