【睿慕课点云处理】第九章-基于深度学习的点云分割方法

课程

课程汇总

作业

在这里插入图片描述

代码注释(tensorflow版本)

github


在这里插入图片描述

EdgeConv修改

增加余弦距离

def get_edge_feature(point_cloud, nn_idx, k=20):
  """Construct edge feature for each point
  Args:
    point_cloud: (batch_size, num_points, 1, num_dims)
    nn_idx: (batch_size, num_points, k)
    k: int

  Returns:
    edge features: (batch_size, num_points, k, num_dims)
  """
  og_batch_size = point_cloud.get_shape().as_list()[0]
  point_cloud = tf.squeeze(point_cloud)         # B*N*num_dims


  if og_batch_size == 1:
    point_cloud = tf.expand_dims(point_cloud, 0)

  point_cloud_central = point_cloud

  point_cloud_shape = point_cloud.get_shape()
  batch_size = point_cloud_shape[0].value
  num_points = point_cloud_shape[1].value
  num_dims = point_cloud_shape[2].value

  # 计算pointcloud的中心点 in:B*N*num_dims,out:B*1*num_dims
  cloud_center=tf.reduce_mean(point_cloud,axis=-2,keep_dims=True)   # B*1*num_dims
  cloud_center=tf.expand_dims(cloud_center,axis=-2)         # B*1*1*num_dims
  cloud_center=tf.tile(cloud_center,[1,num_points,k,1])           # B*N*K*num_dims



  idx_ = tf.range(batch_size) * num_points
  idx_ = tf.reshape(idx_, [batch_size, 1, 1]) 

  point_cloud_flat = tf.reshape(point_cloud, [-1, num_dims])
  point_cloud_neighbors = tf.gather(point_cloud_flat, nn_idx+idx_)   # gather:抽取子集,邻域特征 B*N*K*3

  # 每一个点
  point_cloud_central = tf.expand_dims(point_cloud_central, axis=-2)  # 自身点 B*N*1*3
  point_cloud_central = tf.tile(point_cloud_central, [1, 1, k, 1])   # 赋值,第三个维度复制k倍 B*N*K*3

  # 计算每个点到中心点的向量a、k邻域点到中心点的向量b
  a=point_cloud_central-cloud_center            # B*N*K*num_dims
  b=point_cloud_neighbors-cloud_center          # B*N*K*num_dims

  # 求模
  a_norm=tf.sqrt(tf.reduce_sum(tf.square(a), axis=-1))
  b_norm=tf.sqrt(tf.reduce_sum(tf.square(b), axis=-1))

  # 内积
  a_b = tf.reduce_sum(tf.multiply(a, b), axis=-1)

  # 余弦距离
  cosin = tf.divide(a_b, tf.multiply(a_norm, b_norm))    # B*N*K

  # 对余弦距离扩维
  cosin=tf.expand_dims(cosin,axis=-1)


  edge_feature = tf.concat([point_cloud_central, point_cloud_neighbors-point_cloud_central,cosin], axis=-1)   # 点的特征和边的特征组合起来,在最后一个维度上相加 B*N*K*6
  return edge_feature
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Tech沉思录

点赞加投币,感谢您的资瓷~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值