MinkowskiEngine语义分割
MinkowskiEngine语义分割
要运行示例,请安装Open3D与PIP安装open3d-python。
cd /path/to/MinkowskiEngine
python -m examples.indoor
细分酒店房间
运行示例时,将看到一个旅馆房间和房间的语义分割。运行示例时,以交互方式旋转可视化效果。
首先,加载数据并体素化(量化)数据。调用MinkowskiEngine.utils.sparse_quantize进行体素化。
pcd = o3d.read_point_cloud(file_name)
coords = np.array(pcd.points)
feats = np.array(pcd.colors)
quantized_coords = np.floor(coords / voxel_size)
inds = ME.utils.sparse_quantize(quantized_coords)
准备体素化的坐标和特征后,应用MinkowskiEngine.SparseTensor将其包裹起来。此前,通过调用MinkowskiEngine.utils.sparse_collate来创建批处理。此函数采用一组坐标和特征并将其连接起来。还将批处理索引附加到坐标。最后,通过从颜色中减去0.5,对特征进行伪归一化。
# Create a batch, this process is done in a data loader during training in parallel.
batch = [load_file(config.file_name, 0.02)]
coordinates_, featrues_, pcds = list(zip(*batch))
coordinates, features = ME.utils.sparse_collate(coordinates_, featrues_)
# Normalize features and create a sparse tensor
sinput = ME.SparseTensor(features - 0.5, coords=coordinates).to(device)
最后,将稀疏张量前馈到网络中并获得预测。
soutput = model(sinput)
_, pred = soutput.F.max(1)
经过一些后处理。可以为标签着色,并排可视化输入和预测。

