<div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">Hi Tim,</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">I did some memory profiling using 4.9.0 (which also exhibits the problem). With current code, the MattesMutualInformationImageTo<wbr>ImageMetricv4::<wbr>DerivativeBufferManager::<wbr>DoubleBufferSize() increases the buffer to huge sizes, because <wbr>CheckAndReduceIfNecessary() fails to acquire the synchronization lock. The reason is probably that memory-bound combining the PDF derivatives is slower than its CPU-bound calculation.</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">In release mode, the buffers grew to 50GB before I killed the process. In debug mode, they only grow to around 5GB, again probably because the calculation speed is on par with PDF combining due to debug overhead.</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">Can you review the proposed fix?</div><div class="gmail_default"><font face="verdana, sans-serif"><a href="http://review.source.kitware.com/21501">http://review.source.kitware.com/21501</a></font><br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">Regards,</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">Dženan</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 6, 2016 at 5:32 AM, Timothee Evain <span dir="ltr"><<a href="mailto:tevain@telecom-paristech.fr" target="_blank">tevain@telecom-paristech.fr</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Dženan,<br>
<br>
Sure!<br>
You could find here an archive <a href="https://www.dropbox.com/s/9scgn9if39i4a1x/V4RegistrationMemoryLeak.tar?dl=0" rel="noreferrer" target="_blank">https://www.dropbox.com/s/<wbr>9scgn9if39i4a1x/<wbr>V4RegistrationMemoryLeak.tar?<wbr>dl=0</a><br>
It contains:<br>
-Fixed and moving images in mhd format<br>
-The binary (for windows)<br>
-The source code with its CMakeLists if you want to compile for another OS<br>
<br>
Thanks,<br>
<br>
Tim<br>
<br>
<br>
----- Mail original -----<br>
De: "Dženan Zukić" <<a href="mailto:dzenanz@gmail.com">dzenanz@gmail.com</a>><br>
À: "Timothee Evain" <<a href="mailto:tevain@telecom-paristech.fr">tevain@telecom-paristech.fr</a>><br>
Cc: <a href="mailto:community@itk.org">community@itk.org</a><br>
Envoyé: Lundi 5 Septembre 2016 20:54:29<br>
Objet: Re: [ITK] Bspline registration with Mutual Information v4 : memory concern<br>
<div class="HOEnZb"><div class="h5"><br>
Hi Tim,<br>
<br>
can you turn this snippet into a runnable example which reproduces the<br>
memory leak?<br>
<br>
Regards,<br>
Dženan<br>
<br>
On Mon, Sep 5, 2016 at 12:27 PM, Timothee Evain <<a href="mailto:tevain@telecom-paristech.fr">tevain@telecom-paristech.fr</a><br>
> wrote:<br>
<br>
> Hello everyone,<br>
><br>
> I'm trying a Bspline registration based on the Mutual Information metric<br>
> (v4) and I'm facing a memory problem.<br>
> When running the registration, the memory usage skyrockets in a second<br>
> until freezing the PC by lack of memory.<br>
> I don't know why : this doesn't happen when I'm switching to another<br>
> metric (e.g. Correlation), the images aren't that big (~400k voxels) and a<br>
> previous rigid registration phase behaved correctly.<br>
> Here is my code snippet, what am I doing wrong ? (Image overlap had been<br>
> ensured)<br>
><br>
>    typedef itk::Image<float,3> ImageTypef;<br>
><br>
>    itk::<wbr>ImageRegistrationMethodv4<<wbr>ImageTypef,ImageTypef>::<wbr>Pointer<br>
> WarpHelper=<br>
>       itk::<wbr>ImageRegistrationMethodv4<<wbr>ImageTypef,ImageTypef>::New();<br>
>    itk::<wbr>MattesMutualInformationImageTo<wbr>ImageMetricv4<ImageTypef,<wbr>ImageTypef>::Pointer<br>
> MIMetrics=<br>
>       itk::<wbr>MattesMutualInformationImageTo<wbr>ImageMetricv4<ImageTypef,<br>
> ImageTypef>::New();<br>
>    itk::BSplineTransform<double,<wbr>3,3>::Pointer BSplineTransform=<br>
>       itk::BSplineTransform<double,<wbr>3,3>::New();<br>
>    itk::LBFGSOptimizerv4::Pointer Optimizer=<br>
>       itk::LBFGSOptimizerv4::New();<br>
><br>
>    MIMetrics-><wbr>SetNumberOfHistogramBins(50);<br>
>    MIMetrics-><wbr>SetUseMovingImageGradientFilte<wbr>r(false);<br>
>    MIMetrics-><wbr>SetUseFixedImageGradientFilter<wbr>(false);<br>
>    MIMetrics-><wbr>SetUseFixedSampledPointSet(<wbr>false);<br>
>    MIMetrics-><wbr>SetVirtualDomainFromImage(<wbr>TestIm);<br>
><br>
><br>
>    WarpHelper->SetFixedImage(<wbr>TestIm);<br>
>    WarpHelper-><wbr>SetMetricSamplingPercentage(0.<wbr>002);<br>
>    WarpHelper->SetMovingImage(<wbr>MovIm);<br>
>    WarpHelper->SetMetric(<wbr>MIMetrics);<br>
>    //WarpHelper-><wbr>SetMetricSamplingStrategy(<wbr>WarpHelper->RANDOM);<br>
>    WarpHelper->InPlaceOn();<br>
>    WarpHelper-><wbr>SetInitialTransform(<wbr>BSplineTransform);<br>
>    WarpHelper->SetOptimizer(<wbr>Optimizer);<br>
><br>
>    itk::Array<double> ShrinkFactorPerLevel(1);<br>
>    ShrinkFactorPerLevel[0]=1;<br>
>    itk::Array<double> SmoothSigmaPerLevel(1);<br>
>    SmoothSigmaPerLevel[0]=0;<br>
>    WarpHelper->SetNumberOfLevels(<wbr>1);<br>
>    WarpHelper-><wbr>SetSmoothingSigmasPerLevel(<wbr>SmoothSigmaPerLevel);<br>
>    WarpHelper-><wbr>SetShrinkFactorsPerLevel(<wbr>ShrinkFactorPerLevel);<br>
><br>
>    /* ----- Initialize the Bspline Transform ----- */<br>
>    BSplineTransform-><wbr>SetTransformDomainOrigin(<wbr>TestIm->GetOrigin());<br>
>    BSplineTransform-><wbr>SetTransformDomainDirection(<wbr>TestIm->GetDirection());<br>
><br>
>    itk::Vector<double,3> PhysicalDim;<br>
>    for (int dim = 0; dim < 3; dim++)<br>
>    {<br>
>       PhysicalDim=(TestIm-><wbr>GetSpacing()[dim])*float((<wbr>TestIm-><br>
> GetLargestPossibleRegion().<wbr>GetSize()[dim])-1);<br>
>    }<br>
>    BSplineTransform-><wbr>SetTransformDomainPhysicalDime<wbr>nsions(PhysicalDim);<br>
><br>
>    itk::Size<3> meshSize;<br>
>    meshSize.Fill(10-3);// NbGridNodesEachDim-SplineOrder<br>
>    BSplineTransform-><wbr>SetTransformDomainMeshSize(<wbr>meshSize);<br>
><br>
>    BSplineTransform->SetIdentity(<wbr>);<br>
><br>
>    /* ----- Optimizer setup ----- */<br>
>    itk::Array<double> ScaleBspline(BSplineTransform-<br>
> >GetNumberOfParameters());<br>
>    ScaleBspline.fill(1);<br>
><br>
>    Optimizer-><wbr>SetLineSearchAccuracy(0.9);<br>
>    Optimizer-><wbr>SetDefaultStepLength(1.5);<br>
>    Optimizer->TraceOn();<br>
>    Optimizer-><wbr>SetGradientConvergenceToleranc<wbr>e(1e-3);<br>
>    Optimizer-><wbr>SetMaximumNumberOfFunctionEval<wbr>uations(20);<br>
>    Optimizer-><wbr>SetDoEstimateScales(false);<br>
>    Optimizer->SetScales(<wbr>ScaleBspline);<br>
><br>
><br>
>    try<br>
>    {<br>
>       WarpHelper->Update();<br>
>    }<br>
>    catch (itk::ExceptionObject &err)<br>
>    {<br>
>       std::cerr<<err;<br>
>       return 0;<br>
>    }<br>
><br>
> Thanks,<br>
><br>
> Tim<br>
> ______________________________<wbr>_________________<br>
> Community mailing list<br>
> <a href="mailto:Community@itk.org">Community@itk.org</a><br>
> <a href="http://public.kitware.com/mailman/listinfo/community" rel="noreferrer" target="_blank">http://public.kitware.com/<wbr>mailman/listinfo/community</a><br>
><br>
</div></div></blockquote></div><br></div>