Effacer les filtres
Effacer les filtres

How to use a transformed data store to train the network ?

3 vues (au cours des 30 derniers jours)
Badavath Purnesh Singh
Badavath Purnesh Singh le 24 Avr 2024
Réponse apportée : Lokesh le 25 Avr 2024
Whenever I use transformation for an Image data store (DS) for resizing the images, the resulting transformed DS consists of only images without its labels.
resizedImds = transform(Image DS, @(x) imresize(x, [227 227]));
I need a transformed data store with the labels stored in image data store [Labels= imagesdatastore.Labels].

Réponses (1)

Lokesh
Lokesh le 25 Avr 2024
Hi Badavath,
It is my understanding that you are encountering an issue when transforming an Image Datastore, as the resulting transformed Image Datastore only contains the resized images, without retaining the original labels associated with each image.
As a workaround, you can explicitly add the labels to the output data of your transform function, using a cell array to combine it with the image data. To do this, you will also need to specify that the TransformedDatastore should pass in a second argument that contains the info for each read image.
Here is a sample code snippet:
imds = imageDatastore(fullfile(matlabroot,"toolbox","matlab"),...
"IncludeSubfolders",true,"FileExtensions",".tif","LabelSource","foldernames")
imdsReSz = transform(imds,@resizeAndLabel,"IncludeInfo",true);
imgReSz1 = read(imdsReSz)
imgReSz1 =
1×2 cell array
{227×227×3 uint8} {[demos]} % contains image and label
function [resizedImageWithLabel, info] = resizeAndLabel(image, info)
% Resize the image to the desired size
targetSize = [227, 227];
resizedImage = imresize(image, targetSize);
% Combine the resized image and its label into a cell array
% This maintains the association between the image and its label
resizedImageWithLabel = {resizedImage, info.Label};
end
Please refer to the following MATLAB Answer that is related to a similar issue:

Catégories

En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by