# Flux.jl, Network size reduction

**URL:** <https://discourse.julialang.org/t/flux-jl-network-size-reduction/37413>\
**Category:** New to Julia\
**Created:** [April 11, 2020, 7:29pm UTC](https://discourse.julialang.org/t/flux-jl-network-size-reduction/37413 "2020-04-11T19:29:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![erlebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/erlebach/32/12973_2.png) [@erlebach](https://discourse.julialang.org/u/erlebach)\
**Post date:** [April 11, 2020, 7:29pm UTC](https://discourse.julialang.org/t/flux-jl-network-size-reduction/37413/1 "2020-04-11T19:29:28Z")

</div>

I have the following code, copied and slightly modified from [GitHub - r3tex/LossSurface: Efficient Neural Network Loss Landscape Generation](https://github.com/r3tex/LossSurface). Here is the code:

```julia
sing Flux
#using CuArrays

batchsize = 64

dat_x = Flux.Data.FashionMNIST.images(:train)
dat_x = [reshape(Float32.(x), 28, 28, 1, 1) for x in dat_x]
dat_x = gpu.([reduce((x, y)->cat(x, y, dims=4), batch)
            for batch in Iterators.partition(dat_x, batchsize)])

dat_y = Flux.Data.FashionMNIST.labels(:train)
dat_y = gpu.([Flux.onehotbatch(batch, 0:9)
            for batch in Iterators.partition(dat_y, batchsize)])

dat = zip(dat_x, dat_y);
#-------------------------------------------------------
function large_vgg()
    vgg = gpu(Chain(
        Conv((3,3), 1 =>64, relu, pad=(1,1)), BatchNorm(64),
        Conv((3,3), 64 =>64, relu, pad=(1,1)), BatchNorm(64),
        # Change maxpool function signature (upgraded Flux)
        MaxPool((2,2)),
        Conv((3,3), 64 =>128, relu, pad=(1,1)), BatchNorm(128),
        Conv((3,3), 128=>128, relu, pad=(1,1)), BatchNorm(128),
        MaxPool((2,2)),
        Conv((3,3), 128=>256, relu, pad=(1,1)), BatchNorm(256),
        Conv((3,3), 256=>256, relu, pad=(1,1)), BatchNorm(256),
        Conv((3,3), 256=>256, relu, pad=(1,1)), BatchNorm(256),
        MaxPool((2,2)),
        Conv((3,3), 256=>512, relu, pad=(1,1)), BatchNorm(512),
        Conv((3,3), 512=>512, relu, pad=(1,1)), BatchNorm(512),
        Conv((3,3), 512=>512, relu, pad=(1,1)), BatchNorm(512),
        MaxPool((2,2)), x -> reshape(x, :, size(x,4)),
        Dense(512, 4096, relu),
        Dense(4096, 4096, relu), Dropout(0.5),
        Dense(4096, 10),
        softmax))

        loss(x, y) = Flux.crossentropy(vgg(x), y)
        Flux.train!(loss, params(vgg), dat, ADAM())
end
#-------------------------------------------------
function small_vgg()
    vgg = gpu(Chain(
    Conv((3,3), 1 =>64, relu, pad=(1,1)), BatchNorm(64),
    Dense(64, 256, relu),
    Dense(256, 256, relu), Dropout(0.5),
    Dense(256, 10),
    softmax))

    loss(x, y) = Flux.crossentropy(vgg(x), y)
    Flux.train!(loss, params(vgg), dat, ADAM())
end
######################################

```

which transferred from a Julia Notebook to Atom. Notice the original VGG networkm, packaged into a function named large\_vgg() and a smaller network I wanted to run to save time packaged into the function small\_vgg().

The larger network runs fine, in the sense that the code prints no output and does not stop, even after several minutes. The smaller code produces an error, which is: (the error dump is long, and I am having trouble cutting and pasting. What is the best way to select the full error message to transfer into this message box?) I only show the first few lines in this image:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/c/1/c1c8e1013f406e529f76362fe49020ad9beb65a3.png)

I welcome any ideas because I am stuck. Thanks.

```julia

```

---

<div class="post-metadata">

**Author:** ![erlebach1](https://avatars.discourse-cdn.com/v4/letter/e/ed655f/32.png) [@erlebach1](https://discourse.julialang.org/u/erlebach1)\
**Post date:** [April 12, 2020, 3:43am UTC](https://discourse.julialang.org/t/flux-jl-network-size-reduction/37413/2 "2020-04-12T03:43:31Z")

</div>

Never mind. I solved the problem. I had a simple misunderstanding.
