In this loss function, I need to create full metrics depends on the number of images in batch and size of the image. However, I can get the image size from y_pred but no the batch size because it is coming as None while initializing the graph.
def focal_loss(content, label_remap, gamma_=2, w_d=1e-4):
def focal_loss_fixed(y_true, y_pred):
num_classes = len(content.keys())
print("y_true_b", y_true.get_shape().as_list())
cv_eqation = K.constant([0.114, 0.587, 0.299])
y_true = tf.multiply(y_true, cv_eqation)
y_true = tf.reduce_sum(y_true, axis=3)
y_true = tf.cast(y_true, dtype=tf.uint8)
lbls_resized = y_true
logits_train = y_pred
b, c, w, h = K.int_shape(y_pred)
batch = K.constant(b)
channel = K.variable(c)
width = K.variable(w)
high = K.variable(h)
with tf.variable_scope("loss"):
......
# make the labels one-hot for the cross-entropy
onehot_mat = tf.reshape(tf.one_hot(lbls_resized, num_classes), (-1, num_classes))
# focal loss p and gamma
gamma = np.full((high * width * batch, channel), fill_value=gamma_)
print("gamma", gamma.shape)
.........
return loss
return focal_loss_fixed
Also, I tried a different way by using onehot_mat shape but it has none value in its shape.