I have downloaded a keras model named 'nsfw.299x299.h5' which has been trained to detect the following 5 classes:
- Neutral
- Drawings
- Hentai
- Sexy
- Porn
The model is giving False Positives on some coffee cup images and classifying them as "Porn" when it should have been classified as "Neutral". Now I have downloaded some coffee cup images and have placed them inside a folder named 'neutral' and I want to perform transfer learning and train this 'nsfw.299x299.h5' model again so that the bias can be removed for coffee cup images. Below is the last few lines of summary of the 'nsfw.299x299.h5' model.
__________________________________________________________________________________________________
Model: "model"
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
__________________________________________________________________________________________________
activation_94 (Activation) (None, 8, 8, 192) 0 batch_normalization_94[0][0]
__________________________________________________________________________________________________
mixed10 (Concatenate) (None, 8, 8, 2048) 0 activation_86[0][0]
mixed9_1[0][0]
concatenate_2[0][0]
activation_94[0][0]
__________________________________________________________________________________________________
average_pooling2d_10 (AveragePo (None, 1, 1, 2048) 0 mixed10[0][0]
__________________________________________________________________________________________________
flatten_1 (Flatten) (None, 2048) 0 average_pooling2d_10[0][0]
__________________________________________________________________________________________________
dense_1 (Dense) (None, 256) 524544 flatten_1[0][0]
__________________________________________________________________________________________________
dropout_2 (Dropout) (None, 256) 0 dense_1[0][0]
__________________________________________________________________________________________________
dense_2 (Dense) (None, 128) 32896 dropout_2[0][0]
__________________________________________________________________________________________________
dropout_3 (Dropout) (None, 128) 0 dense_2[0][0]
__________________________________________________________________________________________________
dense (Dense) (None, 5) 645 dropout_3[0][0]
==================================================================================================
Total params: 22,360,869
Trainable params: 17,076,261
Non-trainable params: 5,284,608
I found the following code from the training script from github from where I downloaded the model. Github Link: https://github.com/GantMan/nsfw_model
# Config
height = constants.SIZES['basic']
width = height
weights_file = "weights.best_inception" + str(height) + ".hdf5"
conv_base = InceptionV3(
weights='imagenet',
include_top=False,
input_shape=(height, width, constants.NUM_CHANNELS)
)
# First time run, no unlocking
conv_base.trainable = False
# Let's see it
print('Summary')
print(conv_base.summary())
# Let's construct that top layer replacement
x = conv_base.output
x = AveragePooling2D(pool_size=(8, 8))(x)
x - Dropout(0.4)(x)
x = Flatten()(x)
x = Dense(256, activation='relu', kernel_initializer=initializers.he_normal(seed=None), kernel_regularizer=regularizers.l2(.0005))(x)
x = Dropout(0.5)(x)
# Essential to have another layer for better accuracy
x = Dense(128,activation='relu', kernel_initializer=initializers.he_normal(seed=None))(x)
x = Dropout(0.25)(x)
predictions = Dense(constants.NUM_CLASSES, kernel_initializer="glorot_uniform", activation='softmax')(x)
I am having a hard time in figuring out the training method. How should I go ahead with the training?