# Flux: Obtaining individual layer output for DenseNet from Metalhead.jl

**URL:** <https://discourse.julialang.org/t/flux-obtaining-individual-layer-output-for-densenet-from-metalhead-jl/83830>\
**Category:** Machine Learning\
**Tags:** flux, metalhead\
**Created:** [July 6, 2022, 10:09am UTC](https://discourse.julialang.org/t/flux-obtaining-individual-layer-output-for-densenet-from-metalhead-jl/83830 "2022-07-06T10:09:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcpabst](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@marcpabst](https://discourse.julialang.org/u/marcpabst)\
**Post date:** [July 6, 2022, 10:09am UTC](https://discourse.julialang.org/t/flux-obtaining-individual-layer-output-for-densenet-from-metalhead-jl/83830/1 "2022-07-06T10:09:11Z")

</div>

Hi,

I’m training the `DenseNet` from **[Metalhead.jl](https://github.com/FluxML/Metalhead.jl)** on the CIFAR-10 dataset which generally seems to work quite well. However, I can’t seem to find out how to access the output from individual layers in the `Chain`.

I know about `Flux.activations()` but it just gives me an array of size `size(Flux.activation(chain, input)[1]) = (1, 1, 1024, 1)` which I’m not sure how to interpret. Is there any other way to save the output of an individual layer during a forward pass?

---

<div class="post-metadata">

**Author:** ![theabhirath](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/theabhirath/32/42728_2.png) [@theabhirath](https://discourse.julialang.org/u/theabhirath)\
**Post date:** [July 6, 2022, 11:06am UTC](https://discourse.julialang.org/t/flux-obtaining-individual-layer-output-for-densenet-from-metalhead-jl/83830/2 "2022-07-06T11:06:18Z")

</div>

The `DenseNet` in Metalhead.jl is a large `Chain` wrapper around two smaller `Chain`s - a backbone and a classifier head. `Flux.activations` acts on the larger `Chain` in your example. I think what you might be looking for might be something like `Flux.activations(Metalhead.backbone(model), x)`. You should get a `Tuple` with the output of each one of the layers.

---

<div class="post-metadata">

**Author:** ![marcpabst](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@marcpabst](https://discourse.julialang.org/u/marcpabst)\
**Post date:** [July 6, 2022, 11:43am UTC](https://discourse.julialang.org/t/flux-obtaining-individual-layer-output-for-densenet-from-metalhead-jl/83830/3 "2022-07-06T11:43:05Z")

</div>

That seems to be exactly what I was looking for 🙂 Thanks!
