# KeyError: 'ITKSmoothing' when initializing RegularStepGradientDescentOptimizerv4

**URL:** https://discourse.itk.org/t/keyerror-itksmoothing-when-initializing-regularstepgradientdescentoptimizerv4/3973
**Category:** Engineering
**Created:** [March 22, 2021, 12:30pm UTC](https://discourse.itk.org/t/keyerror-itksmoothing-when-initializing-regularstepgradientdescentoptimizerv4/3973 "2021-03-22T12:30:17Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Soren\_Christensen](https://discourse.itk.org/user_avatar/discourse.itk.org/soren_christensen/32/1710_2.png) [@Soren\_Christensen](https://discourse.itk.org/u/Soren_Christensen)
#### Post date: [March 22, 2021, 12:30pm UTC](https://discourse.itk.org/t/keyerror-itksmoothing-when-initializing-regularstepgradientdescentoptimizerv4/3973/1 "2021-03-22T12:30:17Z")

</div>

Hi,  
I have a fresh pip install of 5.1.1 and get this error when creating an ImageRegistrationMethodv4

```auto
 object:
    registration = itk.ImageRegistrationMethodv4.REGv4F3F3.New(FixedImage=fixed,
                                                               MovingImage=moving,
                                                               Metric=metric,
                                                               Optimizer=optimizer,
                                                               InitialTransform=identityTransform)

```

My metric is using raycastinterpolater as interpolater I saw another post from last year with the same error message for the SiddonJacobRayCastInterpolateImageFunction filter but there were no replies to that post.  
Any ideas appreciated!  
Thanks!  
Soren

```nohighlight
Traceback (most recent call last):
  File "/home/sorenc/CODE/reg/reg_sandbox.py", line 45, in <module>
    register(itk_image,dsa_itk_img,beam_location.tolist())
  File "/register.py", line 14, in register
    optimizer = itk.RegularStepGradientDescentOptimizerv4.New(
  File "/home/sorenc/.virtualenvs/sitk/lib/python3.6/site-packages/itkLazy.py", line 52, in __getattribute__
    itkBase.LoadModule(module, namespace)
  File "/home/sorenc/.virtualenvs/sitk/lib/python3.6/site-packages/itkBase.py", line 91, in LoadModule
    LoadModule(dep, namespace)
  File "/home/sorenc/.virtualenvs/sitk/lib/python3.6/site-packages/itkBase.py", line 91, in LoadModule
    LoadModule(dep, namespace)
  File "/home/sorenc/.virtualenvs/sitk/lib/python3.6/site-packages/itkBase.py", line 87, in LoadModule
    data = module_data[name]
KeyError: 'ITKSmoothing'

```

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [March 22, 2021, 7:12pm UTC](https://discourse.itk.org/t/keyerror-itksmoothing-when-initializing-regularstepgradientdescentoptimizerv4/3973/2 "2021-03-22T19:12:14Z")

</div>

Does the error go away if you import ITK like this:

```auto
# disable lazy loading first and then import itk
import itkConfig
itkConfig.LazyLoading = False
import itk

```

---

<div class="post-metadata">

### Author: ![Soren\_Christensen](https://discourse.itk.org/user_avatar/discourse.itk.org/soren_christensen/32/1710_2.png) [@Soren\_Christensen](https://discourse.itk.org/u/Soren_Christensen)
#### Post date: [March 22, 2021, 7:47pm UTC](https://discourse.itk.org/t/keyerror-itksmoothing-when-initializing-regularstepgradientdescentoptimizerv4/3973/3 "2021-03-22T19:47:21Z")

</div>

Thank you Dzenanz!  
Yes, that takes care of it.

Soren

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [March 23, 2021, 11:56pm UTC](https://discourse.itk.org/t/keyerror-itksmoothing-when-initializing-regularstepgradientdescentoptimizerv4/3973/4 "2021-03-23T23:56:13Z")

</div>

> [@Soren\_Christensen](#):
>
> ```auto
> registration = itk.ImageRegistrationMethodv4.REGv4F3F3.New(FixedImage=fixed,
> MovingImage=moving,
> Metric=metric,
> Optimizer=optimizer,
> InitialTransform=identityTransform)
> 
> ```

We can avoid the error and automatically get the correct filter type by omitting `.REGv4F3F3` (tested with `itk-5.2rc3`):

```auto
registration = itk.ImageRegistrationMethodv4.New(fixed_image=fixed_image,
    moving_image=moving_image,
    metric=metric,
    optimizer=optimizer,
    initial_transform=identityTransform)

```

A full example with the modern, Pythonic `itk` style:

> <https://github.com/InsightSoftwareConsortium/ITK/pull/2436>

---

<div class="post-metadata">

### Author: ![Soren\_Christensen](https://discourse.itk.org/user_avatar/discourse.itk.org/soren_christensen/32/1710_2.png) [@Soren\_Christensen](https://discourse.itk.org/u/Soren_Christensen)
#### Post date: [April 2, 2021, 3:07pm UTC](https://discourse.itk.org/t/keyerror-itksmoothing-when-initializing-regularstepgradientdescentoptimizerv4/3973/6 "2021-04-02T15:07:34Z")

</div>

Thanks!  
I upgraded to 5.2 but I seem to still have issues with the types:  
itk. **version**  
‘5.2.0’  
fixed\_image  
\<itk.itkImagePython.itkImageF3; proxy of \<Swig Object of type ‘ **itkImageF3** \*’ at 0x7f15a6bbe3f0\> \>  
moving\_image  
\<itk.itkImagePython.itkImageF3; proxy of \<Swig Object of type ‘ **itkImageF3** \*’ at 0x7f15b8ed2f30\> \>  
registration = itk.ImageRegistrationMethodv4.New(fixed\_image=fixed\_image,  
moving\_image=moving\_image,)  
TypeError: in method ‘itkImageRegistrationMethodv4REGv4F2F2\_SetFixedImage’, argument 2 of type ‘itkImageF2 const \*’  
Additional information:  
Wrong number or type of arguments for overloaded function ‘ **itkImageRegistrationMethodv4REGv4F2F2\_SetFixedImage** ’.  
Possible C/C++ prototypes are:  
itkImageRegistrationMethodv4REGv4F2F2::SetFixedImage(itkImageF2 const \*)  
itkImageRegistrationMethodv4REGv4F2F2::SetFixedImage(unsigned long,itkImageF2 const \*)

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [April 7, 2021, 1:54am UTC](https://discourse.itk.org/t/keyerror-itksmoothing-when-initializing-regularstepgradientdescentoptimizerv4/3973/7 "2021-04-07T01:54:56Z")

</div>

What code was used?

> **itkImageF3**

> itkImageF2

it appears that we are trying to use 3D images in a 2D image filter.
