python - Getting Weights in Custom Loss Function -


i trying implement custom loss function gives weighted pixel-wise cross entropy value.

i have compiled model "sample_weight_mode='temporal'", , passing different weights each individual image. have following this:

model.fit_generator(train_generator,...) 

where, train_generator yields tuples of (input_image, target_label, weight) having following dimensions:

input_image  ->  (48, 64, 64, 1) target_label ->  (196608, 1) weight       ->  (196608,) 

is possible implement loss function obtaining corresponding weight argument ? please let me know if function shown below can implemented ?

def pixelwise_cross_entropy(target, output, weight):     #~ target = tf.convert_to_tensor(target, dtype=tf.float32)     #~ output = tf.convert_to_tensor(output, dtype=tf.float32)     _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) 

the weight map morphologically eroded version of target. tried creating weight map in custom loss function itself. data 3d, cannot use tensorflow's "tf.nn.erosion2d".

and not convert tensor object numpy array operation, gives following negative dimensions error.

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"]()]] 

could please if have knowledge or have come across similar problem ?


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -