3

Please note everyone, that this is a "Multi-Label" problem as opposed to Multi-Class. It's a multi-label, multi-class problem. I am trying to classify movie posters by genre by reading the images alone. I have over 22000 images overall. I have one hot encoded the genres for the Keas model to predict multiple genres for movies (Used sigmoid in final dense layer activation). I need recommendation for a proper batch size and number of epochs. I am using VGG16. I would also like to know how to choose which layers to freeze.

I have tried for 25 epochs using VGG16. The model tends to over-fit though. Batch size was 10.

Here's my training images count by genre (Note: A movie could be more than one genre which is more often than not, the case)

{'Action': 2226.0, 'Thriller': 2788.0, 'Drama': 9283.0, 'Romance': 2184.0, 'Horror': 2517.0, 'Sci-Fi': 756.0, 'Mystery': 918.0, 'Adventure': 1105.0, 'Animation': 583.0, 'Crime': 1369.0, 'Comedy': 5524.0, 'Fantasy': 735.0, 'Family': 991.0, 'Music': 319.0, 'History': 359.0, 'War': 177.0, 'Musical': 191.0, 'Biography': 484.0, 'Sport': 190.0}

conv_base = VGG16(weights = 'imagenet', include_top = False, input_shape = (224,224,3))

for layer in conv_base.layers[6:]:
    layer.trainable = False

early = EarlyStopping(monitor='acc', patience=7, mode='auto')

classifier = Sequential()
classifier.add(conv_base)

from keras.layers import Dropout
classifier.add(Dense(units = 128, activation = "relu"))
classifier.add(Dropout(0.2))
classifier.add(Dense(units = 128, activation = "relu"))
classifier.add(Dropout(0.1))
classifier.add(Dense(units = 19, activation = 'sigmoid'))

classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ["accuracy"])

classifier.fit(X_train, y_train, epochs=15, batch_size=10, callbacks = [early])
desertnaut
  • 57,590
  • 26
  • 140
  • 166
  • Can you please share more detail about your problem, what you have expected, and what made you feel something's going wrong. – Chris Jan 08 '19 at 01:52
  • Chris, here's my genre count for the test_set: {'Action': 521.0, 'Thriller': 685.0, 'Drama': 2389.0, 'Romance': 533.0, 'Horror': 622.0, 'Sci-Fi': 167.0, 'Mystery': 270.0, 'Adventure': 282.0, 'Animation': 154.0, 'Crime': 363.0, 'Comedy': 1287.0, 'Fantasy': 182.0, 'Family': 232.0, 'Music': 72.0, 'History': 103.0, 'War': 44.0, 'Musical': 50.0, 'Biography': 129.0, 'Sport': 65.0} While doing hard check (perfect label acc), I get 20%. I fear its most likely just predicting drama & comedy (2 most popular genres). Was hoping for 50% initially! – Aditya Jakka Jan 08 '19 at 03:36
  • While, training accuracy was around 94%. I have 19 genres in total. Hence, my y matrix is sparse with 1s for the correct genre. For ex: Action/Comedy movie will have a 1 for comedy & action and 0s for the other genres. So, for training, it was predicting 18/19 labels. I feared it was over-fitting and hence, my worst fears were realized. – Aditya Jakka Jan 08 '19 at 03:42
  • To start with, use `categorical_crossentropy` for a multiclass problem. Your training accuracy can be **completely misleading** when `loss` is wrongly chosen. – Chris Jan 08 '19 at 03:55
  • Possible duplicate of [Keras binary\_crossentropy vs categorical\_crossentropy performance?](https://stackoverflow.com/questions/42081257/keras-binary-crossentropy-vs-categorical-crossentropy-performance) – Chris Jan 08 '19 at 03:56
  • The person in the example has used 'softmax' activation. I cannot use softmax as it is a multi-label problem. Should I really use 'categorical-crossentropy' as loss function for multi-label problems? – Aditya Jakka Jan 08 '19 at 05:52

0 Answers0