WilsonPena
WilsonPena

Reputation: 1571

Machine Learning - Modeling a CNN to identify if image “is” or “isn't” something

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!

Upvotes: 0

Views: 461

Answers (1)

ralf htp
ralf htp

Reputation: 9422

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

Upvotes: 1

Related Questions