Train a deep learning model with filename in single csv file.
7 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Abhijeet
on 3 Apr 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));
See Also
Categories
Find more on Image Processing and Computer Vision in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!