# Replacing convs modules with custom convs, then NotImplementedError

**URL:** <https://discuss.pytorch.org/t/replacing-convs-modules-with-custom-convs-then-notimplementederror/17736>\
**Category:** autograd\
**Created:** [May 8, 2018, 12:36pm UTC](https://discuss.pytorch.org/t/replacing-convs-modules-with-custom-convs-then-notimplementederror/17736 "2018-05-08T12:36:31Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![IlyaOvodov](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/i/bc8723/32.png) [@IlyaOvodov](https://discuss.pytorch.org/u/IlyaOvodov)\
**Post date:** [February 20, 2019, 3:53pm UTC](https://discuss.pytorch.org/t/replacing-convs-modules-with-custom-convs-then-notimplementederror/17736/3 "2019-02-20T15:53:23Z")

</div>

For those who seek a solution and not snobbish mentoring:

```auto
def replace_bn(m, name):
    for attr_str in dir(m):
        target_attr = getattr(m, attr_str)
        if type(target_attr) == torch.nn.BatchNorm2d:
            print('replaced: ', name, attr_str)
            setattr(m, attr_str, SynchronizedBatchNorm2d(target_attr.num_features, target_attr.eps, target_attr.momentum, target_attr.affine))
    for n, ch in m.named_children():
        replace_bn(ch, n)
        
replace_bn(net, "net")

```

---

_[View the full topic](https://discuss.pytorch.org/t/replacing-convs-modules-with-custom-convs-then-notimplementederror/17736)._
