# Use \`ReplaceAll\` to modify a network layer ?

**URL:** <https://community.wolfram.com/t/use-replaceall-to-modify-a-network-layer/16891>\
**Category:** Questions\
**Created:** [October 20, 2020, 10:41am UTC](https://community.wolfram.com/t/use-replaceall-to-modify-a-network-layer/16891 "2020-10-20T10:41:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![grondilu](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/grondilu/32/15533_2.png) [@grondilu](https://community.wolfram.com/u/grondilu)\
**Post date:** [October 20, 2020, 10:41am UTC](https://community.wolfram.com/t/use-replaceall-to-modify-a-network-layer/16891/1 "2020-10-20T10:41:43Z")

</div>

I was reading a paper mentioning the use of a neural network model available in the Wolfram neural repository. The authors explained that they modified the model to use the average function in the pooling layers instead of the max function.

I naïvely thought I could do the same by just applying the rule `Max -> Mean` to all pooling layers to get the same result, but I didn’t succeed.

Here is the simplest possible example I could come up with to show you what I mean :

```
LinearLayer[2] /. 2 -> 3

```

Why doesn’t this instruction return a LinearLayer with three outputs instead of two ? I feel like I’m missing something obvious but I don’t see it :-/

PS. It seems that what I was initially looking for is `NetReplacePart`.

---

<div class="post-metadata">

**Author:** ![rohitnamjoshi](https://avatars.discourse-cdn.com/v4/letter/r/f1d935/32.png) [@rohitnamjoshi](https://community.wolfram.com/u/rohitnamjoshi)\
**Post date:** [October 20, 2020, 1:43pm UTC](https://community.wolfram.com/t/use-replaceall-to-modify-a-network-layer/16891/2 "2020-10-20T13:43:58Z")

</div>

Hi Lucien

The reason is that `LinearLayer[2]` is evaluated before the `Replace`. One workaround

```
Unevaluated[LinearLayer[2]] /. 2 -> 3

```

WL evaluation is described [here](https://reference.wolfram.com/language/tutorial/Evaluation.html).

---

<div class="post-metadata">

**Author:** ![grondilu](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/grondilu/32/15533_2.png) [@grondilu](https://community.wolfram.com/u/grondilu)\
**Post date:** [October 20, 2020, 1:55pm UTC](https://community.wolfram.com/t/use-replaceall-to-modify-a-network-layer/16891/3 "2020-10-20T13:55:09Z")

</div>

But isn’t there necessarily a “2” somewhere in the evaluated form of `LinearLayer[2]` ?

I mean if I define say `f[] := foo` then `f[] /. foo -> bar` does return `bar`.
