Azzera filtri
Azzera filtri

(I have provided a workaround in comments but it is no answer) Matlab example "Train Deep Learning Semantic Segmentation Network Using 3-D Simulation Data" doesn't work.

12 visualizzazioni (ultimi 30 giorni)
Note: If it is not clear in my original post... then let me clarify that the folders are empty. Therefore IncludeSubfolders cannot fix this as there is no subfolder to search for. We are already looking at the most "sub" subfolder possible. Also, I have an intuition regarding what the issue might be but didn't wanna say it to make room for other ideas. My intuition says the problem lies in (a helper function) downloadDataset's last sections where it copies and splits the full data into the specified subfolders created. Note that we are already looking at them without the need for IncludeSubfolders. So setting it to "True" can't fix the issue. While I have an idea where the problem lies... I am quite unqualified to fix this example MATLAB documentation has provided. Further note that the issue has nothing to do with my local environment as it doesn't work on MATLAB cloud either.
Edit: I re-run the script through cloud rather than a local machine and the exact same error happened.
Original post: I have tested the example and found out that the data splitting of real data doesn't properly happen despite the successful creation of its folders. This, in turn, makes the example broken and unusable. Since the split never happens, there is no splitted data in the folders and thus the error is a generic error as expected. I did not altered the code. The link for this example is https://www.mathworks.com/help/deeplearning/ug/train-deep-learning-semantic-segmentation-network-using-3d-simulation-data.html
Error using imageDatastore (line 139)
Folder 'C:\...\AppData\Local\Temp\RealData\train\images' does not have any files or is empty.
Use 'IncludeSubfolders' to include files in all subfolders.
This error comes from the line below:
realData = imageDatastore(realImagesFolder);
I want to be able to run this example.
Edited Note-2: I found the issue with the helper function. I am copying the helper code in its entirety to show you the original. A possible solution will be provided in the answers. (A solution couldn't provided but there is a workaround, I will not accept the workaround as an answer. So that this question can be answered properly by someone else.)
function [simulationImagesFolder, simulationLabelsFolder, realImagesFolder, realLabelsFolder,...
realTestImagesFolder, realTestLabelsFolder] = ...
downloadDataset(simulationDataLocation, simulationDataURL, realDataLocation, realImageDataURL, realLabelDataURL)
% Build the training image and label folder location for simulation data.
simulationDataZip = fullfile(simulationDataLocation,'SimulationDrivingDataset.zip');
% Get the simulation data if it does not exist.
if ~exist(simulationDataZip,'file')
mkdir(simulationDataLocation)
disp('Downloading the simulation data');
websave(simulationDataZip,simulationDataURL);
unzip(simulationDataZip,simulationDataLocation);
end
simulationImagesFolder = fullfile(simulationDataLocation,'SimulationDrivingDataset','images');
simulationLabelsFolder = fullfile(simulationDataLocation,'SimulationDrivingDataset','labels');
camVidLabelsZip = fullfile(realDataLocation,'CamVidLabels.zip');
camVidImagesZip = fullfile(realDataLocation,'CamVidImages.zip');
if ~exist(camVidLabelsZip,'file') || ~exist(camVidImagesZip,'file')
mkdir(realDataLocation)
disp('Downloading 16 MB CamVid dataset labels...');
websave(camVidLabelsZip, realLabelDataURL);
unzip(camVidLabelsZip, fullfile(realDataLocation,'CamVidLabels'));
disp('Downloading 587 MB CamVid dataset images...');
websave(camVidImagesZip, realImageDataURL);
unzip(camVidImagesZip, fullfile(realDataLocation,'CamVidImages'));
end
% Build the training image and label folder location for real data.
realImagesFolder = fullfile(realDataLocation,'train','images');
realLabelsFolder = fullfile(realDataLocation,'train','labels');
% Build the testing image and label folder location for real data.
realTestImagesFolder = fullfile(realDataLocation,'test','images');
realTestLabelsFolder = fullfile(realDataLocation,'test','labels');
% Partition the data into training and test sets if they do not exist.
if ~exist(realImagesFolder,'file') || ~exist(realLabelsFolder,'file') || ...
~exist(realTestImagesFolder,'file') || ~exist(realTestLabelsFolder,'file')
mkdir(realImagesFolder);
mkdir(realLabelsFolder);
mkdir(realTestImagesFolder);
mkdir(realTestLabelsFolder);
% Load the mat file that has the names for testing and training.
partitionNames = load('subsetCamVidDatasetFileNames.mat');
% Extract the test images names.
imageTestNames = partitionNames.imageTestNames;
% Remove the empty cells.
imageTestNames = imageTestNames(~cellfun('isempty',imageTestNames));
% Extract the test labels names.
labelTestNames = partitionNames.labelTestNames;
% Remove the empty cells.
labelTestNames = labelTestNames(~cellfun('isempty',labelTestNames));
% Copy the test images to the respective folder.
for i = 1:size(imageTestNames,1)
labelSource = fullfile(realDataLocation,'CamVidLabels',labelTestNames(i));
imageSource = fullfile(realDataLocation,'CamVidImages','701_StillsRaw_full',imageTestNames(i));
copyfile(imageSource{1}, realTestImagesFolder);
copyfile(labelSource{1}, realTestLabelsFolder);
end
% Extract the train images names.
imageTrainNames = partitionNames.imageTrainNames;
% Remove the empty cells.
imageTrainNames = imageTrainNames(~cellfun('isempty',imageTrainNames));
% Extract the train labels names.
labelTrainNames = partitionNames.labelTrainNames;
% Remove the empty cells.
labelTrainNames = labelTrainNames(~cellfun('isempty',labelTrainNames));
% Copy the train images to the respective folder.
for i = 1:size(imageTrainNames,1)
labelSource = fullfile(realDataLocation,'CamVidLabels',labelTrainNames(i));
imageSource = fullfile(realDataLocation,'CamVidImages','701_StillsRaw_full',imageTrainNames(i));
copyfile(imageSource{1},realImagesFolder);
copyfile(labelSource{1},realLabelsFolder);
end

Risposte (2)

Shreeya
Shreeya il 9 Mag 2024
Hello
A quick look at the error suggests that the content inside the folder is not included in the path and is not accessible, causing the error. The "imageDatastore" accepts the argument ""IncludeSubfolders" as the subfolder inclusion flag. Specify this as true to include all files and subfolders within each folder. You can have a look at the link below for further reference
  1 Commento
Ozgur Toprak Sahin
Ozgur Toprak Sahin il 9 Mag 2024
Modificato: Ozgur Toprak Sahin il 9 Mag 2024
Edit: As expected... it didn't work because there is no subfolder. It is empty just like I mentioned in the post itself. : (
Thanks for your response and sorry for my long reply. I will try it in 2 hours when I get back to computer but I kinda doubt it will work as the folders are empty. So there is no subfolder within train folder.
There is a full dataset within a subfolder of RealData but the code tries to find train data rather than full data. I am suspecting that downloadDataset helper function doesn’t splits the data into train and test as it should though I couldn’t solve it :(
I have also checked whether the copy directory is correct or not… and it seems correct. If my intuition is correct, this narrows the problem to the last sections of downloadDataset but I am unqualified the fix the example.
Note: One thing that makes me more confident about the intuition is that the copy code works too fast. I don’t think that copying 587MB of data and then splitting it would be this fast.

Accedi per commentare.


Ozgur Toprak Sahin
Ozgur Toprak Sahin il 10 Mag 2024
Modificato: Ozgur Toprak Sahin il 10 Mag 2024
I am still typing the answer so wait... I also need to test this which will take me about 15 min due to large amount of data.
Edit: It is gonna take longer, I may have accidentally found a workaround which prevented me from trying my fix idea. So I have to redownload the files. (I am not working on a fix right now because I had to deal with other stuff but I am still curious. For now, there is only the workaround below)
Workaround: The problem is the last "if" inside the helper function. My idea was to pull the subfolder creations within "if" to fix the issue. However, running its inside seperately fixes the issue permanently (?!?) as a workaround. I tried my best to get the problem back so I could attempt to fix it but I couldn't. Once it is fixed... it is fixed for good. Now, you may be skeptical as to whether the problem actually existed in the first place. If that's the case then I suggest you to run the example unaltered and see it for yourself. Once the workaround is applied... the problem is gone. But I don't know whether turning on and off the cloud or machine would bring the issue back.
Workaround code:
mkdir(realImagesFolder);
mkdir(realLabelsFolder);
mkdir(realTestImagesFolder);
mkdir(realTestLabelsFolder);
% Load the mat file that has the names for testing and training.
partitionNames = load('subsetCamVidDatasetFileNames.mat');
% Extract the test images names.
imageTestNames = partitionNames.imageTestNames;
% Remove the empty cells.
imageTestNames = imageTestNames(~cellfun('isempty',imageTestNames));
% Extract the test labels names.
labelTestNames = partitionNames.labelTestNames;
% Remove the empty cells.
labelTestNames = labelTestNames(~cellfun('isempty',labelTestNames));
% Copy the test images to the respective folder.
for i = 1:size(imageTestNames,1)
labelSource = fullfile(realDataLocation,'CamVidLabels',labelTestNames(i));
imageSource = fullfile(realDataLocation,'CamVidImages','701_StillsRaw_full',imageTestNames(i));
copyfile(imageSource{1}, realTestImagesFolder);
copyfile(labelSource{1}, realTestLabelsFolder);
end
% Extract the train images names.
imageTrainNames = partitionNames.imageTrainNames;
% Remove the empty cells.
imageTrainNames = imageTrainNames(~cellfun('isempty',imageTrainNames));
% Extract the train labels names.
labelTrainNames = partitionNames.labelTrainNames;
% Remove the empty cells.
labelTrainNames = labelTrainNames(~cellfun('isempty',labelTrainNames));
% Copy the train images to the respective folder.
for i = 1:size(imageTrainNames,1)
labelSource = fullfile(realDataLocation,'CamVidLabels',labelTrainNames(i));
imageSource = fullfile(realDataLocation,'CamVidImages','701_StillsRaw_full',imageTrainNames(i));
copyfile(imageSource{1},realImagesFolder);
copyfile(labelSource{1},realLabelsFolder);
end
Just run this outside the helper function once and it is good.

Categorie

Scopri di più su Licensing on Cloud Platforms in Help Center e File Exchange

Prodotti


Release

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by