Flux CNN error: Scalar indexing is disallowed


I have 1D data which I can successfully train and test with all to all connected 3 layer model as below:

function build_model_ffn(; nclasses=2)
    return Chain(
            Dense(99, 48, relu),
            Dense(48, 24, relu),
            Dense(24, 12, relu),
            Dense(12, nclasses))

I am currently trying to adapt the 1D data to CNN by converting it into a (33, 3, 1) with 1 channel (reshaping the input data), using the following model for training:

function build_model_dnn(; nclasses=2)
    return Chain(
            Conv((3,3), 1=>1, relu, pad=(1,1)),
            Dense(11, 5, relu),
            Dense(5, nclasses)

The core functionality of training and testing is adapted from the model zoo feed forward example and remains the same for both the above models. While the first one, build_model_ffn runs successfully, the latter fails with a scalar indexing error. I also tried adapting the convolution layer to be 1D which results in the same error. It would be helpful to know any insights on the error resulting in a successful run of the second model.

The following includes more details of the error:

 [11] conv(x::CuArray{Int64, 4, CUDA.Mem.DeviceBuffer}, w::CuArray{Float32, 4, CUDA.Mem.DeviceBuffer}, cdims::DenseConvDims{2, 2, 2, 4, 2}; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ NNlib /user/jlib/packages/NNlib/0QnJJ/src/conv.jl:88

Something is producing an array of integers x here, maybe your input data? The GPU conv wants all Float32, so instead you get some slow fallback, which works by indexing.

1 Like

Many thanks! It was indeed that the input data is of the type int and converting it to float makes it work!