Datastore problems with deep learning. "FileExtensions Name-Value"

7 ビュー (過去 30 日間)
Filip Szczepanski
Filip Szczepanski 2023 年 3 月 9 日
回答済み: Steven Lord 2023 年 3 月 9 日
I keep getting an error about file formats (error message at the bottom).
I am writing a neural net that predicts risk for an area.
I have 6 greyscale maps layered on top of eachother.
I split them into 11x11 px images and stack them on top of eachother and name the files based on the middle pixel risk
I save the slices as .mat files.
After that I have [11 11 6] .mat files inside folders that act as labels.
I want to train on this data
Could someone suggest a way to fix this or a better file format that would work for this project?
files = ["C:\Users\filsz\Documents\MATLAB\test6\Data\very_low\*.mat",
... "C:\Users\filsz\Documents\MATLAB\test6\Data\low\*.mat", ...
"C:\Users\filsz\Documents\MATLAB\test6\Data\medium\*.mat", ...
"C:\Users\filsz\Documents\MATLAB\test6\Data\high\*.mat", ...
"C:\Users\filsz\Documents\MATLAB\test6\Data\very_high\*.mat"];
% load files into the ds
ds = fileDatastore(files,"ReadFcn",@load,"FileExtensions", ".mat");
ds = shuffle(ds);
%split into 2 partitions and get labels
dspTrain = partition(ds,2,1);
dspTest = partition(ds,2,2);
labelsTrain = folders2labels(dspTrain);
labelsTest = folders2labels(dspTest);
%create a table with [files, label] columns
filesTrain = dspTrain.Files;
filesTest = dspTest.Files;
Ttrain = table(filesTrain,labelsTrain);
Ttest = table(filesTrain,labelsTrain);
%convolutional NN layers and options
%this is just a first test so layers and options dont matter too much
layers = [ imageInputLayer([11 11 6])
convolution2dLayer([3 3],64,Stride=1)
reluLayer
maxPooling2dLayer([2 2],Stride=1)
convolution2dLayer([3 3],128,Stride=1)
reluLayer
maxPooling2dLayer([2 2],Stride=1)
convolution2dLayer([3 3],256,Stride=1)
reluLayer
maxPooling2dLayer([2 2],Stride=1)
flattenLayer
fullyConnectedLayer(200)
reluLayer
fullyConnectedLayer(100)
reluLayer
fullyConnectedLayer(5)
softmaxLayer
classificationLayer];
miniBatchSize = 2^18;
options = trainingOptions('adam', ...
'MiniBatchSize',miniBatchSize, ...
'Shuffle','every-epoch', ...
'Plots','training-progress', ...
'Verbose',false, MaxEpochs=1);
%training
net = trainNetwork(Ttrain,layers,options);
%(net = ... is my line 84 from the error message)
Thats the error I keep getting. (changing the filedatastore into imgdatastore with .mat extensions produces the same error)
Error using trainNetwork
Input folders or files contain non-standard file extensions.
Use FileExtensions Name-Value pair to include the non-standard file extensions.
Error in CNN (line 84)
net = trainNetwork(Ttrain,layers,options);
Caused by:
Error using imageDatastore
Input folders or files contain non-standard file extensions.
Use FileExtensions Name-Value pair to include the non-standard file extensions.

採用された回答

Steven Lord
Steven Lord 2023 年 3 月 9 日
The imageDatastore object's documentation page states, in the description of the location input argument, that it "supports files that have an imformats format." Is the mat extension listed by imformats?
listOfFormats = imformats;
extensions = string([listOfFormats.ext]);
ismember("mat", extensions)
ans = logical
0
It is not. I'm not sure imageDatastore is the right tool for this job, or at least not with your data stored in MAT-files. If you really have image data, why not store the data in an image data file format? I happen to know that extensions has 25 elements, so to save space I'll reshape it into a 5-by-5 grid. Try saving your data in one of these formats using imwrite then create your datastore using those image files.
reshape(extensions, [5 5])
ans = 5×5 string array
"bmp" "hdf" "jpf" "pcx" "ras" "cur" "ico" "jpx" "pgm" "svs" "fts" "j2c" "jpg" "png" "tif" "fits" "j2k" "jpeg" "pnm" "tiff" "gif" "jp2" "pbm" "ppm" "xwd"

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Data Workflows についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by