博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
chamfer_pcd
阅读量:5158 次
发布时间:2019-06-13

本文共 3069 字,大约阅读时间需要 10 分钟。

import tensorflow as tfimport numpy as npdef distance_matrix(array1, array2):    """    arguments:        array1: the array, size: (num_point, num_feature)        array2: the samples, size: (num_point, num_feature)    returns:        distances: each entry is the distance from a sample to array1            , it's size: (num_point, num_point)    """    num_point, num_features = array1.shape    expanded_array1 = tf.tile(array1, (num_point, 1))    expanded_array2 = tf.reshape(            tf.tile(tf.expand_dims(array2, 1),                    (1, num_point, 1)),            (-1, num_features))    distances = tf.norm(expanded_array1-expanded_array2, axis=1)    distances = tf.reshape(distances, (num_point, num_point))    return distancesdef av_dist(array1, array2):    """    arguments:        array1, array2: both size: (num_points, num_feature)    returns:        distances: size: (1,)    """    distances = distance_matrix(array1, array2)    distances = tf.reduce_min(distances, axis=1)    distances = tf.reduce_mean(distances)    return distancesdef av_dist_sum(arrays):    """    arguments:        arrays: array1, array2    returns:        sum of av_dist(array1, array2) and av_dist(array2, array1)    """    array1, array2 = arrays    av_dist1 = av_dist(array1, array2)    av_dist2 = av_dist(array2, array1)    return av_dist1+av_dist2def chamfer_distance_tf(array1, array2):    batch_size, num_point, num_features = array1.shape    dist = tf.reduce_mean(               tf.map_fn(av_dist_sum, elems=(array1, array2), dtype=tf.float64)           )    return distdef array2samples_distance(array1, array2):    """    arguments:        array1: the array, size: (num_point, num_feature)        array2: the samples, size: (num_point, num_feature)    returns:        distances: each entry is the distance from a sample to array1    """    num_point, num_features = array1.shape    expanded_array1 = np.tile(array1, (num_point, 1))    expanded_array2 = np.reshape(            np.tile(np.expand_dims(array2, 1),                    (1, num_point, 1)),            (-1, num_features))    distances = np.linalg.norm(expanded_array1-expanded_array2, axis=1)    distances = np.reshape(distances, (num_point, num_point))    distances = np.min(distances, axis=1)    distances = np.mean(distances)    return distancesdef chamfer_distance_numpy(array1, array2):    batch_size, num_point, num_features = array1.shape    dist = 0    for i in range(batch_size):        av_dist1 = array2samples_distance(array1[i], array2[i])        av_dist2 = array2samples_distance(array2[i], array1[i])        dist = dist + (av_dist1+av_dist2)/batch_size    return distif __name__=='__main__':    batch_size = 3    num_point = 10    num_features = 3    np.random.seed(1)    array1 = np.random.randint(0, high=4, size=(batch_size, num_point, num_features))    array2 = np.random.randint(0, high=4, size=(batch_size, num_point, num_features))    print (array1)    #print(array2)    print('numpy: ', chamfer_distance_numpy(array1, array2))

  

转载于:https://www.cnblogs.com/BambooEatPanda/p/10974184.html

你可能感兴趣的文章
(转)Linxu磁盘体系知识介绍及磁盘介绍
查看>>
tkinter布局
查看>>
命令ord
查看>>
Sharepoint 2013搜索服务配置总结(实战)
查看>>
博客盈利请先考虑这七点
查看>>
使用 XMLBeans 进行编程
查看>>
写接口请求类型为get或post的时,参数定义的几种方式,如何用注解(原创)--雷锋...
查看>>
【OpenJ_Bailian - 2287】Tian Ji -- The Horse Racing (贪心)
查看>>
Java网络编程--socket服务器端与客户端讲解
查看>>
List_统计输入数值的各种值
查看>>
学习笔记-KMP算法
查看>>
Timer-triggered memory-to-memory DMA transfer demonstrator
查看>>
跨域问题整理
查看>>
[Linux]文件浏览
查看>>
64位主机64位oracle下装32位客户端ODAC(NFPACS版)
查看>>
获取国内随机IP的函数
查看>>
今天第一次写博客
查看>>
江城子·己亥年戊辰月丁丑日话凄凉
查看>>
IP V4 和 IP V6 初识
查看>>
Spring Mvc模式下Jquery Ajax 与后台交互操作
查看>>