ArrayDataProvider input format issue
- Dominant language
- No language data
- Stars
- 369
- Forks
- 63
- PR merge metrics
- No merged PRs in 30d
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.
```julia
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).
```julia
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.
```julia
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:
```julia
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
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.