Hi all,
I built a custom nn model UnetSkipGenerator
, trained it and needed to save the results, therefore I used Flux.destructure
and saved the parameters it returned. Now I am trying to do some computations with them, but I noticed a behaviour that I cannot explain. When I try to copy values of parameters of one UnetSkipGenerator
to another UnetSkipGenerator
, as follows, it woks just fine.
Gxt1_nn = UnetSkipGenerator(3, 8, 128, 16, upsz)|>gpu
parst, nnt = Flux.destructure(Gxt1_nn)
Gxt1 = nnt(parst)
Gxt2 = UnetSkipGenerator(3, 8, 128, 16, upsz)|>gpu
h1 = Flux.params(Gxt1)
h2 = Flux.params(Gxt2)
for j = 1 : length(h1)
h1[j] .= bezier_phi_theta(0.0f0, θx1[j], h2[j], w2[2][j])
end
function bezier_phi_theta(t, θb, w1b, w2b)
return (1-t)^2*w1b + 2*t*(1-t)*θb + t^2*w2b
end
(Note: new value of h1
does not depend on θx1
nor w2[2]
, because t = 0.0
)
But when I initialize Gxt1
with the saved parameters, the networks return different values. I am pretty sure that the previously trained network was initialized the same way.
How I load the saved parameters:
res = matread("file_with_saved_params.mat")
θx = copy(res["theta"]) |>gpu #saved parametrs
Any suggestion on where the problem could be or where to look? Thanks in advance.
EDIT:
I will just add some other manipution I am doing with the loaded data. I don’t think that it influences the bahaviour somehow, but I always need them to run the upper piece of code.
Gx = UnetSkipGenerator(3, 8, 128, 16, upsz)|>gpu
θ, nn = Flux.destructure(Gx)|>gpu
res = matread("file_with_saved_params.mat")
θx = copy(res["theta"])
res2 = matread("file_with_saved_params2.mat")
θx2 = copy(res2["theta"])
Gxa = nn(θx)|>gpu
Gxb = nn(θx2)|>gpu
Gx1 = UnetSkipGenerator(3, 8, 128, 16, upsz)|>gpu
θx1 = Flux.params(Gx1)
θa = Flux.params(Gxa)
θb = Flux.params(Gxb)
w1 = [copy(pka), deepcopy(θa)] #pk comes from different network
w2 = [copy(pkb), deepcopy(θb)]