Borrar filtros
Borrar filtros

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

3 visualizaciones (últimos 30 días)
Badavath Purnesh Singh
Badavath Purnesh Singh el 24 de Abr. de 2024
Respondida: Lokesh el 25 de Abr. de 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].

Respuestas (1)

Lokesh
Lokesh el 25 de Abr. de 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:

Categorías

Más información sobre Image Processing Toolbox en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by