# Add custom Layer in the middle of torchvision model

**URL:** <https://discuss.pytorch.org/t/add-custom-layer-in-the-middle-of-torchvision-model/159552>\
**Category:** Uncategorized\
**Created:** [August 19, 2022, 8:56am UTC](https://discuss.pytorch.org/t/add-custom-layer-in-the-middle-of-torchvision-model/159552 "2022-08-19T08:56:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shantanu\_Ghosh](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/shantanu_ghosh/32/24369_2.png) [@Shantanu\_Ghosh](https://discuss.pytorch.org/u/Shantanu_Ghosh)\
**Post date:** [August 19, 2022, 8:56am UTC](https://discuss.pytorch.org/t/add-custom-layer-in-the-middle-of-torchvision-model/159552/1 "2022-08-19T08:56:07Z")

</div>

Hi,  
I have created a resnet model from torchvision like this:  
model = torchvision.models.resnet101(pretrained=pre\_trained)  
Now i want to create a custom layer say conv layer, just after max\_pool as indicated in the picture

To be precise, i want to replace the batch norm layer with a custom metadatanorm as indicated in the paper: “[https://arxiv.org/pdf/2104.09052.pdf](https://arxiv.org/pdf/2104.09052.pdf)”

 ![Screen Shot 2022-08-19 at 4.52.37 AM](https://discuss.pytorch.org/uploads/default/original/3X/a/8/a8b1f2480a24d868b642b4a186c27fa5e5eda28d.png)

---

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [August 19, 2022, 8:58am UTC](https://discuss.pytorch.org/t/add-custom-layer-in-the-middle-of-torchvision-model/159552/2 "2022-08-19T08:58:52Z")

</div>

You could replace the layer with an `nn.Sequential` block containing the original layer as well as your new layer as described [here](https://discuss.pytorch.org/t/adding-intermediary-layers-to-a-pre-trained-bert-model/158825/2).
