[ITK Community] [Insight-users] Some error happens : Failed to allocate memory for image
Luis Ibanez
luis.ibanez at kitware.com
Sat Jan 11 12:15:38 EST 2014
Zhq,
It is useful to do the estimation of memory for all the components
of the pipeline.
Let's do this, following the FastMarchingImageFilter.cxx example:
Input Image 512*512*390 = 195 Mb (assuming 16-bits pixel type),
but the reader takes : 400Mb because it keeps a buffer internally.
in the ImageIO class, something that we probably should fix..)
Smoothing filter: will take additional: 400 Mb
Gradient Magnitude ( with its internal helpers ) takes: 800Mb
Sigmoid (since used float pixel type) takes: 400Mb
...etc
A good way to do all this accounting is by using the class
itk::MemoryProbesCollectorBase
as in
itk::MemoryProbesCollectorBase mcollecter;
mcollecter.Start("smoothing");
smoothing->Update();
mcollecter.Stop("smoothing");
mcollecter.Report();
and then do this for every intermediate Update() call to a
filter in the pipeline (you will have to add such calls).
This will give you a summary such as:
reader 400296 = 400Mb
smoothing 799156 = 800Mb
gradient 798860 = 800Mb
sigmoid 399364 = 400Mb
fastMarching 541604 = 540Mb
by the time we count all the memory consumption,
it is:
all 3040580 = 3Gb
To this, one should add the memory allocations of any other
program running in your computer (including the OS).
Please find attached the example:
https://github.com/InsightSoftwareConsortium/ITK/blob/master/Examples/Segmentation/FastMarchingImageFilter.cxx
but, modified with calls to the MemoryProbes collector.
Introducing the memory probes in a similar way your code,
may help to track where the memory consumption is going.
As Jon pointed out, using the ReleaseDataFlagOn() will help,
by releasing intermediate memory as the pipeline progresses.
You may want to add the calls
reader->ReleaseDataFlagOn();
smoothing->ReleaseDataFlagOn();
gradient->ReleaseDataFlagOn();
...etc...
Regards,
Luis
On Fri, Jan 10, 2014 at 4:19 AM, Jon Haitz Legarreta <
jhlegarreta at vicomtech.org> wrote:
> Dear zhq,
> I'd dare to say that evein if your image fits into your memory, you may
> have multiple copies already in memory that prevent your last filter to
> have enough room for it to run.
>
> You may want to check the available meory before that step, or you may try
> releasing the upstream filters' allocated memory turning on the
> ReleaseDataFlag (ReleaseDataFlagOn).
>
> HTH,
> JON HAITZ
>
>
>
> On 10 January 2014 03:26, zhq <15891495523 at 126.com> wrote:
>
>> Dear all :
>>
>> Using the FastMarchingImageFilter to segment a vessel , I meet a
>> error : Failed to allocate memory for image
>>
>> I find the wrong place using try-catch :
>> When the sentence : gradientMagnitude->Update(); is run , the error
>> happens !
>> My computer's memory is 12G , and the volume data is :
>> 512*512*390 . I believe the memory is enough ! And the code has
>> successfully been run once using the other data .
>> Could somebody give me some advices ? Thanks vary much in advance
>> !
>> zhq
>>
>>
>> 来自网易手机号码邮箱了解更多 <http://shouji.163.com>
>>
>> _____________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Kitware offers ITK Training Courses, for more information visit:
>> http://www.kitware.com/products/protraining.php
>>
>> Please keep messages on-topic and check the ITK FAQ at:
>> http://www.itk.org/Wiki/ITK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.itk.org/mailman/listinfo/insight-users
>>
>>
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20140111/7d140af7/attachment-0002.html>
-------------- next part --------------
# This is the root ITK CMakeLists file.
cmake_minimum_required(VERSION 2.4)
if(COMMAND CMAKE_POLICY)
cmake_policy(SET CMP0003 NEW)
endif()
# This project is designed to be built outside the Insight source tree.
project(FastMarching)
# Find ITK.
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
add_executable(FastMarching FastMarching.cxx )
target_link_libraries(FastMarching ${ITK_LIBRARIES})
add_executable(Image3 Image3.cxx )
target_link_libraries(Image3 ${ITK_LIBRARIES})
-------------- next part --------------
A non-text attachment was scrubbed...
Name: FastMarching.cxx
Type: text/x-c++src
Size: 10434 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/community/attachments/20140111/7d140af7/attachment-0002.cxx>
-------------- next part --------------
_____________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php
Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ
Follow this link to subscribe/unsubscribe:
http://www.itk.org/mailman/listinfo/insight-users
More information about the Community
mailing list