Search code examples
pythontensorflowconv-neural-networktflearn

Binary classification, prediction is 0


I am training to create CNN to play geometry dash. I use AlexNet, which is little bit modified to produce output between -1 to 1.

When output> 0 then it should jump. When output< 0 then it should do nothing.

My training data are 80x60 gray images pair with value -1 or 1 , which indicates, what it should do at this frame. I have 7700 images.

(1 is jump) (-1 is to do nothing)

My AlexNet:

    network = input_data(shape=[None, width, height, 1], name='input')
    network = conv_2d(network, 96, 11, strides=4, activation='relu')
    network = max_pool_2d(network, 3, strides=2)
    network = local_response_normalization(network)
    network = conv_2d(network, 256, 5, activation='relu')
    network = max_pool_2d(network, 3, strides=2)
    network = local_response_normalization(network)
    network = conv_2d(network, 384, 3, activation='relu')
    network = conv_2d(network, 384, 3, activation='relu')
    network = conv_2d(network, 256, 3, activation='relu')
    network = max_pool_2d(network, 3, strides=2)
    network = local_response_normalization(network)
    network = fully_connected(network, 4096, activation='tanh')
    network = dropout(network, 0.5)
    network = fully_connected(network, 4096, activation='tanh')
    network = dropout(network, 0.5)
    network = fully_connected(network, output, activation='sigmoid')
    network = regression(network, optimizer='adam', 
            loss='binary_crossentropy',
            learning_rate=lr, name='targets')
    model = tflearn.DNN(network, checkpoint_path='model_alexnet',
                        max_checkpoints=1, tensorboard_verbose=2, 
    tensorboard_dir='log')

If I want to learn the CNN, it all the time predicts something around 0 for all inputs.

What should I do?

I want to predict for each frame 1 or -1.

I know that sigmoid can t reach 1 or -1, so I shift it by 0.001 to 0.999 and -0.999, but it still doesn t work.

EDIT:

Data are balanced, but shuffled. Same number images for jump and not jump.

Moreover I tried to use inbalanced data, but it ended in the different number for all the images.


Solution

  • Finally, I made it.

    the sigmoid function is from 0 to 1, so I can t used y vectos from -1 to 1. Then I have to decrease learning rate from 1e-3 to 1e-6. Also, I used mean_square error instead of binary_crossentropy. This all solved my problem.