ArrayDataProvider input format issue

Open
#236 15 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale

Research direction

Start with the ArrayDataProvider setup and the mx.Reshape calls shown in the issue, then trace how the two-sample prediction input is constructed. Reproduce the constant-probability result and verify the data and label shapes at each boundary. Done means identifying whether the feed or another part of the implementation causes the repeated predictions and documenting a reproducible fix or explanation.

Written by the indexing model from the issue text.

Description

So I'm trying to do image classification with Arraydataprovider without success and I'm pretty confident it is related to that MXNet doesn't feed in the data correctly.
Raw data input is 66 b/w images.

imageFolder = "./datatide1/"
filenames = map(x -> replace(x, ".jpg", ""), readdir(imageFolder))
labels = map(x -> split(x, "_")[1], filenames)
classes = unique(labels)
classDict = Dict(classes[i] => i for i=1:length(classes))
labelSize = 1
width = 75
heigth = 75

data = zeros(Float32, heigth, width, length(filenames)) 
label = zeros(Int64, length(filenames))

for i in 1:length(filenames)
    image = load(string("datatide1/", filenames[i], ".jpg"))
    image_resized = imresize(image, heigth, width)
    temp = convert(Array{Float32}, image_resized)
    data[:,:,i] = temp 
    label[i] = classDict[labels[i]]
end

So the data is first a 75x75x66 matrix with two classes (faces and houses).

mxData = mx.Variable(:data)
mxLabel  = mx.Variable(:softmax_label)

batch_size = 2

input = mx.Reshape(mxData, shape=(width, heigth,1, batch_size))
eval = mx.Reshape(mxData, shape=(width, heigth,1, batch_size))

train_provider = mx.ArrayDataProvider(:data => mx.NDArray(data),
    :softmax_label => label, 
    batch_size=batch_size, 
    shuffle=true)

So now the data is reshaped to fit Conv net input that needs to be a 4D vector.

conv1 = @mx.chain mx.Convolution(input, kernel=(3,3), num_filter=50)  =>
                  mx.Activation(act_type=:tanh) =>
                  mx.Pooling(pool_type=:max, kernel=(2,2), stride=(2,2))

conv2 = @mx.chain mx.Convolution(conv1, kernel=(5,5), num_filter=50) =>
                  mx.Activation(act_type=:tanh) =>
                  mx.Pooling(pool_type=:max, kernel=(2,2), stride=(1,1))

conv3 = @mx.chain mx.Convolution(conv2, kernel=(3,3), num_filter=30) =>
                  mx.Activation(act_type=:tanh) =>
                  mx.Pooling(pool_type=:max, kernel=(2,2), stride=(2,2))

fc1   = @mx.chain mx.Flatten(conv3) =>
                  mx.FullyConnected(num_hidden=700) =>
                  mx.Activation(act_type=:relu) 

fc2   = @mx.chain mx.FullyConnected(fc1, num_hidden=400) =>
                  mx.Activation(act_type=:relu) 

fc3   = mx.FullyConnected(fc2, num_hidden=2) 
mlp  = mx.SoftmaxOutput(fc3, name=:softmax)

I have varied the hyper parameters a lot now and always get stuck in the same minima of 0.63% accuracy.

What makes me think that there is an error with the data feed is that when I'm predicting on two random samples (one house, one face) not previously seen by the model, it always gives out the same probabilities:

2×2 Array{Float32,2}:
 0.128382  0.128382
 0.871618  0.871618

And this just doesn't make sense since one sample is house and one is face PLUS that I've changed the hyper parameters drastically (including optimization algorithms).

Can anyone see if I'm doing something wrong with the data input or if there is something else fundamentally strange with my implementation?
@pluskid

Dominant language
No language data
Stars
370
Forks
63
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dmlc/MXNet.jl

All issues in dmlc/MXNet.jl

Similar issues

More Machine Learning issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.