# Where can i find documentation about Flux modular (approach) for building models?

**URL:** <https://discourse.julialang.org/t/where-can-i-find-documentation-about-flux-modular-approach-for-building-models/66780>\
**Category:** Machine Learning\
**Tags:** machine-learning\
**Created:** [August 21, 2021, 3:50pm UTC](https://discourse.julialang.org/t/where-can-i-find-documentation-about-flux-modular-approach-for-building-models/66780 "2021-08-21T15:50:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![extremety1989](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/extremety1989/32/28184_2.png) [@extremety1989](https://discourse.julialang.org/u/extremety1989)\
**Post date:** [August 21, 2021, 3:50pm UTC](https://discourse.julialang.org/t/where-can-i-find-documentation-about-flux-modular-approach-for-building-models/66780/1 "2021-08-21T15:50:47Z")

</div>

i found this example ,but no documentation how to build this way

```julia
struct FFNetwork
    fc_1
    dropout
    fc_2
    FFNetwork(
        input_dim::Int, hidden_dim::Int, dropout::Float32, num_classes::Int
    ) = new(
        Dense(input_dim, hidden_dim, relu),
        Dropout(dropout),
        Dense(hidden_dim, num_classes),
    )
end

function (net::FFNetwork)(x)
    x = Flux.flatten(x)
    return net.fc_2(net.dropout(net.fc_1(x)))
end

```

---

<div class="post-metadata">

**Author:** ![extremety1989](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/extremety1989/32/28184_2.png) [@extremety1989](https://discourse.julialang.org/u/extremety1989)\
**Post date:** [August 21, 2021, 3:54pm UTC](https://discourse.julialang.org/t/where-can-i-find-documentation-about-flux-modular-approach-for-building-models/66780/2 "2021-08-21T15:54:52Z")

</div>

this pytorch code i want to reproduce to Julia Flux

```julia
class FFNetwork(Module):
    def __init__ (self, input_dims, hidden_dim, dropout_ratio, num_classes):
        super(FFNetwork, self). __init__ ()
        self.flat_image_dims = np.prod(input_dims)
        self.fc_1 = torch.nn.Linear(self.flat_image_dims, hidden_dim)
        self.dropout = torch.nn.Dropout(dropout_ratio)
        self.fc_2 = torch.nn.Linear(hidden_dim, num_classes)

    def forward(self, x):
        x = x.view(-1, self.flat_image_dims)
        return self.fc_2(self.dropout(F.relu(self.fc_1(x))))

```

---

<div class="post-metadata">

**Author:** ![ToucheSir](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/touchesir/32/14411_2.png) [@ToucheSir](https://discourse.julialang.org/u/ToucheSir)\
**Post date:** [August 21, 2021, 7:05pm UTC](https://discourse.julialang.org/t/where-can-i-find-documentation-about-flux-modular-approach-for-building-models/66780/3 "2021-08-21T19:05:01Z")

</div>

Per [Advanced Model Building · Flux](https://fluxml.ai/Flux.jl/stable/models/advanced/), all you need to add to make the custom layer Flux compatible is `@functor FFNetwork`.

---

<div class="post-metadata">

**Author:** ![extremety1989](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/extremety1989/32/28184_2.png) [@extremety1989](https://discourse.julialang.org/u/extremety1989)\
**Post date:** [August 21, 2021, 7:14pm UTC](https://discourse.julialang.org/t/where-can-i-find-documentation-about-flux-modular-approach-for-building-models/66780/4 "2021-08-21T19:14:53Z")

</div>

thanks, but i already figure it out…

---

<div class="post-metadata">

**Author:** ![ToucheSir](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/touchesir/32/14411_2.png) [@ToucheSir](https://discourse.julialang.org/u/ToucheSir)\
**Post date:** [August 21, 2021, 7:17pm UTC](https://discourse.julialang.org/t/where-can-i-find-documentation-about-flux-modular-approach-for-building-models/66780/5 "2021-08-21T19:17:02Z")

</div>

Great that you already figured it out! In future, I would recommend posting what you found here and marking it as a solution as soon as you’ve done so. It saves us time answering a solved question, gives a solution for future readers and is generally good etiquette.
