MinkowskiEngine demo ModelNet40分类
本文将看一个简单的演示示例,该示例训练用于分类的3D卷积神经网络。输入是稀疏张量,卷积也定义在稀疏张量上。该网络是以下体系结构的扩展,但具有剩余的块和更多的层。

创建ModelNet40数据加载器
首先,需要创建一个数据加载器,以返回网格的稀疏张量表示。如果仅使用顶点,则3D模型的网格表示可能会稀疏。
首先以相同的密度采样点。
def resample_mesh(mesh_cad, density=1):
‘’’
https://chrischoy.github.io/research/barycentric-coordinate-for-mesh-sampling/
Samples point cloud on the surface of the model defined as vectices and
faces. This function uses vectorized operations so fast at the cost of some
memory.

param mesh_cad: low-polygon triangle mesh in o3d.geometry.TriangleMesh
param density: density of the point cloud per unit area
param return_numpy: return numpy format or open3d pointcloud format
return resampled point cloudReference :[1] Barycentric coordinate system\begin{align}P = (1 - \sqrt{r_1})A + \sqrt{r_1} (1 - r_2) B + \sqrt{r_1} r_2 C\end{align}
'''
faces = np.array(mesh_cad.triangles).astype(int)
vertices = np.array(mesh_cad.vertices)vec_cross = np.cross(vertices[faces[:, 0], :] - vertices[faces[:, 2], :],vertices[faces[:, 1], :] - vertices[faces[:, 2], :])
face_areas = np.sqrt(np.sum(vec_cross**2, 1))n_samples = (np.sum(face_areas) * density).astype(int)n_samples_per_face = np.ceil(density * face_areas).astype(int)
floor_num = np.sum(n_samples_per_face) - n_samples
if floor_num > 0:indices = np.where(n_samples_per_face > 0)[0]floor_indices = np.random.choice(indices, floor_num, replace=True)n_samples_per_face[floor_indices] -= 1n_samples = np.sum(n_samples_per_face)# Create a vector that contains the face indices
sample_face_idx = np.zeros((n_samples,), dtype=int)
acc = 0
for face_idx, _n_sample in enumerate(n_samples_per_face):sample_face_idx[acc:acc + _n_sample] = face_idxacc += _n_sampler = np.random.rand(n_samples, 2)
A = vertices[faces[sample_face_idx, 0], :]
B = vertices[faces[sample_face_idx, 1], :]
C = vertices[faces[sample_face_idx, 2], :]P = (1 - np.sqrt(r[:, 0:1])) * A + \np.sqrt(r[:, 0:1]) * (1 - r[:, 1:]) * B + \np.sqrt(r[:, 0:1]) * r[:, 1:] * Creturn P

上面的函数将以相同的密度对网格上的点进行采样。接下来,在量化步骤之前经历了一系列数据扩充步骤。
数据扩充
稀疏张量由两个部分组成:1)坐标和2)与这些坐标关联的特征。必须对这两个组件都应用数据增强,以最大化固定数据集的效用,并使网络对噪声具有鲁棒性。
这在图像数据增强中并不是什么新鲜事。对图像应用随机平移,剪切,缩放,所有这些都是坐标数据扩充。颜色失真(例如色平移,颜色通道上的高斯噪声,色相饱和度增强)都具有数据增强功能。
由于在ModelNet40数据集中只有坐标作为数据,将仅应用坐标数据增强。
class RandomRotation:

def _M(self, axis, theta):return expm(np.cross(np.eye(3), axis / norm(axis) * theta))def __call__(self, coords, feats):R = self._M(np.random.rand(3) - 0.5, 2 * np.pi * (np.random.rand(1) - 0.5))return coords @ R, feats

class RandomScale:

def __init__(self, min, max):self.scale = max - minself.bias = mindef __call__(self, coords, feats):s = self.scale * np.random.rand(1) + self.biasreturn coords * s, feats

class RandomShear:

def __call__(self, coords, feats):T = np.eye(3) + np.random.randn(3, 3)return coords @ T, feats

class RandomTranslation:

def __call__(self, coords, feats):trans = 0.05 * np.random.randn(1, 3)return coords + trans, feats

训练ResNet进行ModelNet40分类
主要训练功能很简单。没有使用基于时间的训练,而是使用了基于迭代的训练。与基于时间的训练相比,基于迭代的训练的一个优势在于,训练逻辑独立于批处理大小。
def train(net, device, config):
optimizer = optim.SGD(
net.parameters(),
lr=config.lr,
momentum=config.momentum,
weight_decay=config.weight_decay)
scheduler = optim.lr_scheduler.ExponentialLR(optimizer, 0.95)

crit = torch.nn.CrossEntropyLoss()

net.train()
train_iter = iter(train_dataloader)
val_iter = iter(val_dataloader)
logging.info(f'LR: {scheduler.get_lr()}')
for i in range(curr_iter, config.max_iter):s = time()data_dict = train_iter.next()d = time() - soptimizer.zero_grad()sin = ME.SparseTensor(data_dict['feats'],data_dict['coords'].int()).to(device)sout = net(sin)loss = crit(sout.F, data_dict['labels'].to(device))loss.backward()optimizer.step()t = time() - s...

运行示例
集成所有代码块时,可以运行自主ModelNet40分类网络。
python -m examples.modelnet40 --batch_size 128 --stat_freq 100
完整的代码可以在example / modelnet40.py找到。
https://github.com/NVIDIA/MinkowskiEngine/blob/master/examples/modelnet40.py
警告
ModelNet40数据加载和体素化是训练中最耗时的部分。因此,该示例将所有ModelNet40数据缓存到内存中,这将占用大约10G的内存。

MinkowskiEngine demo ModelNet40分类相关推荐

  1. sumo添加车辆_sumo demo 我们通过使用交通仿真软件SUMO(Simulation of 联合开发网 - pudn.com...

    sumo demo 所属分类:Windows编程 开发工具:C/C++ 文件大小:3KB 下载次数:15 上传日期:2019-03-07 16:12:12 上 传 者:tonythetiger1110 ...

  2. 复现pointnet++在windows10+pytorch1.x上的分类,来自课程白勇老师的点云处理精讲

    1 序言   未设置虚拟机和linux环境,使用了anaconda 创建python环境,根据白勇老师的课程进行学习,本人之前未系统学过python,边摸索边学习.后面发现白老师给的代码和视频有一些差 ...

  3. FatNet:一个用于三维点云处理的特征关注网络

    点击上方"3D视觉工坊",选择"星标" 干货第一时间送达 小黑导读 论文是学术研究的精华和未来发展的明灯.小黑决心每天为大家带来经典或者最新论文的解读和分享,旨 ...

  4. 14.7倍推理加速、18.9倍存储节省!北航、商汤、UCSD提出首个点云二值网络 | ICLR 2021...

    允中 编辑整理 量子位 报道 | 公众号 QbitAI 编者按: 无论是在自动驾驶场景中,还是在手持移动设备上,基于点云的深度学习模型应用越来越广泛. 但这些离线边缘场景自身的限制,给模型的推理.存储 ...

  5. 【AI视野·今日CV 计算机视觉论文速览 第165期】Mon, 21 Oct 2019

    AI视野·今日CS.CV 计算机视觉论文速览 Mon, 21 Oct 2019 Totally 34 papers ?上期速览✈更多精彩请移步主页 Interesting: ?****基于立体视觉的三 ...

  6. 设计方法(原型法、敏捷开发)

    原型法和敏捷开发 [快速]原型法 就是按照客户写的demo. 分类 1. 抛弃型原型 - demo的需求客户确认后就抛弃. a)探索性 - 为了确认需求: b)实验型 - 为了确认规格说明是否可靠. ...

  7. 【转载】搞懂PointNet++,这篇文章就够了!

    论文标题:PointNet++: Deep Hierarchical Feature Learning on Point Sets in a Metric Space 1 motivation 从名字 ...

  8. jQuery easing

    properties:一组包含作为动画属性和终值的样式属性和及其值的集合 duration(可选):动画执行时间,其值可以是三种预定速度之一的字符串("slow", "n ...

  9. python 自动化办公 书_Python自动化办公

    "虽然辛苦,我还是会选择那种滚烫的人生. 独白 今儿有个集美找我,她之前在上海做金融量化分析.后来~"告老还乡",emmm..开玩笑嘿,她家里希望她回家考公务员,So,已 ...

最新文章

  1. Hololens2-OpenXR开发(二)-实现通讯
  2. 最前沿:大规模深度强化学习的发展
  3. EOJ Monthly 2018.11 D. 猜价格
  4. 5G 标准 — R16
  5. HDMI_VGA_CBVS同时显示
  6. Python 中的万能之王 Lambda 函数
  7. C++之operator关键字(重载操作符) 使用总结
  8. hdfs fsck命令查看HDFS文件对应的文件块信息(Block)和位置信息(Locations)
  9. 微信各地服务器如何同步,彻底搞清楚并实现多端同步登录
  10. 自己的父母,能把钱交给他们存吗?
  11. 华为STP相关功能配置
  12. 区块链:关键阻力的突破会带来持续的积极情绪
  13. PHP TCPDF导出支持中文的pdf
  14. 华硕笔记本电池0%充不进电_华硕笔记本电池不充电怎么办
  15. 让老主板更新驱动程序不再拒绝新网卡(转)
  16. bootstrap 检验 法 原理_三种中介效应检验方法及操作步骤 - spssau
  17. 神雕侠侣服务器维修时间,《神雕侠侣》2021年3月11日更新维护新服开启公告
  18. Excel自动插入jpg图片或png图片 VBA 工具 模块
  19. Android 11版本号仍有甜点名称 只是不再公开:红丝绒蛋糕
  20. 支付宝配置沙箱测试android,个人开发者使用支付宝沙箱环境进行代码调试

热门文章

  1. 2022-2028年中国自主可控行业深度调研及投资前景预测报告(全卷)
  2. 2022-2028年中国铁路机车行业投资分析及前景预测报告
  3. Git 错误提交后该如何回滚操作
  4. Go 学习笔记(61)— Go 高阶函数、函数作为一等公民(函数作为输入参数、返回值、变量)的写法
  5. 每个人都应该有一个梦想
  6. virtualenv创建虚拟环境为主_多版本
  7. PyTorch 高级实战教程:基于 BI-LSTM CRF 实现命名实体识别和中文分词
  8. Adam那么棒,为什么还对SGD念念不忘 (1) —— 一个框架看懂优化算法
  9. Java中类、常量、变量、方法名等命名规则
  10. LeetCode简单题之基于排列构建数组