I am trying to implement a custom loss function that gives a vertical weighted cross-entropy value.
I compiled the model with "sample_weight_mode = 'temporal" and pass different weights for each individual image. For this, I have the following:
model.fit_generator(train_generator,...)
where train_generator gives tuples (input_image, target_label, weight) having the following sizes:
input_image -> (48, 64, 64, 1)
target_label -> (196608, 1)
weight -> (196608,)
Is it possible to implement the loss function by receiving this corresponding weight as an argument? Can someone please tell me if the function shown below can be implemented?
def pixelwise_cross_entropy(target, output, weight):
_EPSILON = 10e-8
output /= tf.reduce_sum(output, axis=len(output.get_shape()) - 1, keep_dims=True)
epsilon = tf.cast(tf.convert_to_tensor(_EPSILON), output.dtype.base_dtype)
output = tf.clip_by_value(output, epsilon, 1. - epsilon)
return - tf.reduce_sum(target * tf.log(output) * weight, axis=len(output.get_shape()) - 1)
. . 3D, "tf.nn.erosion2d".
numpy , .
tensorflow.python.framework.errors_impl.InvalidArgumentError: Shape [-1,-1,-1] has negative dimensions
[[Node: mask_target = Placeholder[dtype=DT_FLOAT, shape=[?,?,?], _device="/job:localhost/replica:0/task:0/gpu:0"]()]]
- , ?