So I have 100x100x3 images and its a classification problem with 3 categories.
So my CNN architecture is as follows:
visible = Input(shape=(100, 100, 3))
conv_1 = Conv2D(filters=32, kernel_size=(3, 3), strides=(1, 1), padding='same')(visible)
flatten_1 = Flatten()(conv_1)
dense_1 = Dense(100)(flatten_1)
dense_2 = Dense(3)(dense_1)
act_6 = Activation('softmax')(dense_2)
model = Model(inputs=visible, outputs=act_6)
Now I define my custom loss function as follows:
def custom_loss(visible):
def loss_fun(y_true, y_pred):
return sparse_categorical_crossentropy(y_true, y_pred) + visible[?, 0, 0, 0]
return loss_fun
sgd = SGD(lr=0.1, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(loss=custom_loss(visible), optimizer=sgd)
Of course, the above code gives an error because of "?".
As you can see, I want to add the pixel value of the image which is at (0, 0, 0) for every image to the loss function.
In fact I want to be able to change the (0, 0, 0) to some (x, y, z) depending upon my y_pred for that particular image.
How can I do that?