"Error using roialign" when training a Mask R-CNN model - matlab

I am trying to train a maskrcnn model with trainMaskRCNN(), but get the following error after a number of iterations:
Warning: Empty Proposals. Skipping training step
> In maskrcnn/regionProposal (line 83)
In maskrcnn/forward (line 547)
In images.dltrain.internal.SerialTrainer>modelGradients (line 133)
In deep.internal.dlfeval (line 17)
In dlfeval (line 40)
In images.dltrain.internal/SerialTrainer/fit (line 76)
In images.dltrain.internal.dltrain (line 102)
In trainMaskRCNN (line 240)
In fibers_train (line 50)
Error using roialign
outFeatures = roialign(X, squeeze(boxes), poolSize, 'ROIScale', 1);
↑
Invalid argument at position 2. Value must not be empty.
Error in maskrcnn/roiAlignPooling (line 19)
outFeatures = roialign(X, squeeze(boxes), poolSize, 'ROIScale', 1);
Error in maskrcnn/forward (line 550)
dlPooled = roiAlignPooling(obj, dlX, dlProposals, obj.PoolSize);
Error in images.dltrain.internal.SerialTrainer>modelGradients (line 133)
[networkOutputs{:},state] = forward(net,inputs{:});
Error in deep.internal.dlfeval (line 17)
[varargout{1:nargout}] = fun(x{:});
Error in dlfeval (line 40)
[varargout{1:nargout}] = deep.internal.dlfeval(fun,varargin{:});
Error in images.dltrain.internal.SerialTrainer/fit (line 76)
[loss,grad,state,networkOutputs,lossData] = dlfeval(#modelGradients,self.Network,self.LossFcn,...
Error in images.dltrain.internal.dltrain (line 102)
net = fit(networkTrainer);
Error in trainMaskRCNN (line 240)
[network,info] = images.dltrain.internal.dltrain(mbqTrain,network,options,lossFcn,metrics,'Loss', 'ExperimentMonitor',params.ExperimentMonitor);
Error in fibers_train (line 50)
[net,info] = trainMaskRCNN(ds,net,options); %,FreezeSubNetwork="backbone"
I don't really have any idea of what could be the cause of this. Any help?

Related

Is it possible to use integral2 /integral3 for piecewise constant function?

I have defined the following parameters:
sigma=#(u)0.2.*((0<=u) && (u<1))+0.3.*((1<=u) && (u<2));
alpha=#(u)0.1.*((0<=u) && (u<1))+0.4.*((1<=u) && (u<2));
lambda=3;
if lambda==0
E1Integrand=#(T,u,a)...
(-1.*(T-u).*exp(-1.*lambda.*(T-u))).^2.*...
(-1.*(T-a).*exp(-1.*lambda.*(T-a))).*...
sigma(u).^2.*alpha(a).*sigma(a);
else
E1Integrand=#(T,u,a)...
((1-exp(-1.*lambda.*(T-u)))./lambda).^2.*...
((1-exp(-1.*lambda.*(T-a)))./lambda).*...
sigma(u).^2.*alpha(a).*sigma(a);
end
E1Integrand_amax=#(u)u;
E1Integral=integral2(NewE1Integrand,0,1.5,0,E1Integrand_amax);
I want to do double integral for a piecewise constant function. However, the following error message occurs:
Operands to the || and && operators must be convertible to logical scalar values.
Error in #(u)0.2.*((0<=u)&&(u<1))+0.3.*((1<=u)&&(u<2))
Error in
#(T,u,a)((1-exp(-1.*lambda.*(T-u)))./lambda).^2.*((1-exp(-1.*lambda.*(T-
a)))./lambda).*sigma(u).^2.*alpha(a).*sigma(a)
Error in #(u,a)E1Integrand(0.2,u,a)
Error in integral2Calc>integral2t/tensor (line 228)
Z = FUN(X,Y); NFE = NFE + 1;
Error in integral2Calc>integral2t (line 55)
[Qsub,esub] = tensor(thetaL,thetaR,phiB,phiT);
Error in integral2Calc (line 9)
[q,errbnd] = integral2t(fun,xmin,xmax,ymin,ymax,optionstruct);
Error in integral2 (line 106)
Q = integral2Calc(fun,xmin,xmax,yminfun,ymaxfun,opstruct);
I wonder how to fix it, or integral2 cannot use to integrate piecewise constant function.

