ML Lab 3
ML Lab 3
Lab Report # 3
Muhammad Jahangir
21-cs-089
Basit Ali
21-cs-104
Instructor: Ms. Faiza Jahangir
Task 1
Write a MATLAB code that will load “xception” model and train your
desired dataset and get the trained file.
Steps
1 First download the Dataset form Kaggle
Code
clc;
close all;
clear;
datasetpath = fullfile("C:\Users\Muhammad Jahangir\Desktop\Fruits
Classification\test\");
imds = imageDatastore(datasetpath,...
'IncludeSubfolders',true,...
'LabelSource','foldernames');
labels = countEachLabel(imds);
num_images = length(imds.Files);
num_folds =2;
perm = randperm(num_images,6);
for fold_idx=1:length(perm)
subplot(2,3,fold_idx);
imshow(imread(imds.Files{perm(fold_idx)}));
title(sprintf("%s",imds.Labels(perm(fold_idx))));
end
• It loads a dataset of fruit images and displays a random subset for visualization.
• The dataset is split into 2 folds for cross-validation.
• It customizes the Xception neural network by replacing its final classification layers with
new layers suitable for fruit classification.
• Training options are set, specifying optimization settings, data augmentation techniques,
and other parameters.
• An augmented image data store is created for training, applying data augmentation to the
training images.
• The custom Xception-based network is trained on the augmented data.
• The trained model is saved as 'fruits' for future use.
Task 2
Analyze network “Xception” and write a MATLAB code that will fine-
tuned your network.
new_fc_layer = fullyConnectedLayer(number_of_classes,'Name','Mfa',...
'WeightLearnRateFactor',10,...
'BiasLearnRateFactor',10);
m_instance = replaceLayer(m_instance,'predictions',new_fc_layer);
new_softmax_layer = softmaxLayer('name','softmax');
m_instance =
replaceLayer(m_instance,'predictions_softmax',new_softmax_layer);
newclasslayer = classificationLayer('Name','Newlayer');
m_instance =
replaceLayer(m_instance,'ClassificationLayer_predictions',newclasslaye
r);
Conclusion
This MATLAB code trains a deep learning model for fruit classification using transfer learning
with the Xception architecture. We customizes a pre-trained Xception network, and trains it
using augmented data, ultimately saving the trained model. We Fine-tuning the network on the
dataset using the specified training options.