运行示例后,权重会自动下载,并且权重目前是Scannet 3D分段基准测试中排名最高的算法。
有关更多详细信息,请参阅完整的室内细分示例。
import os
|
import argparse |
|
|
import numpy as np |
|
|
from urllib.request import urlretrieve |
|
|
try: |
|
|
import open3d as o3d |
|
|
except ImportError: |
|
|
raise ImportError('Please install open3d with `pip install open3d`.') |
|
|
import torch |
|
|
import MinkowskiEngine as ME |
|
|
from examples.minkunet import MinkUNet34C |
|
|
from examples.common import Timer |
|
|
# Check if the weights and file exist and download |
|
|
if not os.path.isfile('weights.pth'): |
|
|
print('Downloading weights and a room ply file...') |
|
|
urlretrieve("http://cvgl.stanford.edu/data2/minkowskiengine/weights.pth", |
|
|
'weights.pth') |
|
|
urlretrieve("http://cvgl.stanford.edu/data2/minkowskiengine/1.ply", '1.ply') |
|
|
parser = argparse.ArgumentParser() |
|
|
parser.add_argument('--file_name', type=str, default='1.ply') |
|
|
parser.add_argument('--weights', type=str, default='weights.pth') |
|
|
parser.add_argument('--use_cpu', action='store_true') |
|
|
CLASS_LABELS = ('wall', 'floor', 'cabinet', 'bed', 'chair', 'sofa', 'table', |
|
|
'door', 'window', 'bookshelf', 'picture', 'counter', 'desk', |
|
|
'curtain', 'refrigerator', 'shower curtain', 'toilet', 'sink', |
|
|
'bathtub', 'otherfurniture') |
|
|
VALID_CLASS_IDS = [ |
|
|
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, 24, 28, 33, 34, 36, 39 |
|
|
] |
|
|
SCANNET_COLOR_MAP = { |
|
|
0: (0., 0., 0.), |
|
|
1: (174., 199., 232.), |
|
|
2: (152., 223., 138.), |
|
|
3: (31., 119., 180.), |
|
|
4: (255., 187., 120.), |
|
|
5: (188., 189., 34.), |
|
|
6: (140., 86., 75.), |
|
|
7: (255., 152., 150.), |
|
|
8: (214., 39., 40.), |
|
|
9: (197., 176., 213.), |
|
|
10: (148., 103., 189.), |
|
|
11: (196., 156., 148.), |
|
|
12: (23., 190., 207.), |
|
|
14: (247., 182., 210.), |
|
|
15: (66., 188., 102.), |
|
|
16: (219., 219., 141.), |
|
|
17: (140., 57., 197.), |
|
|
18: (202., 185., 52.), |
|
|
19: (51., 176., 203.), |
|
|
20: (200., 54., 131.), |
|
|
21: (92., 193., 61.), |
|
|
22: (78., 71., 183.), |
|
|
23: (172., 114., 82.), |
|
|
24: (255., 127., 14.), |
|
|
25: (91., 163., 138.), |
|
|
26: (153., 98., 156.), |
|
|
27: (140., 153., 101.), |
|
|
28: (158., 218., 229.), |
|
|
29: (100., 125., 154.), |
|
|
30: (178., 127., 135.), |
|
|
32: (146., 111., 194.), |
|
|
33: (44., 160., 44.), |
|
|
34: (112., 128., 144.), |
|
|
35: (96., 207., 209.), |
|
|
36: (227., 119., 194.), |
|
|
37: (213., 92., 176.), |
|
|
38: (94., 106., 211.), |
|
|
39: (82., 84., 163.), |
|
|
40: (100., 85., 144.), |
|
|
} |
|
|
def load_file(file_name): |
|
|
pcd = o3d.io.read_point_cloud(file_name) |
|
|
coords = np.array(pcd.points) |
|
|
colors = np.array(pcd.colors) |
|
|
return coords, colors, pcd |
|
|
if __name__ == '__main__': |
|
|
config = parser.parse_args() |
|
|
device = torch.device('cuda' if ( |
|
|
torch.cuda.is_available() and not config.use_cpu) else 'cpu') |
|
|
print(f"Using {device}") |
|
|
# Define a model and load the weights |
|
|
model = MinkUNet34C(3, 20).to(device) |
|
|
model_dict = torch.load(config.weights) |
|
|
model.load_state_dict(model_dict) |
|
|
model.eval() |
|
|
coords, colors, pcd = load_file(config.file_name) |
|
|
# Measure time |
|
|
with torch.no_grad(): |
|
|
voxel_size = 0.02 |
|
|
# Feed-forward pass and get the prediction |
|
|
in_field = ME.TensorField( |
|
|
features=torch.from_numpy(colors).float(), |
|
|
coordinates=ME.utils.batched_coordinates([coords / voxel_size], dtype=torch.float32), |
|
|
quantization_mode=ME.SparseTensorQuantizationMode.UNWEIGHTED_AVERAGE, |
|
|
minkowski_algorithm=ME.MinkowskiAlgorithm.SPEED_OPTIMIZED, |
|
|
device=device, |
|
|
) |
|
|
# Convert to a sparse tensor |
|
|
sinput = in_field.sparse() |
|
|
# Output sparse tensor |
|
|
soutput = model(sinput) |
|
|
# get the prediction on the input tensor field |
|
|
out_field = soutput.slice(in_field) |
|
|
logits = out_field.F |
|
|
_, pred = logits.max(1) |
|
|
pred = pred.cpu().numpy() |
|
|
# Create a point cloud file |
|
|
pred_pcd = o3d.geometry.PointCloud() |
|
|
# Map color |
|
|
colors = np.array([SCANNET_COLOR_MAP[VALID_CLASS_IDS[l]] for l in pred]) |
|
|
pred_pcd.points = o3d.utility.Vector3dVector(coords) |
|
|
pred_pcd.colors = o3d.utility.Vector3dVector(colors / 255) |
|
|
pred_pcd.estimate_normals() |
|
|
# Move the original point cloud |
|
|
pcd.points = o3d.utility.Vector3dVector( |
|
|
np.array(pcd.points) + np.array([0, 5, 0])) |
|
|
# Visualize the input point cloud and the prediction |
|
|
o3d.visualization.draw_geometries([pcd, pred_pcd]) |
MinkowskiEngine语义分割的更多相关文章
- caffe初步实践---------使用训练好的模型完成语义分割任务
caffe刚刚安装配置结束,乘热打铁! (一)环境准备 前面我有两篇文章写到caffe的搭建,第一篇cpu only ,第二篇是在服务器上搭建的,其中第二篇因为硬件环境更佳我们的步骤稍显复杂.其实,第 ...
- R-CNN论文翻译——用于精确物体定位和语义分割的丰富特征层次结构
原文地址 我对深度学习应用于物体检测的开山之作R-CNN的论文进行了主要部分的翻译工作,R-CNN通过引入CNN让物体检测的性能水平上升了一个档次,但该文的想法比较自然原始,估计作者在写作的过程中已经 ...
- 【Keras】基于SegNet和U-Net的遥感图像语义分割
上两个月参加了个比赛,做的是对遥感高清图像做语义分割,美其名曰"天空之眼".这两周数据挖掘课期末project我们组选的课题也是遥感图像的语义分割,所以刚好又把前段时间做的成果重新 ...
- 笔记︱图像语义分割(FCN、CRF、MRF)、论文延伸(Pixel Objectness、)
图像语义分割的意思就是机器自动分割并识别出图像中的内容,我的理解是抠图- 之前在Faster R-CNN中借用了RPN(region proposal network)选择候选框,但是仅仅是候选框,那 ...
- 笔记:基于DCNN的图像语义分割综述
写在前面:一篇魏云超博士的综述论文,完整题目为<基于DCNN的图像语义分割综述>,在这里选择性摘抄和理解,以加深自己印象,同时达到对近年来图像语义分割历史学习和了解的目的,博古才能通今!感 ...
- 人工智能必须要知道的语义分割模型:DeepLabv3+
图像分割是计算机视觉中除了分类和检测外的另一项基本任务,它意味着要将图片根据内容分割成不同的块.相比图像分类和检测,分割是一项更精细的工作,因为需要对每个像素点分类,如下图的街景分割,由于对每个像素点 ...
- 语义分割的简单指南 A Simple Guide to Semantic Segmentation
语义分割是将标签分配给图像中的每个像素的过程.这与分类形成鲜明对比,其中单个标签被分配给整个图片.语义分段将同一类的多个对象视为单个实体.另一方面,实例分段将同一类的多个对象视为不同的单个对象(或实例 ...
- MIT提出精细到头发丝的语义分割技术,打造效果惊艳的特效电影
来自 MIT CSAIL 的研究人员开发了一种精细程度远超传统语义分割方法的「语义软分割」技术,连头发都能清晰地在分割掩码中呈现.在对比实验中,他们的结果远远优于 PSPNet.Mask R-CNN. ...
- 语义分割Semantic Segmentation研究综述
语义分割和实例分割概念 语义分割:对图像中的每个像素都划分出对应的类别,实现像素级别的分类. 实例分割:目标是进行像素级别的分类,而且在具体类别的基础上区别不同的实例. 语义分割(Semantic S ...
随机推荐
- WordPress 函数do_action()详解和应用举例
do_action()函数: 我们经常能看到在一些WordPress函数中调用了do_action()函数,例如get_header(), get_footer()等调用模板的函数中经常调用do_ ...
- Think5之ajax批量删除数据功能
//批量删除学员信息 public function deleteMany() { $id = input('post.'); //判断id是数组还是一个数值 if(is_array($id)){ f ...
- Spring初识及其IOC入门
一.框架 框架是一些类和接口的集合,它一个半成品,已经对基础的代码进行了封装并提供相应的API,开发者在使用框架时直接调用封装好的api可以省去很多代码编写,从而提高工作效率和开发速度. 二.Spri ...
- sqlserver2018 报错恢复
报错: Description: SQL Server 检测到基于一致性的逻辑 I/O 错误 校验和不正确(应为: 0xb2b1af16,但实际为: 0xac9393a2).在文件 'C:\Progr ...
- LA3905流星
题意: 在一个二维平面上有n个流星,每个流星有自己的初始位置和速度,有一个照相机,张相机的可视范围是一个矩形框,左下角(0,0)右上角(w ,h),然后问你相机的矩形内出现的最多的流星数是 ...
- Docker用Dockerfile定制镜像
用Dockerfile定制镜像 镜像的定制实际上就是定制每一层所添加的配置.文件.如果我们可以把每一层修改.安装.构建.操作的命令都写入一个脚本,用这个脚本来构建.定制镜像,那之前提示的无法重复的问题 ...
- VS里的 代码片段(Code snippet)很有用,制作也很简单
工欲善其事必先利其器,而 Visual Studio 就是我们的开发利器. 上一篇文章,介绍了一个很棒的快捷键,如果你还没用过这个快捷键,看完之后应该会豁然开朗.如果你已经熟练的应用它,也会温故而知新 ...
- ES 6 中的箭头函数及用法
ES6标准新增了一种新的函数:Arrow Function(箭头函数). 主要的几种写法如下: 组成: 参数 => 语句, 参数不是1个: (参数,参数2)=>语句 语句不止一条: 参数 ...
- ElasticSearch实战系列十一: ElasticSearch错误问题解决方案
前言 本文主要介绍ElasticSearch在使用过程中出现的各种问题解决思路和办法. ElasticSearch环境安装问题 1,max virtual memory areas vm.max_ma ...
- springboot+Thymeleaf+layui 实现分页
layui分页插件 引入相关的js和css layui:css <link rel="stylesheet" th:href="@{layui/css/layui. ...