Train a deep learning model with filename in single csv file.

8 visualizaciones (últimos 30 días)
Pratham Shah
Pratham Shah el 29 de Mzo. de 2023
Editada: Pratham Shah el 1 de Mayo de 2023
I want to train U-Net model for an application. Images are having multiple bands saved in different .tif file. To train DL model in MATLAB we require an imagedatastore. But I have filenames for all the images saved in single .csv file, so I'm not able to make a custom 'matReader' function for it.
I have done this when one .csv file contains filenames of different band and mask for a 'single image'. But in this approach I had to make multiple csv files. I want to do the process from a single csv file.
Structure of .csv file is something like:
Image1_B1, Image1_B2...., Mask1
Image2_B1, Image2_B2..., Mask2
.
.
ImageN_B1, ImageN_B2..., MaskN

Respuestas (1)

Abhijeet
Abhijeet el 3 de Abr. de 2023
Hi,
You can create a custom matReader function to read the image data from the filenames stored in the csv file, by the following approach:
% Read the csv file into the fileList variable
fileList = readtable('image_file_list.csv');
% The customMatReader function to read the files from the filename variable
function img = customMatReader(filename, imageSize)
img = imread(filename);
img = imresize(img, imageSize);
end
% The size of the images, you should modify it as per your images
imageSize = [256, 256];
% Split the columns in the CSV into separate variables
fileList = splitvars(fileList);
% Create an imageDatastore from the filenames in the CSV file.
% The 'ReadFcn' option specifies a custom function to read the image data from each filename.
% The resulting 'imds' object can be used for training the U-Net model.
imds = imageDatastore(fileList{:,1:end-1}, 'ReadFcn', @(filename) customMatReader(filename, imageSize));
  1 comentario
Pratham Shah
Pratham Shah el 5 de Abr. de 2023
Hi,
Thank you for your response!
I would like to clarify that one row consists of different channels of a single image. So, I need to pass one entire row of csv file in an instance. Also, as I'm reading csv using,
fileList = readtable('image_file_list.csv','Delimiter',',');
This line isn't making any difference
fileList = splitvars(fileList);
I have custom read function which will make a single image by stacking all the channels. Please tell me how can I pass single row to imageDatastore at a time.

Iniciar sesión para comentar.

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by