# Error when running a simple ANN model in Flux

**URL:** <https://discourse.julialang.org/t/error-when-running-a-simple-ann-model-in-flux/88890>\
**Category:** Machine Learning\
**Tags:** flux\
**Created:** [October 18, 2022, 8:23am UTC](https://discourse.julialang.org/t/error-when-running-a-simple-ann-model-in-flux/88890 "2022-10-18T08:23:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![imantha](https://avatars.discourse-cdn.com/v4/letter/i/6a8cbe/32.png) [@imantha](https://discourse.julialang.org/u/imantha)\
**Post date:** [October 18, 2022, 8:23am UTC](https://discourse.julialang.org/t/error-when-running-a-simple-ann-model-in-flux/88890/1 "2022-10-18T08:23:20Z")

</div>

Hi I am trying to run a simple ANN model in flux but having trouble with understanding the errors. Any idea what I am doing incorrectly

```julia
# Shapes : X_train : (204,2) , X_val : (51,2), y_train : (204,3), y_val : (51,3) 
# Shapes of X_train, y_train transposed during training

in_dims = 2
l1 = 16
l2 = 16
out_dims = 3
lr = 0.001
epochs = 50

# Function to get Model
get_model(in_dims, l1, l2, out_dims) = Chain(
    Dense(in_dims, l1, relu),
    Dense(l1, l2, relu),
    Dense(l2, out_dims)
)

# Function for training
function training_loop(model::Chain,dataset::Dict)
    (;X_train,X_val,y_train,y_val) = (;sort(dataset)...)
    
    loss_fn(x,y) = mse(model(x),y)
    opt = ADAM(lr)

    losses = Float64[]
    for e = 1:epochs
        train!(loss_fn, params(model), [(X_train',y_train')], opt)
        train_loss = loss_fn(X_train, y_train)
        push!(losses, train_loss)
        println("epoch : $(e) \t training loss : $(train_loss)")
    end
    return losses
end

# Call the function to contruct model and train
dataset = Dict(:X_train => X_train, :X_val => X_val, :y_train => y_train, :y_val => y_val)
train_loss = training_loop(model, dataset)

>>>
ERROR: Mutating arrays is not supported -- called setindex!(Matrix{Any}, ...)
This error occurs when you ask Zygote to differentiate operations that change
the elements of arrays in place (e.g. setting values with 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:** [October 19, 2022, 3:41pm UTC](https://discourse.julialang.org/t/error-when-running-a-simple-ann-model-in-flux/88890/2 "2022-10-19T15:41:49Z")

</div>

If you print out the sizes and eltypes of `x` and `y` in `loss_fn`, that would help identify any issues.
