def build_optimizer(self): print('Building chamfer distance loss and emd loss optimizer...') self.optimizer = tf.train.AdamOptimizer(3e-5) dist1 = {} dist2 = {} match = {} dist1_mid, idx1, dist2_mid, idx2 = nn_distance(self.pcl_gt[16384], self.mid) self.mid_loss = (tf.reduce_mean(dist1_mid) + tf.reduce_mean(dist2_mid)) for stage in self.hierarchies: dist1[stage], _idx1, dist2[stage], _idx2 = nn_distance( self.pcl_gt[stage], self.out[stage]) self.cd_loss_pu[stage] = tf.reduce_mean( dist1[stage]) + tf.reduce_mean(dist2[stage]) if stage == 1024: match[stage] = approx_match(self.pcl_gt[stage], self.out[stage]) self.emd_loss_pu[stage] = tf.reduce_mean( match_cost(self.pcl_gt[stage], self.out[stage], match[stage])) self.train_loss = 0.5 * (self.cd_loss_pu[1024] + self.emd_loss_pu[1024] / 1000) + self.mid_loss + self.cd_loss_pu[16384] self.cd_loss = self.cd_loss_pu[16384] update_ops = tf.get_collection(tf.GraphKeys.UPDATE_OPS) with tf.control_dependencies(update_ops): self.opt_op = self.optimizer.minimize(self.train_loss)
def build_loss_calculater(self): if self.mode == 'test': self.gt, self.pred = scale(self.gt, self.pred) #cd dist1, idx1, dist2, idx2 = nn_distance(self.gt, self.pred) self.cd_loss = tf.reduce_mean(dist1) + tf.reduce_mean(dist2) #emd match = approx_match(self.pred, self.gt) # self.emd_loss = tf.reduce_mean(match_cost(self.gt, self.pred, match)) / float(tf.shape(self.pred)[1]) self.emd_loss = tf.reduce_mean(match_cost(self.pred, self.gt, match))
def build_loss(self): self.scaled_gt, self.scaled_pred = scale(self.gt, self.pred) #cd dist1, idx1, dist2, idx2 = nn_distance(self.scaled_gt, self.scaled_pred) self.cd_loss = tf.reduce_mean(dist1) + tf.reduce_mean(dist2) #emd match = approx_match(self.scaled_pred, self.scaled_gt) # self.emd_loss = tf.reduce_mean(match_cost(self.gt, self.pred, match)) / float(tf.shape(self.pred)[1]) self.emd_loss = tf.reduce_mean( match_cost(self.scaled_pred, self.scaled_gt, match))
def build_loss(self): # self.ph_pred = tf.placeholder(tf.float32, shape = (None, 1024, 3), name = 'ph_pred') # self.ph_gt = tf.placeholder(tf.float32, shape = (None, 16384, 3), name = 'ph_gt') # self.ph_pred2 = tf.placeholder(tf.float32, shape = (None, 1024, 3), name = 'ph_pred2') # self.ph_gt2 = tf.placeholder(tf.float32, shape = (None, 1024, 3), name = 'ph_gt2') self.scaled_gt, self.scaled_pred = scale(self.gt, self.pred) #cd dist1, idx1, dist2, idx2 = nn_distance(self.scaled_gt, self.scaled_pred) self.cd_loss = tf.reduce_mean(dist1) + tf.reduce_mean(dist2) #emd match = approx_match(self.scaled_pred, self.scaled_gt) # self.emd_loss = tf.reduce_mean(match_cost(self.gt, self.pred, match)) / float(tf.shape(self.pred)[1]) self.emd_loss = tf.reduce_mean( match_cost(self.scaled_pred, self.scaled_gt, match))