Open gerwang opened 5 years ago
I found that the number of linear iterations and whether to use preconditioner means a lot to the convergence. Reducing nLinearIterations from 10 to 3 and disable preconditioner can make Opt work on the sfs example.
What version of terra are you using?
This is a problem, the default parameters should work fine. For the LM solver, what happens if you set the residual_reset_period to 1?
Thanks for your reply. My terra is cloned from its github master branch, built from source with LLVM 6.0.1 and VS2015. I tried setting residual_reset_period to 1, but OptLM still reverts every iteration.
virtual void combinedSolveInit() override {
m_solverParams.set("nIterations", &m_combinedSolverParameters.nonLinearIter);
m_solverParams.set("lIterations", &m_combinedSolverParameters.linearIter);
m_solverParams.set("residual_reset_period", &m_combinedSolverParameters.residual_reset_period);
}
...
struct CombinedSolverParameters {
bool useCUDA = false;
bool useOpt = true;
bool useOptLM = false;
bool useCeres = false;
bool earlyOut = false;
unsigned int numIter = 1;
unsigned int nonLinearIter = 3;
unsigned int linearIter = 200;
unsigned int patchIter = 32;
bool profileSolve = true;
bool optDoublePrecision = false;
float residual_reset_period = 1;
};
And here is the output.
Saving targetDepth 640x480x1
Num Active Unknowns: 192162
1 weight
100 fit
100 reg
Saving targetIntensity.png 640x480x1
Saving targetDepth 640x480x1
Saving maskEdgeMap.png 640x960x1
Saving maskEdgeMap 640x960x1
Num Active Unknowns: 192162
1 weight
100 fit
100 reg
Saving sfsInitDepth.ply 640x480x1
warning: Linking two modules of different data layouts: 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0/nvvm/libdevice/libdevice.10.bc' is '' whereas 'external' is 'e-m:w-i64:64-f80:128-n8:16:32:64-S128'
Using Opt v0.2.2
nUnknowns = 307200
nResiduals = 0 + 307200 * 6
nnz = 0 + 307200 * 26
compile time: 4.1668634786038
problem plan complete
GPU memory usage: used = 2142.637501, free = 9121.362499 MB, total = 11264.000000 MB
22524.102539063
Solving
//////////// (Opt(LM)) ///////////////
cost=175.765216
model_cost=22708265.595070
model_cost_change=-22708089.829853
trust_region_radius=5000.000000
REVERT
cost=175.765216
model_cost=22708265.612590
model_cost_change=-22708089.847374
trust_region_radius=1250.000000
REVERT
cost=175.765216
model_cost=22708265.717455
model_cost_change=-22708089.952239
trust_region_radius=156.250000
REVERT
cost=175.765216
model_cost=22708266.675104
model_cost_change=-22708090.909887
trust_region_radius=9.765625
REVERT
cost=175.765216
model_cost=22708278.340151
model_cost_change=-22708102.574935
trust_region_radius=0.305176
REVERT
cost=175.765216
model_cost=22708241.150293
model_cost_change=-22708065.385077
trust_region_radius=0.004768
REVERT
zeta=1.6423318817270691e-005, breaking at iteration: 2
cost=175.765216
model_cost=22708195.599687
model_cost_change=-22708019.834471
trust_region_radius=0.000037
REVERT
zeta=1.0141227687073646e-009, breaking at iteration: 2
cost=175.765216
model_cost=22708194.554962
model_cost_change=-22708018.789745
trust_region_radius=0.000000
REVERT
zeta=1.4936715456057726e-014, breaking at iteration: 2
cost=175.765216
model_cost=22708194.546709
model_cost_change=-22708018.781492
trust_region_radius=0.000000
REVERT
zeta=-3.6332546053598101e-015, breaking at iteration: 2
cost=175.765216
model_cost=22708194.546677
model_cost_change=-22708018.781460
trust_region_radius=0.000000
REVERT
zeta=0, breaking at iteration: 2
cost=175.765216
model_cost=22708194.546676
model_cost_change=-22708018.781460
trust_region_radius=0.000000
REVERT
zeta=-4.0369495604115869e-016, breaking at iteration: 2
cost=175.765216
model_cost=22708194.546676
model_cost_change=-22708018.781460
trust_region_radius=0.000000
REVERT
zeta=0, breaking at iteration: 2
cost=175.765216
model_cost=22708194.546676
model_cost_change=-22708018.781460
trust_region_radius=0.000000
REVERT
zeta=4.036949560411584e-016, breaking at iteration: 2
cost=175.765216
model_cost=22708194.546676
model_cost_change=-22708018.781460
trust_region_radius=0.000000
REVERT
zeta=1.2110848681234751e-015, breaking at iteration: 2
cost=175.765216
model_cost=22708194.546676
model_cost_change=-22708018.781460
trust_region_radius=0.000000
Trust_region_radius is less than the min, exiting
final cost=175.765216
--------------------------------------------------------
Kernel | Count | Total | Average
----------------------+----------+-----------+----------
----------------------+----------+-----------+----------
overall | 1 | 313.555ms| 313.5549ms
----------------------+----------+-----------+----------
precompute_W_H | 30 | 26.998ms| 0.8999ms
----------------------+----------+-----------+----------
computeCost_W_H | 16 | 6.909ms| 0.4318ms
----------------------+----------+-----------+----------
PCGInit1_W_H | 15 | 31.470ms| 2.0980ms
----------------------+----------+-----------+----------
PCGSaveSSq_W_H | 1 | 1.077ms| 1.0773ms
----------------------+----------+-----------+----------
PCGComputeCtC_W_H | 15 | 16.487ms| 1.0991ms
----------------------+----------+-----------+----------
PCGFinalizeDiagonal_W_H | 15 | 16.556ms| 1.1037ms
----------------------+----------+-----------+----------
PCGStep1_W_H | 36 | 41.774ms| 1.1604ms
----------------------+----------+-----------+----------
PCGStep2_W_H | 36 | 39.746ms| 1.1041ms
----------------------+----------+-----------+----------
PCGStep3_W_H | 36 | 37.802ms| 1.0501ms
----------------------+----------+-----------+----------
computeModelCost_W_H | 15 | 7.849ms| 0.5233ms
----------------------+----------+-----------+----------
savePreviousUnknowns_W_H | 15 | 15.594ms| 1.0396ms
----------------------+----------+-----------+----------
PCGLinearUpdate_W_H | 15 | 15.675ms| 1.0450ms
----------------------+----------+-----------+----------
revertUpdate_W_H | 15 | 15.611ms| 1.0407ms
--------------------------------------------------------
TIMING 313.554932 31.469507 41.774025
Per-iter times ms (nonlinear,linear): 119.2413 119.3221
===Shape From Shading===
**Final Costs**
Opt GN,Opt LM,CERES
,1.75765216273377006928e+02,
Solved
About to save
Saving sfsOutput 640x480x1
Saving sfsOutput.ply 640x480x1
Save
GPU memory usage: used = 2117.512501, free = 9146.487499 MB, total = 11264.000000 MB
plan free complete
GPU memory usage: used = 2117.512501, free = 9146.487499 MB, total = 11264.000000 MB
Also I don't understand why when I enable preconditioner or increase nLinearIteration, the loss increases and solution drifts. Is there anything underlining mathematical principle of PCG algorithm?
Using Opt with LLVM 6.0.1 and CUDA 10.0 on Windows 10. Other examples work fine, but when running shape from shading exmple, OptGN method cannot converge and cost rises. OptLM reverts every iteration, so the final solution remains identical to the initial one. However, CUDA method and ceres method works fine.
Can anyone please explain why Opt fails on sfs examples? If I plan to solve sfs problem with Opt, can I? What should I be careful of?
Here is my screenshot: