I have part of my code as following:
class_label = tf.placeholder(tf.float32, [None], name="condition_checking")
row_index = tf.where(class_label > 0)
I want to check when row_index is empty to write the following
loss_f_G_filtered = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(
logits=y1_filterred, labels=y__filtered), name="filtered_reg")
if row_index == []:
loss_f_G_filtered = tf.constant(0, tf.float32)
However, I do not know how to check if row_index
is an empty tensor.
is_empty = tf.equal(tf.size(row_index), 0)
You can use tf.cond
:
idx0 = tf.shape(row_index)[0]
loss_f_G_filtered = tf.cond(idx0 == 0,
lambda: tf.constant(0, tf.float32),
lambda: ...another function...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With