pointNet代码

介绍

组成

1.PointNet classification network分类网络

  1. part segmentation network

数据集

1.point clouds sampled from 3D shapes
2.ShapeNetPart dataset.

结构

其主要分成以下三部分:

  • 数据处理
  • model构建
  • 结果选择

数据处理

将点云处理成程序可用的格式,具体实现在 provider.py 中,主要包含了数据下载、预处理(shuffle->rotate->jitter)、格式转换(hdf5->txt)

shuffle

def shuffle_data(data, labels):
    """ Shuffle data and labels.
        Input:
          data: B,N,... numpy array
          label: B,... numpy array
        Return:
          shuffled data, label and shuffle indices
    """
    idx = np.arange(len(labels))#返回一个列表
    # print(‘idx=‘,idx)#idx= [   0    1    2 ... 2045 2046 2047]
    np.random.shuffle(idx)#把idx进行shuffle
    # print(‘idx=‘, idx)
    return data[idx, ...], labels[idx], idx

rotate旋转处理

def rotate_point_cloud(batch_data):
    # print(‘batch data shape=‘,batch_data.shape)#(32, 1024, 3)
    rotated_data = np.zeros(batch_data.shape, dtype=np.float32)
    for k in range(batch_data.shape[0]):
        rotation_angle = np.random.uniform() * 2 * np.pi#生成一个随机数
        cosval = np.cos(rotation_angle)
        sinval = np.sin(rotation_angle)
        rotation_matrix = np.array([[cosval, 0, sinval],
                                    [0, 1, 0],
                                    [-sinval, 0, cosval]])
        shape_pc = batch_data[k, ...]
        rotated_data[k, ...] = np.dot(shape_pc.reshape((-1, 3)), rotation_matrix)
        #先让shape_pc的形状变成(?,3),因为旋转矩阵为(3,3)
    return rotated_data

jitter抖动处理

def jitter_point_cloud(batch_data, sigma=0.01, clip=0.05):
    B, N, C = batch_data.shape
    assert(clip > 0)
    jittered_data = np.clip(sigma * np.random.randn(B, N, C), -1*clip, clip)#将数组范围限制在(-1*clip, clip)
    jittered_data += batch_data
    return jittered_data

model构建

Feature transform net

with tf.variable_scope(‘transform_net1‘) as sc:#T-net
    transform = input_transform_net(point_cloud, is_training, bn_decay, K=3)
print(‘point cloud=‘,point_cloud)#(32, 1024, 3)
# print(‘input transform=‘,transform)#(32, 3, 3)
point_cloud_transformed = tf.matmul(point_cloud, transform)
# print(‘point_cloud_transformed=‘,point_cloud_transformed)#(32, 1024, 3)

mlp(64,128,1024)

net = tf_util.conv2d(net_transformed, 64, [1,1],
                         padding=‘VALID‘, stride=[1,1],
                         bn=True, is_training=is_training,
                         scope=‘conv3‘, bn_decay=bn_decay)
print(‘net3=‘,net)#(32, 1024, 1, 64)
net = tf_util.conv2d(net, 128, [1,1],
                         padding=‘VALID‘, stride=[1,1],
                         bn=True, is_training=is_training,
                         scope=‘conv4‘, bn_decay=bn_decay)
print(‘net4=‘,net)#(32, 1024, 1, 128)
net = tf_util.conv2d(net, 1024, [1,1],
                         padding=‘VALID‘, stride=[1,1],
                         bn=True, is_training=is_training,
                         scope=‘conv5‘, bn_decay=bn_decay)
print(‘net5=‘,net)#(32, 1024, 1, 1024)

类别投票

实现方法

batch_pred_sum.shape=(?,40) # 每个data对40个类的可能性

pred_val.shape=(?,) # 每个data所属的可能性最大的类

 pred_val = np.argmax(batch_pred_sum, 1)
 #返回沿轴axis最大值的索引,即得到预测值最大的那一类的idx(label)

评估

输出(预测label,真实label)

</dump/pred_label.txt>

4, 4
0, 0
2, 2
8, 8
14, 23
...
<shape_names.txt>

airplane
bathtub
bed
bench
bookshelf
bottle
bowl
car
chair
cone
cup

保存预测错误的图片,并可视化

</dump/xxxx_pred_name.jpg>
命名=第几个预测错误的图片+真实label+预测label

例子 /dump/1028_label_bed_pred_sofa.jpg

三张点云图片,分别是当前点云数据旋转三个不同角度之后的样子

save code

  for i in range(start_idx, end_idx):
        l = current_label[i]
        total_seen_class[l] += 1
        total_correct_class[l] += (pred_val[i-start_idx] == l)
        fout.write(‘%d, %d\n‘ % (pred_val[i-start_idx], l))
        # print(‘!!!!!!!!!!‘,‘%d, %d\n‘ % (pred_val[i-start_idx], l))
        if pred_val[i-start_idx] != l and FLAGS.visu: # ERROR CASE, DUMP!如果预测错了
            img_filename = ‘%d_label_%s_pred_%s.jpg‘ % (error_cnt, SHAPE_NAMES[l],
                                                   SHAPE_NAMES[pred_val[i-start_idx]])
            #第几个预测错误的图片+真实label+预测label
            img_filename = os.path.join(DUMP_DIR, img_filename)
            output_img = pc_util.point_cloud_three_views(np.squeeze(current_data[i, :, :]))
            scipy.misc.imsave(img_filename, output_img)
            error_cnt += 1

