mavillan / py-hausdorff

Fast computation of Hausdorff distance in Python
GNU General Public License v3.0
250 stars 34 forks source link

data structure not support Tensor? #5

Open jizhang02 opened 5 years ago

jizhang02 commented 5 years ago

I use this hausdorff function as loss function in keras based neural network, an error happend in this hasudorff function: a bytes-like object is required, not 'Tensor' Could someone solve it? Thanks!

mavillan commented 5 years ago

Can you provide more context about your problem? It seems to me a problem with the expected metric function by tensorflow.

jizhang02 commented 5 years ago

Can you provide more context about your problem? It seems to me a problem with the expected metric function by tensorflow.

Thank you for your reply! This is function I used as loss funtion:

def hausdorff_distance(y_true, y_pred):

y_true_f = K.flatten(y_true)
y_pred_f = K.flatten(y_pred)
print(type(y_pred_f))
#first method
d2_matrix = pairwise_distances(y_true_f, y_pred_f, metric='euclidean')
res = tf.math.reduce_mean(tf.math.minimum(d2_matrix, axis=0)) + tf.math.reduce_mean(tf.math.minimum(d2_matrix, axis=1))
return res
#second method
#return max(directed_hausdorff(y_true_f, y_pred_f)[-1], directed_hausdorff(y_pred_f, y_true_f)[-1])

I use hausdorff function in U-Net as loss function written in Keras, the error was "a bytes-like object is required, not 'Tensor'". image