![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1492317/image.png)
Error using augmented image datastore
8 次查看(过去 30 天)
显示 更早的评论
Hi all,
So sorry for such a straighforward question, however, I cannot seem to resolve this as I work through the example online or using my own data, I am working through the image captioning example, however, when I get to the part that requires me to use augmentation along with an image Datastore:
tblFilenames = table(cat(1,annotationsTrain.Filename));
augimdsTrain = augmentedImageDatastore(inputSizeNet,tblFilenames,'ColorPreprocessing','gray2rgb')
I get the following error:
Error using augmentedImageDatastore (line 251) Unexpected image path. Provide valid image paths in the first column of the table.
This error occurs both when I use my own data and the data downloaded from mathworks specified in the example. I haven't really used a table of image paths before when setting up a datastore so I am probably doing something very silly at this stage. Apologies again for such a basic question. Any help would be much appreciated
0 个评论
回答(1 个)
Siraj
2023-9-25
Hi!
I understand that you are trying to create an augmented datastore by providing a table of predictors and responses to the "augmentedImageDatastore" function. However, you are encountering an error message stating "Unexpected image path," which indicates that there might be an issue with the image paths you are using.
It appears that the error is caused by incorrect or invalid image paths when using the “augmentedImageDatastore” function with a table as input. In this case, the table should contain absolute or relative image paths in its first column.
To resolve the error, it is important to double-check the entries in the table and ensure that they contain the correct image paths. Location of the images may vary depending on the system and the current working directory. Therefore, using the example path directly may not be appropriate for your specific setup.
Here's a short working example that demonstrates the process of generating random images, saving them in a folder, reading the images back, storing their locations in a table, and finally creating an “augmentedImageDatastore” using the table.
% Create a new folder to store the generated images
mkdir('TrainImages');
imageSize = [128, 128];
% Generate and save 5 random images
for i = 1:5
% Generate a random image
randomImage = randi([0, 255], imageSize, 'uint8');
% Create a filename for the image
filename = sprintf('TrainImages/random_image_%d.png', i);
% Save the image
imwrite(randomImage, filename);
end
folderPath = 'TrainImages'; % Specify the folder path
% Get a list of all files in the folder
fileList = dir(fullfile(folderPath, '*.png')); % Change the extension if needed
filenames = {};
% Loop through the files and store the filenames in a cell array
for i = 1:numel(fileList)
filename = fullfile(folderPath, fileList(i).name);
filenames = [filenames, filename];
end
% Create a table with the filenames
tblFilenames = table(filenames', 'VariableNames', {'Filename'});
inputSizeNet = [64, 64, 3];
% Create an augmentedImageDatastore
augimdsTrain = augmentedImageDatastore(inputSizeNet, tblFilenames, 'ColorPreprocessing', 'gray2rgb');
Additionally, I am including the structure of the current working directory to provide a clearer understanding.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1492317/image.png)
For further information on the "augmentedImageDatastore" function, you can refer to the following link:
To learn more about the "fullfile" function, you can refer to the following link:
Hope this helps.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!