画点云图的code

draw_point_cloud()
Input:
points: Nx3 numpy array
Output:
gray image

记录loss,预测精确度

/dump/log_evaluate.txt

eval mean loss: 1.816358
eval accuracy: 0.501216
eval avg class acc: 0.421297
  airplane: 0.980
   bathtub: 0.440
       bed: 0.940
     bench: 0.450
     ...

原文地址:https://www.cnblogs.com/yibeimingyue/p/12005683.html

时间: 2024-08-30 17:02:45

pointNet代码的相关文章

错误和问题解决的成本

问题描写叙述 错误 数据收集 根本原因 版本号   组件:数据修复           在一个实际成本组织中,(平均,先进先出,后进先出) 一个或更 多的下面情况可能发生: 1.导航到物料成本历史表单上的数量信息,与现有量表单的数量不匹配的记录 2. 一些物料前期已计成本的数量与前面的事务处理历史表单的数量不匹配 3. 全部的库存值报表与事务处理值报表不匹配 4. 存货层次成本更新表单的总数量与现有量数量表单不匹配(只在先进先出/后进先出) 5.这些症状的不论什么一个意味着 MMT-CQL不匹配

Xcode 快速开发 代码块 快捷键

Xcode的代码片段(Code Snippets)创建自定义的代码片段,当你重用这些代码片段时,会给你带来很大的方便. 常用的: 1.strong:@property (nonatomic,strong) <#Class#> *<#object#>;2.weak:@property (nonatomic,weak) <#Class#> *<#object#>;3.copy:@property (nonatomic,copy) NSString *<#s

solr分布式索引【实战一、分片配置读取:工具类configUtil.java,读取配置代码片段,配置实例】

1 private static Properties prop = new Properties(); 2 3 private static String confFilePath = "conf" + File.separator + "config.properties";// 配置文件目录 4 static { 5 // 加载properties 6 InputStream is = null; 7 InputStreamReader isr = null;

微信支付PHP SDK —— 公众号支付代码详解

在微信支付 开发者文档页面 下载最新的 php SDK http://mch.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=11_1 这里假设你已经申请完微信支付 1. 微信后台配置  如图 我们先进行测试,所以先把测试授权目录和 测试白名单添加上.测试授权目录是你要发起微信请求的哪个文件所在的目录. 例如jsapi 发起请求一般是jsapi.php所在目录 为测试目录,测试白名单即开发人员的微信号. 正式的支付授权目录不能和测试的一样否则会报错.不填

如何上传代码到github?

如何上传代码到github? 首先你需要一个github账号,所有还没有的话先去注册吧! https://github.com/ 我们使用git需要先安装git工具,这里给出下载地址,下载后一路直接安装即可: https://git-for-windows.github.io/ 1.进入Github首页,点击New repository新建一个项目  2.填写相应信息后点击create即可 Repository name: 仓库名称 Description(可选): 仓库描述介绍 Public,

自己写的代码会写了,还是太渣,复杂度什么的直接报表

原题目是这样子的,本人按照一贯的作风想得很简单 #include<iostream> using namespace std; void H(int n) { while (n > 1) { if (n % 2 == 0) //这一步把取余和除法弄混淆. { cout << n << " "; n = n / 2; } else { cout << n << " "; n = 3 * n + 1; }

category is in invalid format hint微信第三方平台将第三方提交的代码包提交审核出错

微信第三方平台通过接口https://api.weixin.qq.com/wxa/submit_audit?access_token=TOKEN将第三方提交的代码包提交审核时一直返回错误码85008的错误信息: category is in invalid format hint 查了半天是接口提交数据时json_encode时中文不能编码提交 将向微信的提交代码     $this->https_post($url,json_encode($postData)); 改为     $this->

CSS颜色代码大全

CSS颜色代码大全 颜色代码表(一): EEEEEE FFCCFF FF66FF FF00FF DDDDDD FFCCCC FF66CC FF00CC CCCCCC FFCC99 FF6699 FF0099 BBBBBB FFCC66 FF6666 FF0066 AAAAAA FFCC33 FF6633 FF0033 999999 FFCC00 FF6600 FF0000 888888 CCCCFF CC66FF CC00FF 777777 CCCCCC CC66CC CC00CC 666666

mp4网页播放代码,有声音无图像的解决办法~

mp4网页播放代码,有声音无图像的解决办法~ 关于网页播放mp4格式的视频,找了一些插件,这里推荐一下video.js 官方网址:http://www.videojs.com/ github :https://github.com/videojs/video.js/ demo:http://www.videojs.com/downloads/video-js-4.12.5.zip 使用方法: ①引入文件:指派flash播放的swf文件 <link href="//example.com/p