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

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 Commenti

Well, the obvious thing to say is that in the code you have shown us objectrecognition is indeed not defined. Where are you supposedly defining it?
Your going to have to make it even more "obvious" for me. I know how to define regular variable but not folders. I am working with code that was handed down to me. I am still learning and by no means an "expert". These concepts are new to me so snarky attitudes aren't necessary, thanks bud.
I'm not sure how it can be made more obvious
If you write:
b = sin(a)
but have never created the variable a, matlab is going to tell you that a is undefined.
Similarly, if you write:
I = imread(objectrecognition.testcoral{1});
but have never created the variable objectrecognition, matlab is going to tell you it's undefined.
No idea why you're talking about folders though.
Because I'm trying to import a folder of images to be processed, I thought that was OBVIOUS from the question. Yes it is OBVIOUS that if you don't define a variable matlab won't know what to do with it. I'm not trying to define a VARIABLE I'm trying to read in several images. In case it isn't OBVIOUS I don't know how to define a FOLDER as a VARIABLE. Perhaps you should try to actually help instead of being sarcastic. Since your experts please tell me how to define my folder of images so matlab will recognize them.
You need to cut down the attitude a bit. There was no sarcasm in my comment and nothing is obvious in your question and despite what you may think, we're trying to help you.
In particular, I've no idea what you mean by defining a folder as a variable. Folders and variables are not interchangeable, they're two completely different concepts. You can put the name of a folder in a variable, eg.:
thisvariablecontainsafoldername = 'C:\My document\My Image Folder';
and possibly you can then use that name to tell matlab to load an image in that folder:
someimage = imread(fullfile(thisvariablecontainsafoldername, 'FancyImage.png'));
or more directly as:
someimage = imread('C:\My document\My Image Folder\FancyImage.png')
I've no idea if that's something like that you're after and if it is I've no idea why you think that objectrecognition.testcoral{1} would be interpreted as something remotely similar.
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.
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'

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Deep Learning Toolbox in Centro assistenza e File Exchange

Richiesto:

il 27 Feb 2020

Commentato:

il 28 Feb 2020

Community Treasure Hunt

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

Start Hunting!

Translated by