0

I'm trying to build a CNN to play a game online. This game to be precise:

https://www.gameeapp.com/game-bot/ibBTDViUP

I've collected images and labels for each image. These labels tell the network to press SPACE (output 1) or do nothing (output 0).

I'm training the network using Keras, like this:

history = model.fit_generator(
        train_generator,
        steps_per_epoch=2000 // batch_size,
        epochs=3,
        validation_data=validation_generator,
        validation_steps=800 // batch_size)

The network looks like this:

model = Sequential()
model.add(Conv2D(32, (3, 3), input_shape=(275, 208, 1)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))

model.add(Conv2D(64, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))

model.add(Conv2D(64, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))

model.add(Flatten())
model.add(Dense(64))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(1))
model.add(Activation('sigmoid'))

model.compile(loss='binary_crossentropy',
              optimizer='rmsprop',
              metrics=['accuracy'])

The thing is. Most of the time the network ends up always outputting 1 or always zero even when the images are completely unrelated to the game images.

Am I modelling this problem the right way?

How can I make the best way for the network to be able to Identify to "not do" anything.

Please let me know if the question isn't clear and Thanks in advance!

WilsonPena
  • 1,451
  • 2
  • 18
  • 37

1 Answers1

1

You want to do binary image classification ( binary : is - is not ) and i think your net looks good. In Binary Image Classification with CNN - best practices for choosing "negative" dataset? are general hints for training binary image classification networks. In https://medium.com/@kylepob61392/airplane-image-classification-using-a-keras-cnn-22be506fdb53 is a complete guide for setting up image classification network in keras. i am not sure about the training possibly use plain model.fit() like in https://medium.com/@kylepob61392/airplane-image-classification-using-a-keras-cnn-22be506fdb53

ralf htp
  • 9,149
  • 4
  • 22
  • 34
  • I was looking for that SO question right there. Thank you. I am actually already training and trying the network in practice. But the results are far from the expected. – WilsonPena Aug 24 '18 at 14:09
  • possibly because it trains badly for some reasons. maybe try to adapt the batch size – ralf htp Aug 24 '18 at 14:21
  • I actually tried several batch sizes, it didn't make that much difference. I have 1500 samples total, it seems like a good amount considering what I've seen in the internet. – WilsonPena Aug 24 '18 at 14:24
  • i do not know what images you have but generally the critical structures should be centered, cf https://stackoverflow.com/questions/45561037/why-mnist-trained-model-is-not-good-at-digits-which-not-in-the-center-of-the-p – ralf htp Aug 24 '18 at 14:38