Hi,
I would like to share with you what I’ve noticed concerning RAM consumption by using OTB through python. Here a simple a sample code :
def memory_usage_psutil():
import resource
return resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1000.0
images = ["raster1.tif", "raster2.tif", ..., "rasterN.tif"]
for image in images:
bandMath = otb.Registry.CreateApplication("BandMath")
bandMath.SetParameterStringList("il", [image])
bandMath.SetParameterString("out", output)
bandMath.SetParameterString("exp", "im1b1 + 1")
print("Memory usage {} MB".format(memory_usage_psutil()))
bandMath.ExecuteAndWriteOutput()
bandMath = None
If you are running this kind of code, your memory consumption will raise until reach your limit (your code could crash or be kill).
The only solution I’ve found is to wrap ExecuteAndWriteOutput() thanks multiprocessing.Process() as in otb_memory.py (2.6 KB)
I think it is related to python and it’s garbage collector behavior. Is someone know a better solution to clean-up RAM ?
python otb_memory.py -h
highlight otb python bindings RAM usage
optional arguments:
-h, --help show this help message and exit
-in INPUT_IMG
-loop NB_LOOP number of loop
-wrap WRAP wrap ExecuteAndWriteOutput() ?
-output OUTPUT output path
as input, you could use T32TNT_20180407T102019_SCL_20m.tif (354.9 KB)
in advance, thanks