# New layer in an existing pretrained model

**URL:** <https://discuss.pytorch.org/t/new-layer-in-an-existing-pretrained-model/22436>\
**Category:** Uncategorized\
**Created:** [August 4, 2018, 3:09pm UTC](https://discuss.pytorch.org/t/new-layer-in-an-existing-pretrained-model/22436 "2018-08-04T15:09:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gilsho](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@gilsho](https://discuss.pytorch.org/u/gilsho)\
**Post date:** [August 4, 2018, 3:09pm UTC](https://discuss.pytorch.org/t/new-layer-in-an-existing-pretrained-model/22436/1 "2018-08-04T15:09:00Z")

</div>

Hello,

I would like to add to an existing model, like AlexNet, additional layers.  
My custom layer only changes the activation values, and does not affect any dimension.  
My layer includes a 2D convolution but with constant weights (I set requires\_grad=False).

The thing is that I’m having a hard time loading the pretrained values.  
I’m looking at model.state\_dict() and I can see that my layer affects the state\_dict, in contrast to pooling or ReLU that doesn’t appear in it.

How do I force my layer to not change the original state\_dict (like pooling or activation functions)?

Thanks.

---

<div class="post-metadata">

**Author:** ![JuanFMontesinos](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/juanfmontesinos/32/76115_2.png) [@JuanFMontesinos](https://discuss.pytorch.org/u/JuanFMontesinos)\
**Post date:** [August 4, 2018, 3:29pm UTC](https://discuss.pytorch.org/t/new-layer-in-an-existing-pretrained-model/22436/2 "2018-08-04T15:29:25Z")

</div>

I don’t understand the question.  
Ofc your need layer changes state\_dic, it has to appear there.

If the problem is you are having troubles loading the pretrained model try to use the argument `strict=false` when loading the pretrained model. This allows you to load weights without having the exact order. Just use a singular name for your new layers not get error while loading.

---

<div class="post-metadata">

**Author:** ![gilsho](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@gilsho](https://discuss.pytorch.org/u/gilsho)\
**Post date:** [August 4, 2018, 3:44pm UTC](https://discuss.pytorch.org/t/new-layer-in-an-existing-pretrained-model/22436/3 "2018-08-04T15:44:04Z")

</div>

Unfortunately, because AlexNet is implemented with _sequential_ any additional layer changes the layers names, so `strict=false` doesn’t work.

I can manually remove and rename keys from the state\_dict. I wonder if there’s a better way.
