0
$\begingroup$

I am training Cifar-10 dataset of 32 x 32 sized coloured images for image classification. Here is the link/source to the dataset and its description: https://www.cs.toronto.edu/~kriz/cifar.html

The CIFAR-10 dataset consists of 60000 32x32 colour images in 10 classes, with 6000 images per class. There are 50000 training images and 10000 test images.

The dataset is divided into five training batches and one test batch, each with 10000 images. The test batch contains exactly 1000 randomly-selected images from each class. The training batches contain the remaining images in random order, but some training batches may contain more images from one class than another. Between them, the training batches contain exactly 5000 images from each class.

Here are the classes in the dataset, as well as 10 random images from each: airplane
automobile
bird
cat
deer
dog
frog
horse
ship
truck

The classes are completely mutually exclusive. There is no overlap between automobiles and trucks. "Automobile" includes sedans, SUVs, things of that sort. "Truck" includes only big trucks. Neither includes pickup trucks.

I am facing an issue that my trained model shows absurd results of only a constant accuracy of 10% I don't know what changes are necessary to resolve this issue.

This is my matlab code to train the model;

%% Data Preprocessing % Load CIFAR-10 dataset % Specify the folder where the CIFAR-10 dataset files are located datasetFolder = 'C:\ZNew Drive D\Machine Learning\Cifar 10'; % Replace with the actual folder path

% Load CIFAR-10 training data XTrain = []; YTrain = []; batchFile1 = fullfile(datasetFolder,'data_batch_1.mat'); batchFile2 = fullfile(datasetFolder,'data_batch_2.mat'); batchFile3 = fullfile(datasetFolder,'data_batch_3.mat'); batchFile4 = fullfile(datasetFolder,'data_batch_4.mat'); batchFile5 = fullfile(datasetFolder,'data_batch_5.mat');

batchFile1Data = load(batchFile1); batchFile2Data = load(batchFile2); batchFile3Data = load(batchFile3); batchFile4Data = load(batchFile4); batchFile5Data = load(batchFile5);

% Extract data arrays from batch data structures and normalize data1 = double(batchFile1Data.data)/255; data2 = double(batchFile2Data.data)/255; data3 = double(batchFile3Data.data)/255; data4 = double(batchFile4Data.data)/255; data5 = double(batchFile5Data.data)/255;

% Reshape and concatenate data into XTrain XTrain = cat(4, ... reshape(data1, [32, 32, 3, 10000]), ... reshape(data2, [32, 32, 3, 10000]), ... reshape(data3, [32, 32, 3, 10000]), ... reshape(data4, [32, 32, 3, 10000]), ... reshape(data5, [32, 32, 3, 10000]));

YTrain = [batchFile1Data.labels; batchFile2Data.labels; batchFile3Data.labels; batchFile4Data.labels; batchFile5Data.labels];

% Load CIFAR-10 test data testFile = fullfile(datasetFolder, 'test_batch.mat'); testData = load(testFile); testD = double(testData.data)/255; XTest = reshape((testD), [32, 32, 3, 10000]); YTest = testData.labels;

% Define the CNN architecture net = [ imageInputLayer([32 32 3])

convolution2dLayer(5, 128, 'Padding', 'same')
reluLayer
maxPooling2dLayer(2, 'Stride', 2)

convolution2dLayer(5, 128, 'Padding', 'same')
reluLayer
maxPooling2dLayer(2, 'Stride', 2)

convolution2dLayer(5, 256, 'Padding', 'same')
reluLayer
maxPooling2dLayer(2, 'Stride', 2)

convolution2dLayer(5, 256, 'Padding', 'same')
reluLayer
maxPooling2dLayer(2, 'Stride', 2)

convolution2dLayer(5, 128, 'Padding', 'same')
reluLayer
maxPooling2dLayer(2, 'Stride', 2)

fullyConnectedLayer(1024)
reluLayer

% Add a Dropout layer with a dropout rate (e.g., 0.5)
%dropoutLayer(0.5)

fullyConnectedLayer(10)
softmaxLayer
classificationLayer

];

% Convert training and validation labels to categorical format YTrainCategorical = categorical(YTrain); YTestCategorical = categorical(YTest);

% Specify training options options = trainingOptions('sgdm', ... 'MiniBatchSize', 128, ... 'MaxEpochs', 10, ... 'InitialLearnRate', 0.001, ... 'Shuffle', 'every-epoch', ... 'Verbose', true, ... 'Plots', 'training-progress', ... 'ValidationData', {XTestPermuted, YTestCategorical}, ... 'ValidationFrequency', 10);

% Train the network net = trainNetwork(XTrain, YTrainCategorical, net, options);

% Evaluate the trained network on the test data YTestPred = classify(net, XTestPermuted); accuracy = sum(YTestPred == YTestCategorical) / numel(YTestCategorical); disp(['Test accuracy: ', num2str(accuracy)]);

$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.