[ITK] Bspline registration with Mutual Information v4 : memory concern

Timothee Evain tevain at telecom-paristech.fr
Thu Sep 8 03:11:46 EDT 2016


Yes, that sounds like a good idea, I'll put that into a block. 

Thanks,

Tim

----- Mail original -----
De: "Dženan Zukić" <dzenanz at gmail.com>
À: "Timothee Evain" <tevain at telecom-paristech.fr>
Cc: community at itk.org
Envoyé: Mercredi 7 Septembre 2016 23:20:14
Objet: Re: [ITK] Bspline registration with Mutual Information v4 : memory concern

Hi Tim,

the memory is released in destructor, and the easiest way to trigger it is
to do registration in a function or an unnamed block (example attached).

Regards,
Dženan

On Tue, Sep 6, 2016 at 12:34 PM, Timothee Evain <tevain at telecom-paristech.fr
> wrote:

> Dženan,
>
> Your fix works like a charm. The process take now ~4Gb(in release).
> I observed that this memory isn't released after the end of the
> registration process. Is that intended ?
> Also, to write it down for potential users who want to patch their 4.10
> version or earlier, there is a small macro to change (ITK_CONSTEXPR_VAR
> into ITK_CONSTEXPR) since master branch had a modification about macros.
>
> Anyway, many thanks to you for the swift help ! :)
>
> Tim
>
>
>
> ----- Mail original -----
> De: "Dženan Zukić" <dzenanz at gmail.com>
> À: "Timothee Evain" <tevain at telecom-paristech.fr>
> Cc: community at itk.org
> Envoyé: Mardi 6 Septembre 2016 17:43:49
> Objet: Re: [ITK] Bspline registration with Mutual Information v4 : memory
> concern
>
> Hi Tim,
>
> I did some memory profiling using 4.9.0 (which also exhibits the problem).
> With current code, the MattesMutualInformationImageToImageMetricv4::
> DerivativeBufferManager::DoubleBufferSize() increases the buffer to huge
> sizes, because 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.
>
> 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.
>
> Can you review the proposed fix?
> http://review.source.kitware.com/21501
>
> Regards,
> Dženan
>
> On Tue, Sep 6, 2016 at 5:32 AM, Timothee Evain <
> tevain at telecom-paristech.fr>
> wrote:
>
> > Hi Dženan,
> >
> > Sure!
> > You could find here an archive https://www.dropbox.com/s/
> 9scgn9if39i4a1x/
> > V4RegistrationMemoryLeak.tar?dl=0
> > It contains:
> > -Fixed and moving images in mhd format
> > -The binary (for windows)
> > -The source code with its CMakeLists if you want to compile for another
> OS
> >
> > Thanks,
> >
> > Tim
> >
> >
> > ----- Mail original -----
> > De: "Dženan Zukić" <dzenanz at gmail.com>
> > À: "Timothee Evain" <tevain at telecom-paristech.fr>
> > Cc: community at itk.org
> > Envoyé: Lundi 5 Septembre 2016 20:54:29
> > Objet: Re: [ITK] Bspline registration with Mutual Information v4 : memory
> > concern
> >
> > Hi Tim,
> >
> > can you turn this snippet into a runnable example which reproduces the
> > memory leak?
> >
> > Regards,
> > Dženan
> >
> > On Mon, Sep 5, 2016 at 12:27 PM, Timothee Evain <
> > tevain at telecom-paristech.fr
> > > wrote:
> >
> > > Hello everyone,
> > >
> > > I'm trying a Bspline registration based on the Mutual Information
> metric
> > > (v4) and I'm facing a memory problem.
> > > When running the registration, the memory usage skyrockets in a second
> > > until freezing the PC by lack of memory.
> > > I don't know why : this doesn't happen when I'm switching to another
> > > metric (e.g. Correlation), the images aren't that big (~400k voxels)
> and
> > a
> > > previous rigid registration phase behaved correctly.
> > > Here is my code snippet, what am I doing wrong ? (Image overlap had
> been
> > > ensured)
> > >
> > >    typedef itk::Image<float,3> ImageTypef;
> > >
> > >    itk::ImageRegistrationMethodv4<ImageTypef,ImageTypef>::Pointer
> > > WarpHelper=
> > >       itk::ImageRegistrationMethodv4<ImageTypef,ImageTypef>::New();
> > >    itk::MattesMutualInformationImageToImageMetricv4<ImageTypef,
> > ImageTypef>::Pointer
> > > MIMetrics=
> > >       itk::MattesMutualInformationImageToImageMetricv4<ImageTypef,
> > > ImageTypef>::New();
> > >    itk::BSplineTransform<double,3,3>::Pointer BSplineTransform=
> > >       itk::BSplineTransform<double,3,3>::New();
> > >    itk::LBFGSOptimizerv4::Pointer Optimizer=
> > >       itk::LBFGSOptimizerv4::New();
> > >
> > >    MIMetrics->SetNumberOfHistogramBins(50);
> > >    MIMetrics->SetUseMovingImageGradientFilter(false);
> > >    MIMetrics->SetUseFixedImageGradientFilter(false);
> > >    MIMetrics->SetUseFixedSampledPointSet(false);
> > >    MIMetrics->SetVirtualDomainFromImage(TestIm);
> > >
> > >
> > >    WarpHelper->SetFixedImage(TestIm);
> > >    WarpHelper->SetMetricSamplingPercentage(0.002);
> > >    WarpHelper->SetMovingImage(MovIm);
> > >    WarpHelper->SetMetric(MIMetrics);
> > >    //WarpHelper->SetMetricSamplingStrategy(WarpHelper->RANDOM);
> > >    WarpHelper->InPlaceOn();
> > >    WarpHelper->SetInitialTransform(BSplineTransform);
> > >    WarpHelper->SetOptimizer(Optimizer);
> > >
> > >    itk::Array<double> ShrinkFactorPerLevel(1);
> > >    ShrinkFactorPerLevel[0]=1;
> > >    itk::Array<double> SmoothSigmaPerLevel(1);
> > >    SmoothSigmaPerLevel[0]=0;
> > >    WarpHelper->SetNumberOfLevels(1);
> > >    WarpHelper->SetSmoothingSigmasPerLevel(SmoothSigmaPerLevel);
> > >    WarpHelper->SetShrinkFactorsPerLevel(ShrinkFactorPerLevel);
> > >
> > >    /* ----- Initialize the Bspline Transform ----- */
> > >    BSplineTransform->SetTransformDomainOrigin(TestIm->GetOrigin());
> > >    BSplineTransform->SetTransformDomainDirection(
> > TestIm->GetDirection());
> > >
> > >    itk::Vector<double,3> PhysicalDim;
> > >    for (int dim = 0; dim < 3; dim++)
> > >    {
> > >       PhysicalDim=(TestIm->GetSpacing()[dim])*float((TestIm->
> > > GetLargestPossibleRegion().GetSize()[dim])-1);
> > >    }
> > >    BSplineTransform->SetTransformDomainPhysicalDime
> nsions(PhysicalDim);
> > >
> > >    itk::Size<3> meshSize;
> > >    meshSize.Fill(10-3);// NbGridNodesEachDim-SplineOrder
> > >    BSplineTransform->SetTransformDomainMeshSize(meshSize);
> > >
> > >    BSplineTransform->SetIdentity();
> > >
> > >    /* ----- Optimizer setup ----- */
> > >    itk::Array<double> ScaleBspline(BSplineTransform-
> > > >GetNumberOfParameters());
> > >    ScaleBspline.fill(1);
> > >
> > >    Optimizer->SetLineSearchAccuracy(0.9);
> > >    Optimizer->SetDefaultStepLength(1.5);
> > >    Optimizer->TraceOn();
> > >    Optimizer->SetGradientConvergenceTolerance(1e-3);
> > >    Optimizer->SetMaximumNumberOfFunctionEvaluations(20);
> > >    Optimizer->SetDoEstimateScales(false);
> > >    Optimizer->SetScales(ScaleBspline);
> > >
> > >
> > >    try
> > >    {
> > >       WarpHelper->Update();
> > >    }
> > >    catch (itk::ExceptionObject &err)
> > >    {
> > >       std::cerr<<err;
> > >       return 0;
> > >    }
> > >
> > > Thanks,
> > >
> > > Tim
> > > _______________________________________________
> > > Community mailing list
> > > Community at itk.org
> > > http://public.kitware.com/mailman/listinfo/community
> > >
> >
>


More information about the Community mailing list