Closed eshafeeqe closed 7 years ago
Are you trying to do this per node or per edge actually?
It's a shot in the dark but maybe this helps: https://github.com/mihaibujanca/dynamicfusion/blob/gpu_optimisation/kfusion/solvers/dynamicfusion.t
Also check #97.
In terms of whether or not you can pass float or float3 in a graph, my guess it that you can't. Looking at the code, I think graphs are only supposed to be used with indices, so you should be having an external array for weights and the indices in the graph.
This is the OptGraph
constructor:
OptGraph(std::vector<std::vector<int>> indices) : m_indices(indices), m_edgeCount((int)indices[0].size()){
copyToGPU();
}
Its per edge actually, thanks, I will check both links
While it would be nice to be able to store value on graph edges, there currently isn't built-in support, You can emulate the behavior, however, by adding an extra Array, with dimension equal to the edge count, and an extra node in your graph that indexes into said array.
Example: Before adding a float3 weight to each edge:
N = Dim("N", 0)
nodes = Array("nodes", float3, {N}, 0)
G = Graph("G", 1, "v0", {N}, 2, "v1", {N), 3)
Energy( f(nodes(G.v0), nodes(G.v1)) )
After adding a float3 weight to each edge:
N,E = Dim("N", 0), Dim("E", 1)
nodes = Array("nodes", float3, {N}, 0)
weights = Array("weights", float3, {E}, 1)
G = Graph("G", 2, "v0", {N}, 3, "v1", {N), 4, "w", {E), 5)
Energy( f(nodes(G.v0), nodes(G.v1),weights(G.w)) )
On the C side, weights
is just like nodes
(but of length equal to the edge count), and the w
component of the graph should just be the trivial array {0,1,2,...,|E|-1}
.
@Mx7f Thanks for the detailed reply.
I updated new Opt and tried the following energy formulation code ` local N, D = Dim("N",0), Dim("D",1)
local w_fitSqrt = Param("w_fitSqrt", float, 0) local w_regSqrt = Param("w_regSqrt", float, 1) local w_rotSqrt = Param("w_rotSqrt", float, 2)
local Offset = Unknown("Offset",opt.float3,{N},3)
local RotRow1 = Unknown("RotRow1",opt.float3,{N},4) local RotRow2 = Unknown("RotRow2",opt.float3,{N},5) local RotRow3 = Unknown("RotRow3",opt.float3,{N},6)
local UrShape = Array("UrShape", opt.float3,{N},7) -- graph node position
local InitPoints = Array("InitPoints", opt.float3,{D},8) -- initial points local Constraints = Array("Constraints", opt.float3,{D},9) -- target point local Normals = Array("Normals", opt.float3,{D},10) -- target normal
local G = Graph("G", 11, "v0", {N}, 12, "v1", {N}, 14)
local Gfit = Graph("Gfit", 16, "v0", {N}, 17, "v1", {N}, 18, "v2", {N}, 19, "v3", {N}, 20, "w", {D}, 21)
local Weights = Array("Weights", opt.float4,{D}, 21) -- user constraints
UsePreconditioner(true)
function Dot(a,b) return a:dot(b) end
function Matrix3x3Mul(rot1,rot2,rot3, v) return Vector( rot1(0)v(0)+rot1(1)v(1)+rot1(2)v(2), rot2(0)v(0)+rot2(1)v(1)+rot2(2)v(2), rot3(0)v(0)+rot3(1)v(1)+rot3(2)*v(2)) end
local e_fit = Dot(InitPoints(Gfit.w) + Weights(Gfit.w,0)*Offset(Gfit.v0) - Constraints(Gfit.w),Normals(Gfit.w))
local valid = greatereq(Constraints(0,0,0), -999999.9) Energy(Select(valid, w_fitSqrt*e_fit, 0))
local regCost = (UrShape(G.v1) + Offset(G.v1) - UrShape(G.v0) - Offset(G.v0)) - Matrix3x3Mul(RotRow1(G.v0), RotRow2(G.v0), RotRow3(G.v0), (UrShape(G.v1) - UrShape(G.v0)))
Energy(w_regSqrt*regCost) `
And I got following error
o.t:1954: residual contains image reads from multiple domains stack traceback: [C]: in function 'assert' o.t:1954: in function 'fn' ad.t:510: in function 'visit' ad.t:513: in function 'visit' ad.t:513: in function 'visit' ad.t:516: in function 'visit' o.t:1943: in function 'fn' o.t:639: in function 'MapAndGroupBy' o.t:2023: in function 'toenergyspecs' o.t:2466: in function 'problemSpecFromFile' o.t:868: in function <o.t:862> [C]: in function 'xpcall' o.t:862: in function <o.t:861>
Any leads for fixing this issue ?
Yes.
If we take a look at:
local e_fit = Dot(InitPoints(Gfit.w) + Weights(Gfit.w,0)*Offset(Gfit.v0) - Constraints(Gfit.w),Normals(Gfit.w))
local valid = greatereq(Constraints(0,0,0), -999999.9)
Energy(Select(valid, w_fitSqrt*e_fit, 0))
this energy term is using terms from both the Gfit
domain (all of the e_fit
term) and the dense D
domain (Constraints(0,0,0)
). Constraints(0,0,0)
isn't even well-defined, since the Constraints array is 1D. I think you meant Constraints(Gfit.w)
.
That error message could definitely be improved.
Ok, that error message is not really much to go on. Could you set the verbosity (in the initialization struct) to 2 and attach the log.txt file?
I would be concerned about propagating NaNs through derivatives, can you preprocess your constraints so they are valid numbers less than -999999.9?
In the meantime, there are some things that I see in your energy that could be concerning:
local G = Graph("G", 11,
"v0", {N}, 12,
"v1", {N}, 14)
local Gfit = Graph("Gfit", 16,
Here you skip an index after every node; so you'd need to have dummy pointers at those locations in the problemParams
array in the C code.
"w", {D}, 21)
local Weights = Array("Weights", opt.float4,{D}, 21) -- user constraints
Here you are using the same index to refer to an integer array of length |D| and a float4 array of length |D|, which can't be correct.
I don't know if opt.float3
and opt.float4
are defined; all the examples use opt_float3
and opt_float4
as far as I know.
You still need to index into the channel of Constraints(Gfit.w)
to compare it against the scalar -999999.9.
@Mx7f Thanks for the reply,
Actually, there is a dummy pointer in that location.
The second one was a coding mistake it should be 22 instead of 21.
Thanks for suggesting to use opt_float3. But it was working fine with opt.float3 as well. I got Opt code before releasing from one of your authors and in that example shown like this, I just continued this.
Anyway, it was an issue because of NANs. I will see any problems in the inputs and will report here.
Dear @Mx7f
Thank you so much for the help. After a couple of bug fixing, it started working now. You can close the issue now.
Glad to hear it!
I would like to form a problem in which I want to assign weights for each nodes in the graph. So it is possible to pass those variables in the graph itself?