error: Reference to non-existent field 'opts'.

hello, error occurs when I run demo_im2mcg.m:
Reference to non-existent field 'opts'.
Error in edgesDetect (line 33)
opts=model.opts; opts.nTreesEval=min(opts.nTreesEval,opts.nTrees);
Error in img2ucms>img2ucm (line 91)
[E,~,O] = edgesDetect( I, model );
Error in img2ucms>img2ucm_scale (line 75)
[ucm2, times] = img2ucm(I, model, param.mult_Pb, param.sat_sPb, param.nvec, param.dthresh, param.ic_gamma);
Error in img2ucms (line 56)
[ucms{s}, times] = img2ucm_scale(I, model, param);
Error in im2mcg (line 63)
[ucm2] = img2ucms(image, sf_model, scales);
Error in demo_im2mcg (line 10)
[candidates_scg, ucm2_scg] = im2mcg(I,'fast');
demo_im2mcg.m is following:
%% Demo to show the results of MCG
clear all;close all;home;
% Read an input image
I = imread(fullfile(root_dir, 'demos','101087.jpg'));
tic;
% Test the 'fast' version, which takes around 5 seconds in mean
[candidates_scg, ucm2_scg] = im2mcg(I,'fast');
toc;
tic;
% Test the 'accurate' version, which tackes around 30 seconds in mean
[candidates_mcg, ucm2_mcg] = im2mcg(I,'accurate');
toc;
%% Show UCM results (dilated for visualization)
figure;
subplot(1,3,1)
imshow(I), title('Image')
subplot(1,3,2)
imshow(imdilate(ucm2_scg,strel(ones(3))),[]), title('Fast UCM (SCG)')
subplot(1,3,3)
imshow(imdilate(ucm2_mcg,strel(ones(3))),[]), title('Accurate UCM (MCG)')
%% Show Object Candidates results and bounding boxes
% Candidates in rank position 11 and 12
id1 = 11; id2 = 12;
% Get the masks from superpixels and labels
mask1 = ismember(candidates_mcg.superpixels, candidates_mcg.labels{id1});
mask2 = ismember(candidates_mcg.superpixels, candidates_mcg.labels{id2});
% Bboxes is a matrix that contains the four coordinates of the bounding box
% of each candidate in the form [up,left,down,right]. See folder bboxes for
% more function to work with them
% Show results
figure;
subplot(1,3,1)
imshow(I), title('Image')
subplot(1,3,2)
imshow(mask1), title('Candidate + Box')
hold on
plot([candidates_mcg.bboxes(id1,4) candidates_mcg.bboxes(id1,4) candidates_mcg.bboxes(id1,2) candidates_mcg.bboxes(id1,2) candidates_mcg.bboxes(id1,4)],...
[candidates_mcg.bboxes(id1,3) candidates_mcg.bboxes(id1,1) candidates_mcg.bboxes(id1,1) candidates_mcg.bboxes(id1,3) candidates_mcg.bboxes(id1,3)],'r-')
subplot(1,3,3)
imshow(mask2), title('Candidate + Box')
hold on
plot([candidates_mcg.bboxes(id2,4) candidates_mcg.bboxes(id2,4) candidates_mcg.bboxes(id2,2) candidates_mcg.bboxes(id2,2) candidates_mcg.bboxes(id2,4)],...
[candidates_mcg.bboxes(id2,3) candidates_mcg.bboxes(id2,1) candidates_mcg.bboxes(id2,1) candidates_mcg.bboxes(id2,3) candidates_mcg.bboxes(id2,3)],'r-')
edgesDetect function is following:
Copyright code removed, the function edgesDetect is available here:
can anybody help to solve it? thank you !

2 Kommentare

Adam Danz
Adam Danz am 21 Nov. 2019
If you edit your question and format your code by selecting the code and using the [>] button, it will be much easier to read.
Adam Danz
Adam Danz am 21 Nov. 2019
I don't see where edgesDetect is being called or where the 2nd input 'model' is produced. Obviously 'model' should be a structure with a field "opts" and this variable is likely produced by another function but we don't see that part.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Ridwan Alam
Ridwan Alam am 21 Nov. 2019
Bearbeitet: Ridwan Alam am 21 Nov. 2019

2 Stimmen

Updated Solution:
inside im2mcg.m, (line 52)
sf_model = loadvar(fullfile(mcg_root, 'datasets', 'models', 'sf_modelFinal.mat'),'model');
change that to:
sf_model = load(fullfile(mcg_root, 'datasets', 'models', 'sf_modelFinal.mat'));
sf_model = sf_model.model;
%% old conversation
Can you double check your downloaded version of the model?
This one has model.opts:

11 Kommentare

shengzhou
shengzhou am 21 Nov. 2019
Thank you for your answer, but it still does not work. Both two models have model.opts, I'm not sure whether I did something when I run 'full' folder. Have you ever run the code of MCG and meet the same error? I will eally appreciate it if you can give me more advices.
Ridwan Alam
Ridwan Alam am 21 Nov. 2019
Bearbeitet: Ridwan Alam am 21 Nov. 2019
Sure. Unfortunately, I haven't. Sometimes it depends a lot on the installation process. I belive you have tried uninstalling and reinstalling the package.
But my two cents in this case would be to add a "breakpoint" in edgesDetect() before line with "opts=model.opts; opts.nTreesEval=min(opts.nTreesEval,opts.nTrees);". And double check if the model passed to this function has the "opts" property.
It's always a challenge to work with libraries like this. Sorry, the best I can do here is to help you debug.
Ridwan Alam
Ridwan Alam am 21 Nov. 2019
Bearbeitet: Ridwan Alam am 21 Nov. 2019
Just a hunch:
inside im2mcg.m, (line 52)
sf_model = loadvar(fullfile(mcg_root, 'datasets', 'models', 'sf_modelFinal.mat'),'model');
change that to:
sf_model = load(fullfile(mcg_root, 'datasets', 'models', 'sf_modelFinal.mat'));
sf_model = sf_model.model;
Please keep me informed how it goes.
shengzhou
shengzhou am 21 Nov. 2019
Screenshot from 2019-11-21 22-20-54.png
I ever added a "breakpoint" in edgesDetect() before line with "opts=model.opts; opts.nTreesEval=min(opts.nTreesEval,opts.nTrees);". The model has been passed to this function and it should have the field 'opts', but it doesn't work.
Ridwan Alam
Ridwan Alam am 21 Nov. 2019
BINGO!!
you see it's not "model.opts", its "model.model.opts"
Solution:
inside im2mcg.m, (line 52)
sf_model = loadvar(fullfile(mcg_root, 'datasets', 'models', 'sf_modelFinal.mat'),'model');
change that to:
sf_model = load(fullfile(mcg_root, 'datasets', 'models', 'sf_modelFinal.mat'));
sf_model = sf_model.model;
shengzhou
shengzhou am 21 Nov. 2019
yes, it works! could you tell me why? Thank you.
Ridwan Alam
Ridwan Alam am 21 Nov. 2019
Because "loadvar" is obsolete. "load" is replacing "loadvar".
Please accept my response as an answer, and vote if you appreciate the help. Thanks!
shengzhou
shengzhou am 21 Nov. 2019
ok, thank you so much.
Adam Danz
Adam Danz am 21 Nov. 2019
+1
nice persistence
Ridwan Alam
Ridwan Alam am 21 Nov. 2019
thanks :-)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by