# Two questions on Flux

**URL:** <https://discourse.julialang.org/t/two-questions-on-flux/22307>\
**Category:** Machine Learning\
**Created:** [March 25, 2019, 3:21pm UTC](https://discourse.julialang.org/t/two-questions-on-flux/22307 "2019-03-25T15:21:18Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [March 27, 2019, 6:21am UTC](https://discourse.julialang.org/t/two-questions-on-flux/22307/21 "2019-03-27T06:21:14Z")

</div>

> [@baggepinnen](#):
>
> No special clothing required 😛

![](https://global.discourse-cdn.com/julialang/original/3X/f/9/f91e42dbd36e97495802df0e4fdf4e11481b72aa.png)

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [July 1, 2019, 9:50am UTC](https://discourse.julialang.org/t/two-questions-on-flux/22307/22 "2019-07-01T09:50:32Z")

</div>

For those still interested in using BFGS (or L-BFGS) to train flux models, I made a small utility package to facilitate this

> [@\[ANN\] FluxOptTools](https://discourse.julialang.org/t/ann-fluxopttools/25888):
>
> [FluxOptTools.jl](https://github.com/baggepinnen/FluxOptTools.jl) This package contains some utilities to enhance training of [Flux.jl](https://github.com/FluxML/Flux.jl) models. Train using Optim [Optim.jl](https://github.com/JuliaNLSolvers/Optim.jl) can be used to train Flux models (if Flux is on branch sf/zygote\_updated), here’s an example how using Flux, Zygote, Optim, FluxOptTools, Statistics m = Chain(Dense(1,3,tanh) , Dense(3,1)) x = LinRange(-pi,pi,100)' y = sin.(x) loss() = mean(abs2, m(x) .- y) Zygote.refresh() pars = Flux.params(m) lossfun, gradfun, fg!, p0 = optfuns(loss, pars) res = Optim.opti…

---

<div class="post-metadata">

**Author:** ![DoktorMike](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/doktormike/32/2736_2.png) [@DoktorMike](https://discourse.julialang.org/u/DoktorMike)\
**Post date:** [July 1, 2019, 11:18am UTC](https://discourse.julialang.org/t/two-questions-on-flux/22307/23 "2019-07-01T11:18:06Z")

</div>

That’s really cool. I’ll try that out later today. 😊

---

<div class="post-metadata">

**Author:** ![FedericoStra](https://avatars.discourse-cdn.com/v4/letter/f/76d3ee/32.png) [@FedericoStra](https://discourse.julialang.org/u/FedericoStra)\
**Post date:** [October 2, 2020, 3:28pm UTC](https://discourse.julialang.org/t/two-questions-on-flux/22307/24 "2020-10-02T15:28:35Z")

</div>

You could define

```julia
randomize!(_) = nothing

function randomize!(d::Dense)
    d.W .= randn(Float32, size(d.W))
    d.b .= randn(Float32, size(d.b))
end

function randomize!(c::Chain)
    for l in c.layers
        randomize!(l)
    end
end

```

and now you can easily reset all your dense layers and chains to random normal distributed parameters, even of nested models like

```julia
Chain(x -> [x], Dense(1,2,σ),
    Chain(Dense(2,7,σ), Dense(7,4,σ)),
    Dense(4,1,σ), first)

```

[Previous page](https://discourse.julialang.org/t/two-questions-on-flux/22307.md?page=1)
