itk-python weird time consuming

Hi teams,

I tried some itk.filter both in cpp and python.
The cpp version is ok but python version is quite time consuming(for New statement)

cost 15 second for this code

itk.RescaleIntensityImageFilter[self.inputType, self.outputType].New()

cost 4 second for this code


Is there any ways to fix it or avoid it?

Thank you!

Best regards

Hi @HiunIce ,

Welcome to the ITK community! :sun_with_face:

The delay is related to loading library dependencies in Python. At the beginning of your Python session, call itk.force_load() (will take some time the first time), and subsequent calls to .New() will be faster. Due to OS caching, subsequent calls even after exiting an interpreter will be faster.

Hope this helps,

Thanks your reply, it runs faster after the first calling.
But my interpreter seems do not save any cache for it, when I rerun the script(ctrl+F10 in pycharm), it will runs force_load() again.
I am using pycharm for windows10.

Thank you.


PyCharm does some additional processing to try to understand the code. @hjmjohnson @kjweimer made contributions in the upcoming 5.3rc4.post1 release that improves type annotations for IDE’s like PyCharm. I do not know whether it will improve PyCharm’s preprocessing times, but you may try to see if improves your experience.

Thanks a lot!

1 Like