hehefan / PointRNN

TensorFlow implementation of PointRNN, PointGRU and PointLSTM.
MIT License
144 stars 20 forks source link

Calculation of CD and EMD loss #10

Open ParthGoyal1508 opened 2 years ago

ParthGoyal1508 commented 2 years ago

Hey! while calculating chamfer distance loss using tf_nn_distance module

dists_forward, _, dists_backward, _ = tf_nndistance.nn_distance(predicted_frames[i], frames[i+int(seq_length/2)]) loss_cd = tf.reduce_mean(input_tensor=dists_forward+dists_backward)

dists_forward has the shape output: dist1: (batch_size,#point_1) that means it's averaged over num_points and hence you aren't dividing it by num_points.

while calculating earth mover distance using tf_approxmatch module

match = tf_approxmatch.approx_match(frames[i+int(seq_length/2)], predicted_frames[i]) emd_distance = tf.reduce_mean(input_tensor=tf_approxmatch.match_cost(frames[i+int(seq_length/2)], predicted_frames[i], match))

match_cost has the shape match : batch_size * #query_points * #dataset_points and after taking reduce mean it's giving the mean over whole point cloud and that's why you are dividing the emd loss as self.emd /= (int(seq_length/2)*num_points)

But in the loss calculation you are using self.loss += (alpha*loss_cd + beta*loss_emd) before dividing loss_emd with the num_points that means loss_cd is calculated over per molecule but loss _emd is calculated over per point cloud and let's assume if we take alpha as 1 and beta as 1, will that mean we aren't taking the equal contribution of both type of loss?

@hehefan Could you please clarify this? Thanks.

hehefan commented 2 years ago

Hi @ParthGoyal1508,

You are right. The alpha and beta are set to 1. For training, the contribution of the losses is not equal.