Hi everyone,
Julia is (sometimes) segfaulting when running this function :
function emloop(img, Sigma, mu, t, model, imgc, bg, FullTs)
EMiter = 1;
Check = typemax(Float64);
GModels, Genes,
(x, y) = size(img);
D = zeros(x, y); E = zeros(x, y); B = zeros(x, y);
# And we start the EM loop
while EMiter <= maxEM && Check > ϵ
# Calculate the betas & find the optimal transformation for the current
iteration
(D, E, B) = fastBetas(model, [], mu, Sigma, img);
nt = findTransform(model, B, Gray((bg.r + bg.g + bg.b)/3), FullTs);
# Now calculate the optimal parameters for the appearance model
OldMu = mu; # For termination purposes
(mu, Sigma) = calcTheta(img, D, E, B);
# Apply the transformation found to the image
img = RigidTransform(img, nt, bg, true, true);
# Deal with the transformation
Oldt = t;
t += nt;
t.tx %= x;
t.ty %= y;
# Termination criteria
NormOldTT = sqrt((Oldt.tx - t.tx)^2 + (Oldt.ty - t.ty)^2 + (Oldt.θ -
t.θ)^2);
CheckMu = norm(OldMu.D - mu.D) + norm(OldMu.E - mu.E) + norm(OldMu.B -
mu.B)
Check = CheckMu + NormOldTT # Giving lots of weight to the
transformation
EMiter += 1;
end
return emdata(D, E, B, img, θ(Sigma, mu), t);
end
Some context: img is and Image{RGB{Float64}}, Sigma and mu are custom types
:
type Σ
D::Array{Float64, 2}
E::Array{Float64, 2}
B::Array{Float64, 2}
end
type μ
D::Array{Float64, 1}
E::Array{Float64, 1}
B::Array{Float64, 1}
end
t is another custom type to represent a rigid body transformation
(translation_x, translation_y, rotation_angle), bg is, for example,
RGB(0.0, 0.0, 0.0) (black), and FullTs is an array of transformations,
namely all the transformations we consider.
It's weird for multiple reasons: first of all, this code was running fine
when not in a separate function returning a custom type (the custom type in
the return is to ease the access since I want to call this function for an
array of images with pmap and output all that which is not practical).
Furthermore, sometimes it crashes with a segfault, sometimes with an
undefined reference on this line, not always after the same EM iteration:
CheckMu = norm(OldMu.D - mu.D) + norm(OldMu.E - mu.E) + norm(OldMu.B - mu.B)
Thanks in advance for the help,
Archibald