Errors in using integral2 in MATLAB

I have asked this question two days ago. Now I re-derive the formulas and write new codes. But I still encounter the same error in using integral2.
clear
clc
% parameter settings
syms KI c r phi
KId = 0.000005;
G = 76.0;
nu = 0.31;
Vh = 2;
NA = 6.02214129*10^23;
b = 3.52*sqrt(6)/6;
A0 = G*b^2*(2-nu)/(8*pi*(1-nu));
lambda = 2;
m = 2.2;
kapa = 1.0;
beff = b;
delta2 = 1.0;
D = 1.9*10^(-14);
kB = 1.38064852*10^(-23);
R = 8.3144598;
E = 250;
Rc = 2*b;
for c0=0.0000005:0.0000005:0.0001
for T=1:1:300
for rou=b:b:10*b
for theta=0:0.01*pi:pi
h = (5*(1+nu)*D*Vh*cos(theta/2)*KI^2/(12*sqrt(2*pi)*kB*NA*T*KId))^(2/5);
B0 = G*Vh*c*h^2/(2*pi*(1-nu));
sigma1122 = ((cos(2*theta)*rou^2 + cos(2*phi)*r^2 - cos(theta - phi)*2*rou*r)*((sqrt(rou/r) + sqrt(r/rou))*cos((theta + phi)/2) - 2) + (sin(2*theta)*rou^2 - sin(2*phi)*r^2 - sin(theta - phi)*2*rou*r)*(sqrt(rou/r) - sqrt(r/rou))*sin((theta + phi)/2))*B0/((cos(2*theta)*rou^2 + cos(2*phi)*r^2 - cos(theta - phi)*2*rou*r)^2 + (sin(2*theta)*rou^2 - sin(2*phi)*r^2 - sin(theta - phi)*2*rou*r)^2); % 2*(psiHc+conj(psiHc));
sigma12 = KI*sin(theta)*cos(theta/2)/(2*sqrt(2*pi*rou));
c = c0*exp(((1+nu)*sigma1122/3-2*E*Vh*(c-c0)/(9*(1-nu)))*Vh/(R*T));
fun = #(r,phi) c*sin(2*phi)/r;
eq = pi*rou*A0*(log(8*rou*m/(lambda*b))-2)+kapa*G*beff^2*delta2-0.5*b*pi*rou^2*(sigma12-(G*Vh/(2*pi*(1-nu)*NA))*integral2(fun,0,Rc,0,2*pi));
solve(eq==0,KI);
end
end
end
end
The error information is:
Warning: The system is inconsistent. Solution does not exist.
In symengine (line 57)
In sym/privBinaryOp (line 903)
In / (line 297)
In #(r,phi)c*sin(2*phi)/r
In integral2Calc>integral2t/tensor (line 228)
In integral2Calc>integral2t (line 55)
In integral2Calc (line 9)
In integral2 (line 106)
In KIpredictor (line 44)
Error using integral2Calc>integral2t/tensor (line 231)
Input function must return 'double' or 'single' values. Found 'sym'.
Error in integral2Calc>integral2t (line 55)
[Qsub,esub] = tensor(thetaL,thetaR,phiB,phiT);
Error in integral2Calc (line 9)
> [q,errbnd] = integral2t(fun,xmin,xmax,ymin,ymax,optionstruct);
Error in integral2 (line 106)
> Q = integral2Calc(fun,xmin,xmax,yminfun,ymaxfun,opstruct);
Error in KIpredictor (line 44)
> eq =
pi*rou*A0*(log(8*rou*m/(lambda*b))-2)+kapa*G*beff^2*delta2-0.5*b*pi*rou^2*(sigma12-(G*Vh/(2*pi*(1-nu)*NA))*integral2(fun,0,Rc,0,2*pi));
I think the problem is due the complexity of the integrand. A detailed description of the integand is in the attached figure.
formula

