필터 지우기
필터 지우기

Hi all, how to create image datasets. I need them to train neural networks. I have about 15 to 20 images and I need to turn these images into an image dataset. Please.

조회 수: 21 (최근 30일)
I have tried to find the way to build image dataset but all of the example are using Python. But i want to use Matlab. Please help me.

채택된 답변

Abhijit Bhattacharjee
Abhijit Bhattacharjee 2022년 5월 19일
This is easy to do in MATLAB! You can put all your images into a folder and use the imageDatastore command.
Assuming the folder of images is on the path, here is an example:
imds = imageDatastore("name_of_image_folder");
  댓글 수: 2
Nurul Farhana Mohd Fadzli
Nurul Farhana Mohd Fadzli 2022년 5월 19일
After that what i need to do ? can you show me the example of your matlab interface?
Abhijit Bhattacharjee
Abhijit Bhattacharjee 2022년 5월 19일
What you do next depends on your application. In your original question, you asked what you need to make a dataset. The code I provided should be sufficient for that.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

yanqi liu
yanqi liu 2022년 5월 20일
yes,sir,may be use cnn transfer to train model,such as
unzip('MerchData.zip');
% use image folder to get dataset
imds = imageDatastore('MerchData','IncludeSubfolders',true,'LabelSource','foldernames');
[imdsTrain,imdsValidation] = splitEachLabel(imds,0.7,'randomized');
% use Alexnet to get cnn model
alex_net = alexnet;
class_number = length(unique(imds.Labels));
alex_net_share = alex_net.Layers(1:end-3);
alex_net_add = [
fullyConnectedLayer(class_number,'Name','fc8','WeightLearnRateFactor',10, 'BiasLearnRateFactor',20)
softmaxLayer('Name','softmax')
classificationLayer('Name','classification')
];
layers_1 = [alex_net_share
alex_net_add];
% train
augimdsTrain = augmentedImageDatastore([227 227],imdsTrain);
augimdsValidation = augmentedImageDatastore([227 227],imdsValidation);
miniBatchSize = 10;
valFrequency = floor(numel(augimdsTrain.Files)/miniBatchSize);
options = trainingOptions('sgdm', ...
'MiniBatchSize',miniBatchSize, ...
'MaxEpochs',5, ...
'InitialLearnRate',3e-4, ...
'Shuffle','every-epoch', ...
'ValidationData',augimdsValidation, ...
'ValidationFrequency',valFrequency, ...
'Verbose',false);
trainedNet = trainNetwork(augimdsTrain,layers_1,options);
% test
[YPred,probs] = classify(trainedNet,augimdsValidation);
accuracy = mean(YPred == imdsValidation.Labels)
accuracy = 1
% app
idx = randperm(numel(imdsValidation.Files),4);
figure
for i = 1:4
subplot(2,2,i)
I = readimage(imdsValidation,idx(i));
imshow(I)
label = YPred(idx(i));
title(string(label) + ", " + num2str(100*max(probs(idx(i),:)),3) + "%");
end
  댓글 수: 2
Nurul Farhana Mohd Fadzli
Nurul Farhana Mohd Fadzli 2022년 5월 20일
So, if i want to use my dataset, then what part do i need to change? Is it the MerchData? I am sorry im still new to Matlab.
yanqi liu
yanqi liu 2022년 5월 20일
yes,sir,let us check the folder MerchData,we can find that one subfolder is one class,so if use our data,we can just make a new subfolder, and use name as subfolder name
then put images in it,and run code

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by