Tensorflow architecture for pixel based image classification

378 views Asked by At

I have an RGBI image including 4 bands and want to be able to classify image pixels using tensorflow and deep learning into two classes. In the training data, each pixel is regarded an observation with 4 values/features as image intensity. I used the following function to create the network

def deep_learn(X,Y,X_test,Y_test):

    net = input_data(shape=[None, 1,4])
    net = tflearn.lstm(net, 128, return_seq=True)
    net = tflearn.lstm(net, 128)
    net = tflearn.fully_connected(net, 2, activation='softmax')
    net = tflearn.regression(net, optimizer='adam',
                             loss='categorical_crossentropy', name="deep")
    model = tflearn.DNN(net, tensorboard_verbose=2)
    model.fit(X, Y, n_epoch=1, validation_set=0.1, show_metric=True,
              snapshot_step=100)
    # Save model when training is complete to a file
    model.save("deep")
    return model

but I got the following error

ValueError: Cannot feed value of shape (64, 4) for Tensor 'InputData/X:0', which has shape '(?, 1, 4)'

I don't know where the problem is. Is there any benefit in using Deep Neural Networks versus Random Forest for pixel-based classification? and if yes, how can I do this using the above function.

Thank you.

1

There are 1 answers

3
martianwars On BEST ANSWER

You need to expand the dimensions of variable X, to account for the time step in the LSTM. Instead of directly passing X, use np.expand_dims like -

X = np.expand_dims(X, axis=1)