undefined variable or class when using imread for object recognition, machine learning

5 views (last 30 days)
I am working on an object recognition program to detect and classify objects in the ocean using Matlabs Yolo deep learning function. I am using the imread function to import jpeg files into matlab to then be evaluated. I am getting an undefined variable or class in my imread function. The folders containing the images are in my directory. Any guidance would be appreciated, the portion of code with the error is attached.
doTraining = true;
% if ~doTraining && ~exist('yolov2ResNet50VehicleExample.mat','file')
% % Download pretrained detector.
% disp('Downloading pretrained detector (98 MB)...');
% pretrainedURL = 'https://www.mathworks.com/supportfiles/vision/data/yolov2ResNet50VehicleExample.mat';
% websave('yolov2ResNet50VehicleExample.mat',pretrainedURL);
% end
% The above comments are the initial code that is run when downloading the
% pre-trained dector from Matlab. When these run: doTraining = false.
% Moving forward, doTraining must be true. This allows new images to be
% trained on this detector.
%%
% This command reads a selected image out of a folder titled "Coral"- the
% folder name must be changed here when using a new folder of images.
I = imread(objectrecognition.testcoral{1}); ERROR
% The ROI (Region of Interest) labels are obtained using the Matlab
% imageLabeler- type this into the command window to have the Image Labeler
% appear. The ROI labels are to be selected by hand on the desired
% images.
% Insert the ROI labels from the Table obtained from imageLabeler
I = insertShape(I,'Rectangle',Coral.Healthy{4});
% Resize and display image.
I = imresize(I,3);
imshow(I)
error:
Undefined variable "objectrecognition" or class "objectrecognition.testcoral".
Error in Untitled3 (line 17)
I = imread(objectrecognition.testcoral{1});
  7 Comments
Image Analyst
Image Analyst on 28 Feb 2020
I see nothing demeaning from Adam or Guillaume or see where Jacob's intelligence was mentioned at all by them. I almost decided not to try to help but thought I'd try to see if we can start from scratch with a better attitude.
Jacob, can you post or give the name of the example from the Deep Learning Toolbox that you are trying to modify? My guess is that objectrecognition has something to do with an imageDatastore, which the Mathworks often uses when doing deep learning training. Also attach your FULL code so we can see where you started modifying the original example and mistakenly somehow deleted the lines where objectrecognition was created.
Adam
Adam on 28 Feb 2020
With such a terrible attitude to learning and asking for help you are lucky that anyone wants to help.
imread is a function. You either pass a variable to it as its input or you pass a hard-coded string. But from what you have said you knnow how to create a variable. I assume you also know how to create a hard-coded string that points to the folder location.
But instead, what you are using is objectrecognition. That is why the error message talks about variables and why I and others talked about variables. This is expected to be a variable, so it has to be defined. If it isn't it doesn't refer to a set of files or anything. But as your comments seem to suggest you know all this anyway. So since you aren't going beyond that I guess there's no more help to give. You know what a variable is, you know how to define one, so define one that contains a string that points to your folder location = e.g. 'C:\SomeFolder\SomeSubfolder'

Sign in to comment.

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 27 Feb 2020
help imread

More Answers (0)

Community Treasure Hunt

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

Start Hunting!