Matlab- 1D Numerical integration with function stored in multiple variables

as you can see in the last few lines below, I'm trying to store my function on multiple variables because it gets rather ugly. However, doing this yields the error shown below.
A fix for this would be to manually substitute k and kp, but this is precisely what I'm trying to avoid. Any help would be appreciated. thanks!
clc
clear
hbar = 1.055e-34;
mo = 9.1095e-31;
q = 1.602e-19;
kb=1.38065e-23;
T=298;
Ef = -0.1*q; % -100meV in units Joules
V0 = 1*q;
L = 1e-9;
k = #(E) (2*mo*E/hbar.^2)^.5;
kp = #(E) (2*mo*(V0-E)/hbar.^2)^.5;
fun = #(E) (exp(-2*kp*L) .* ((16*k.^2 .* kp.^2) ./ ((k.^2 + kp.^2).^2))) .* exp(-E./(kb*T));
Q = integral(fun,0,inf);
Error below
Undefined operator '*' for input arguments of type 'function_handle'.
Error in #(E)(exp(-2*kp*L).*((16*k.^2.*kp.^2)./((k.^2+kp.^2).^2))).*exp(-E./(kb*T))
Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
Error in integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 83)
[q,errbnd] = vadapt(#AToInfInvTransform,interval);
Error in integral (line 88)
Q = integralCalc(fun,a,b,opstruct);
Error in PS3_2 (line 17)
Q = integral(fun,0,inf);
Use this here
k = #(E) (2.*mo.*E./hbar.^2).^.5;
kp = #(E) (2.*mo.*(V0-E)./hbar.^2).^.5;
fun = #(E) (exp(-2*kp(E)*L).*((16*k(E).^2.*kp(E).^2)./((k(E).^2+kp(E).^2).^2))).*exp(-E./(kb*T));
Q = integral(fun,0,inf);
I think you need to pass the argument E, then are you sure kb*T is correct? Maybe kp(E)*T? Then, you forgot the . is the sqrt for k and kp, or if it isn't a sqrt then the dot is on the wrong side of the power symbol.

Questions with integral2 , Double, Syms and Dot calucations

I got 2 questions here.
1. If I have y = a*x^2 + 5. What function can make it into y = a.*x.^2 +5. As you seen, dot was inserted.
It's easy, but kinda diffcult to describe, but please have patience with me. Thank you so much.
First, let me make a very simple example of my problem.
If I want to calucate Y = F(x=1)+ 2.^2, and I know F(x=1) = a+b,(a and b are syms). This means Y = a + b + 4. Problem is here,
Matlab give me error if I write down as.
F = function( .... ); <==== output of function is F(X=1), and = F(x=1) = a+b
Y = integral2( F + 2.^2, .. , .. ,..)
However, if I just copy the output of F as
Y = integral2( a+b + 2.^2, .. , .. ,..)
Now it works!!!
Ok. Please allow me to talk about my code here. I am trying to find a double interation by using integral2. One part of my equcation(which is Y) is from another int output(which is F). Matlab will give ERROR for code below:
clear all;
a=4;
la1=1/(pi*500^2); la2= la1*5;
p1=25; p2=p1/25;
sgma2=10^(-11);
index=1;
g=2./a;
syms r u1 u2
powe= -2 ;
seta= 10^powe;
xNor = ( (u2./u1).^(a./2) + 1 ).^(2./a);
x = (xNor).^(0.5) * seta^(-1/a);
fun1 = r./(1+ r.^a );
out1 = int(fun1, x, Inf) ; %== This is my F in my example
q=pi.*(la1.*p1.^(2./a)+la2.*p2.^(2./a));
yi = #(u2,u1) exp(-u2.*(1+2.*...
( out1 )./... %=== out1 is the problem here.
( (( (u2./u1).^(a./2) + 1 ).^(2./a)).*seta.^(-2./a)))).*...
exp(-sgma2.*q.^(-a./2).* seta.*u2.^(a./2)./...
((( (u2./u1).^(a./2) + 1 ).^(2./a)).^(a./2)) );
maxF =#(u2) u2;
out2 = integral2(yi,0,Inf,0 ,maxF) % == this is Y in my previous example.
However, since I know the out1 = pi/4 - atan(10*(u2^2/u1^2 + 1)^(1/2))/2 (no dot,1/2, not 1./2). Instead of writing down out1, I will just type the equaction and add dot in the
yi = #(u2,u1) exp(-u2.*(1+2.*...
( pi./4 - atan(10.*(u2.^2./u1.^2 + 1).^(1./2))./2 )./... %=== not "out1"
( (( (u2./u1).^(a./2) + 1 ).^(2./a)).*seta.^(-2./a)))).*...
exp(-sgma2.*q.^(-a./2).* seta.*u2.^(a./2)./...
((( (u2./u1).^(a./2) + 1 ).^(2./a)).^(a./2)) );
Now the code is working!!!! The final output is = 0.9957.
Dear friends, I already spend a long time on this, but I still can not find out the problem. Could you please take a deeper look for me. Please copy the code to you matlab and test. Thank you so much.
Below is the error given by matlab, if I just use "out1" in yi = #(u2,u1) ......
Error using integralCalc/finalInputChecks (line 511)
Input function must return 'double' or 'single' values. Found 'sym'.
Error in integralCalc/iterateScalarValued (line 315)
finalInputChecks(x,fx);
Error in integralCalc/vadapt (line 133)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 76)
[q,errbnd] = vadapt(#AtoBInvTransform,interval);
Error in
integral2Calc>#(xi,y1i,y2i)integralCalc(#(y)fun(xi*ones(size(y)),y),y1i,y2i,opstruct.integralOptions)
(line 18)
innerintegral = #(x)arrayfun(#(xi,y1i,y2i)integralCalc( ...
Error in
integral2Calc>#(x)arrayfun(#(xi,y1i,y2i)integralCalc(#(y)fun(xi*ones(size(y)),y),y1i,y2i,opstruct.integralOptions),x,ymin(x),ymax(x))
(line 18)
innerintegral = #(x)arrayfun(#(xi,y1i,y2i)integralCalc( ...
Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
Error in integralCalc/vadapt (line 133)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 84)
[q,errbnd] = vadapt(#AToInfInvTransform,interval);
Error in integral2Calc>integral2i (line 21)
[q,errbnd] = integralCalc(innerintegral,xmin,xmax,opstruct.integralOptions);
Error in integral2Calc (line 8)
[q,errbnd] = integral2i(fun,xmin,xmax,ymin,ymax,optionstruct);
Error in integral2 (line 107)
Q = integral2Calc(fun,xmin,xmax,yminfun,ymaxfun,opstruct);
Error in ref7_equ11n2 (line 129)
out2 = integral2(yi,0,Inf,0 ,maxF)
The documentation of the function integral2 states:
integral2 - Numerically evaluate double integral
You won't be able to use integral2 with symbolic expressions, unless you convert them to function handles using matlabfunction.

Error with strcmp matlab

In follow-up to a question of mine from yesterday, I tried to do the following:
For the b0, bq+1 and B I did:
bq1 = [];
for (i=1:length(Mte(1,:,3)))
t = sym(['bq' int2str(i)]);
bq1 = [bq1; t];
end
I then ran:
>> solve(H_tot_te*b == Mte(:,:,Q)*bq1 + lvec + Mprime*B1)
Error using char
Conversion to char from logical is not possible.
Error in solve>getEqns (line 245)
vc = char(v);
Error in solve (line 141)
[eqns,vars,options] = getEqns(varargin{:});
So I tried:
>> solve(double(H_tot_te*b == Mte(:,:,Q)*bq1 + lvec + Mprime*B1))
Error using strcmp
The number of rows of the string matrix must
match the number of elements in the cell.
Error in solve>getEqns (line 246)
if any(strcmp(vc, {'IgnoreAnalyticConstraints', 'IgnoreSpecialCases', ...
Error in solve (line 141)
[eqns,vars,options] = getEqns(varargin{:});
What does this error mean, and how I can fix it?