# Flattened data vs Flux.flatten layer

**URL:** <https://discourse.julialang.org/t/flattened-data-vs-flux-flatten-layer/68650>\
**Category:** Machine Learning\
**Created:** [September 23, 2021, 8:37pm UTC](https://discourse.julialang.org/t/flattened-data-vs-flux-flatten-layer/68650 "2021-09-23T20:37:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![congUoM](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/conguom/32/10413_2.png) [@congUoM](https://discourse.julialang.org/u/congUoM)\
**Post date:** [September 23, 2021, 8:37pm UTC](https://discourse.julialang.org/t/flattened-data-vs-flux-flatten-layer/68650/1 "2021-09-23T20:37:11Z")

</div>

Hi all,

I am trying to use the following MLP model (for MNIST) in the model zoo as a template for my work, and I have this problem:  
[https://github.com/FluxML/model-zoo/blob/master/vision/mlp\_mnist/mlp\_mnist.jl](https://github.com/FluxML/model-zoo/blob/master/vision/mlp_mnist/mlp_mnist.jl)

I remove the flattening data (lines 18 - 19) and try to add a Flux.flatten layer before the Dense layer, like this:

```julia
return Chain(
              Flux.flatten,
              Dense(prod(imgsize), 32, relu),
              Dense(32, nclasses))

```

but I got very bad training/testing accuracy (it still runs though). I thought they should be the same. Any idea?  
Thanks.

---

<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:** [September 23, 2021, 10:43pm UTC](https://discourse.julialang.org/t/flattened-data-vs-flux-flatten-layer/68650/2 "2021-09-23T22:43:19Z")

</div>

I think they should be too. Can you confirm the shape of `x` is correct before it’s fed into the network (i.e. after [https://github.com/FluxML/model-zoo/blob/master/vision/mlp\_mnist/mlp\_mnist.jl#L84](https://github.com/FluxML/model-zoo/blob/master/vision/mlp_mnist/mlp_mnist.jl#L84))? If everything looks right there (the batch is 28 x 28 x [batch size]) and you experience this poor performance across multiple runs, please do file an issue 🙂

---

<div class="post-metadata">

**Author:** ![congUoM](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/conguom/32/10413_2.png) [@congUoM](https://discourse.julialang.org/u/congUoM)\
**Post date:** [September 23, 2021, 11:40pm UTC](https://discourse.julialang.org/t/flattened-data-vs-flux-flatten-layer/68650/3 "2021-09-23T23:40:20Z")

</div>

I check the shape of x before its fed into the networks and it is of the shape (28, 28, 256), which looks correct. I just submit the issue:  
[https://github.com/FluxML/model-zoo/issues/316](https://github.com/FluxML/model-zoo/issues/316)
