# Metalhead.UNet output array limit

**URL:** <https://discourse.julialang.org/t/metalhead-unet-output-array-limit/110029>\
**Category:** General Usage\
**Tags:** metalhead, unet\
**Created:** [February 10, 2024, 1:07pm UTC](https://discourse.julialang.org/t/metalhead-unet-output-array-limit/110029 "2024-02-10T13:07:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cirobr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cirobr/32/219994_2.png) [@cirobr](https://discourse.julialang.org/u/cirobr)\
**Post date:** [February 10, 2024, 1:07pm UTC](https://discourse.julialang.org/t/metalhead-unet-output-array-limit/110029/1 "2024-02-10T13:07:06Z")

</div>

Cheers,

Would like to confirm if the `yhat` array output of `Metalhead.UNet` model is limited to [0:1] elements. Apparently its upper bound is higher than 1.

Model is instantiated as follows:

> backbone = Metalhead.backbone( ResNet(50; pretrain=true) )  
> modelcpu = Metalhead.UNet((512,512), 3, 1, backbone)  
> model = modelcpu |\> gpu;

Then, without training, model is excited with:

> x = rand(Float32, (512,512,3,1) |\> gpu  
> yhat = model(x)

Thanks in advance for clarifying.

---

<div class="post-metadata">

**Author:** ![FPGro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fpgro/32/20822_2.png) [@FPGro](https://discourse.julialang.org/u/FPGro)\
**Post date:** [February 10, 2024, 10:32pm UTC](https://discourse.julialang.org/t/metalhead-unet-output-array-limit/110029/2 "2024-02-10T22:32:21Z")

</div>

Not currently on a computer, but as far as I remember, the output is not restricted to [0,1] by default.  
You can actually just take a look at the model architecture in the REPL by just doing

```julia
julia> cpumodel

```

Take a look at the last lines to see if the output of the last transformation would be restricted to [0,1] (sigmoid/hardsigmoid) or not. I guess it’s just relu +/- batchnorm at the end.  
That said, you can simply add a missing sigmoid/hardsigmoid at the end to get what you want.

---

<div class="post-metadata">

**Author:** ![cirobr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cirobr/32/219994_2.png) [@cirobr](https://discourse.julialang.org/u/cirobr)\
**Post date:** [February 10, 2024, 11:24pm UTC](https://discourse.julialang.org/t/metalhead-unet-output-array-limit/110029/3 "2024-02-10T23:24:01Z")

</div>

Indeed, last layer is a (1,1) convolution followed by relu. For the record, code follows:

> Chain(  
> Chain(  
> Conv((3, 3), 3 =\> 3, pad=1, bias=false), # 81 parameters  
> BatchNorm(3), # 6 parameters, plus 6  
> NNlib.relu,  
> Conv((3, 3), 3 =\> 3, pad=1, bias=false), # 81 parameters  
> BatchNorm(3), # 6 parameters, plus 6  
> ),  
> Chain(  
> Conv((1, 1), 3 =\> 1, bias=false), # 3 parameters  
> BatchNorm(1, relu), # 2 parameters, plus 2
