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

조회 수: 3 (최근 30일)
Pratham Shah
Pratham Shah 2023년 3월 29일
편집: Pratham Shah 2023년 5월 1일
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

답변 (1개)

Abhijeet
Abhijeet 2023년 4월 3일
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
Pratham Shah
Pratham Shah 2023년 4월 5일
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.

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

카테고리

Help CenterFile Exchange에서 Image Processing and Computer Vision에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by