作者: David Griffiths
创建日期: 2020/05/25
最后修改: 2024/01/09
描述: PointNet在ModelNet10分类中的实现。
无序的3D点集(即点云)的分类、检测和分割是计算机视觉中的核心问题。此示例实现了开创性的点云深度学习论文PointNet (Qi et al., 2017)。有关PointNet的详细介绍,请参见这篇博客文章。
如果使用colab,请首先通过!pip install trimesh
安装trimesh。
import os
import glob
import trimesh
import numpy as np
from tensorflow import data as tf_data
from keras import ops
import keras
from keras import layers
from matplotlib import pyplot as plt
keras.utils.set_random_seed(seed=42)
我们使用ModelNet10模型数据集,这是ModelNet40数据集的较小10类版本。首先下载数据:
DATA_DIR = keras.utils.get_file(
"modelnet.zip",
"http://3dvision.princeton.edu/projects/2014/3DShapeNets/ModelNet10.zip",
extract=True,
)
DATA_DIR = os.path.join(os.path.dirname(DATA_DIR), "ModelNet10")
从 http://3dvision.princeton.edu/projects/2014/3DShapeNets/ModelNet10.zip 下载数据
0/473402300 ━━━━━━━━━━━━━━━━━━━━ 0s 0s/step
8192/473402300 ━━━━━━━━━━━━━━━━━━━━ 1:06:44 8us/step
40960/473402300 ━━━━━━━━━━━━━━━━━━━━ 26:17 3us/step
90112/473402300 ━━━━━━━━━━━━━━━━━━━━ 17:49 2us/step
188416/473402300 ━━━━━━━━━━━━━━━━━━━━ 11:20 1us/step
385024/473402300 ━━━━━━━━━━━━━━━━━━━━ 6:55 1us/step
786432/473402300 ━━━━━━━━━━━━━━━━━━━━ 4:03 1us/step
1581056/473402300 ━━━━━━━━━━━━━━━━━━━━ 2:21 0us/step
3170304/473402300 ━━━━━━━━━━━━━━━━━━━━ 1:20 0us/step
6004736/473402300 ━━━━━━━━━━━━━━━━━━━━ 47s 0us/step
8880128/473402300 ━━━━━━━━━━━━━━━━━━━━ 35s 0us/step
11902976/473402300 ━━━━━━━━━━━━━━━━━━━━ 28s 0us/step
14925824/473402300 ━━━━━━━━━━━━━━━━━━━━ 24s 0us/step
17915904/473402300 ━━━━━━━━━━━━━━━━━━━━ 22s 0us/step
21020672/473402300 ━━━━━━━━━━━━━━━━━━━━ 20s 0us/step
23977984/473402300 ━━━━━━━━━━━━━━━━━━━━ 18s 0us/step
26861568/473402300 ━━━━━━━━━━━━━━━━━━━━ 17s 0us/step
29958144/473402300 ━━━━━━━━━━━━━━━━━━━━ 16s 0us/step
33071104/473402300 ━━━━━━━━━━━━━━━━━━━━ 16s 0us/step
36175872/473402300 ━━━━━━━━━━━━━━━━━━━━ 15s 0us/step
39206912/473402300 ━━━━━━━━━━━━━━━━━━━━ 14s 0us/step
41902080/473402300 ━━━━━━━━━━━━━━━━━━━━ 14s 0us/step
45015040/473402300 ━━━━━━━━━━━━━━━━━━━━ 14s 0us/step
48021504/473402300 ━━━━━━━━━━━━━━━━━━━━ 13s 0us/step
51003392/473402300 ━━━━━━━━━━━━━━━━━━━━ 13s 0us/step
53960704/473402300 ━━━━━━━━━━━━━━━━━━━━ 13s 0us/step
56803328/473402300 ━━━━━━━━━━━━━━━━━━━━ 12s 0us/step
59834368/473402300 ━━━━━━━━━━━━━━━━━━━━ 12s 0us/step
62750720/473402300 ━━━━━━━━━━━━━━━━━━━━ 12s 0us/step
65839104/473402300 ━━━━━━━━━━━━━━━━━━━━ 12s 0us/step
68698112/473402300 ━━━━━━━━━━━━━━━━━━━━ 11s 0us/step
71385088/473402300 ━━━━━━━━━━━━━━━━━━━━ 11s 0us/step
74432512/473402300 ━━━━━━━━━━━━━━━━━━━━ 11s 0us/step
77365248/473402300 ━━━━━━━━━━━━━━━━━━━━ 11s 0us/step
80363520/473402300 ━━━━━━━━━━━━━━━━━━━━ 11s 0us/step
83156992/473402300 ━━━━━━━━━━━━━━━━━━━━ 11s 0us/step
86179840/473402300 ━━━━━━━━━━━━━━━━━━━━ 10s 0us/step
89300992/473402300 ━━━━━━━━━━━━━━━━━━━━ 10s 0us/step
92282880/473402300 ━━━━━━━━━━━━━━━━━━━━ 10s 0us/step
95371264/473402300 ━━━━━━━━━━━━━━━━━━━━ 10s 0us/step
98410496/473402300 ━━━━━━━━━━━━━━━━━━━━ 10s 0us/step
101130240/473402300 ━━━━━━━━━━━━━━━━━━━━ 10s 0us/step
104169472/473402300 ━━━━━━━━━━━━━━━━━━━━ 10s 0us/step
107192320/473402300 ━━━━━━━━━━━━━━━━━━━━ 9s 0us/step
110297088/473402300 ━━━━━━━━━━━━━━━━━━━━ 9s 0us/step
113344512/473402300 ━━━━━━━━━━━━━━━━━━━━ 9s 0us/step
116391936/473402300 ━━━━━━━━━━━━━━━━━━━━ 9s 0us/step
119513088/473402300 ━━━━━━━━━━━━━━━━━━━━ 9s 0us/step
122626048/473402300 ━━━━━━━━━━━━━━━━━━━━ 9s 0us/step
125313024/473402300 ━━━━━━━━━━━━━━━━━━━━ 9s 0us/step
128368640/473402300 ━━━━━━━━━━━━━━━━━━━━ 9s 0us/step
131432448/473402300 ━━━━━━━━━━━━━━━━━━━━ 8s 0us/step
134520832/473402300 ━━━━━━━━━━━━━━━━━━━━ 8s 0us/step
137560064/473402300 ━━━━━━━━━━━━━━━━━━━━ 8s 0us/step
140648448/473402300 ━━━━━━━━━━━━━━━━━━━━ 8s 0us/step
143720448/473402300 ━━━━━━━━━━━━━━━━━━━━ 8s 0us/step
146808832/473402300 ━━━━━━━━━━━━━━━━━━━━ 8s 0us/step
149864448/473402300 ━━━━━━━━━━━━━━━━━━━━ 8s 0us/step
152592384/473402300 ━━━━━━━━━━━━━━━━━━━━ 8s 0us/step
155623424/473402300 ━━━━━━━━━━━━━━━━━━━━ 8s 0us/step
158728192/473402300 ━━━━━━━━━━━━━━━━━━━━ 8s 0us/step
161783808/473402300 ━━━━━━━━━━━━━━━━━━━━ 7s 0us/step
164806656/473402300 ━━━━━━━━━━━━━━━━━━━━ 7s 0us/step
167895040/473402300 ━━━━━━━━━━━━━━━━━━━━ 7s 0us/step
170975232/473402300 ━━━━━━━━━━━━━━━━━━━━ 7s 0us/step
174071808/473402300 ━━━━━━━━━━━━━━━━━━━━ 7s 0us/step
177119232/473402300 ━━━━━━━━━━━━━━━━━━━━ 7s 0us/step
180166656/473402300 ━━━━━━━━━━━━━━━━━━━━ 7s 0us/step
182976512/473402300 ━━━━━━━━━━━━━━━━━━━━ 7s 0us/step
185884672/473402300 ━━━━━━━━━━━━━━━━━━━━ 7s 0us/step
188932096/473402300 ━━━━━━━━━━━━━━━━━━━━ 7s 0us/step
192028672/473402300 ━━━━━━━━━━━━━━━━━━━━ 7s 0us/step
195117056/473402300 ━━━━━━━━━━━━━━━━━━━━ 6s 0us/step
198189056/473402300 ━━━━━━━━━━━━━━━━━━━━ 6s 0us/step
201302016/473402300 ━━━━━━━━━━━━━━━━━━━━ 6s 0us/step
204406784/473402300 ━━━━━━━━━━━━━━━━━━━━ 6s 0us/step
207470592/473402300 ━━━━━━━━━━━━━━━━━━━━ 6s 0us/step
210575360/473402300 ━━━━━━━━━━━━━━━━━━━━ 6s 0us/step
213581824/473402300 ━━━━━━━━━━━━━━━━━━━━ 6s 0us/step
216268800/473402300 ━━━━━━━━━━━━━━━━━━━━ 6s 0us/step
218374144/473402300 ━━━━━━━━━━━━━━━━━━━━ 6s 0us/step
220569600/473402300 ━━━━━━━━━━━━━━━━━━━━ 6s 0us/step
222363648/473402300 ━━━━━━━━━━━━━━━━━━━━ 6s 0us/step
225345536/473402300 ━━━━━━━━━━━━━━━━━━━━ 6s 0us/step
228425728/473402300 ━━━━━━━━━━━━━━━━━━━━ 6s 0us/step
231473152/473402300 ━━━━━━━━━━━━━━━━━━━━ 5s 0us/step
234577920/473402300 ━━━━━━━━━━━━━━━━━━━━ 5s 0us/step
237690880/473402300 ━━━━━━━━━━━━━━━━━━━━ 5s 0us/step
240746496/473402300 ━━━━━━━━━━━━━━━━━━━━ 5s 0us/step
243834880/473402300 ━━━━━━━━━━━━━━━━━━━━ 5s 0us/step
246898688/473402300 ━━━━━━━━━━━━━━━━━━━━ 5s 0us/step
249954304/473402300 ━━━━━━━━━━━━━━━━━━━━ 5s 0us/step
252936192/473402300 ━━━━━━━━━━━━━━━━━━━━ 5s 0us/step
255672320/473402300 ━━━━━━━━━━━━━━━━━━━━ 5s 0us/step
258695168/473402300 ━━━━━━━━━━━━━━━━━━━━ 5s 0us/step
261734400/473402300 ━━━━━━━━━━━━━━━━━━━━ 5s 0us/step
264847360/473402300 ━━━━━━━━━━━━━━━━━━━━ 5s 0us/step
267919360/473402300 ━━━━━━━━━━━━━━━━━━━━ 4s 0us/step
271015936/473402300 ━━━━━━━━━━━━━━━━━━━━ 4s 0us/step
273768448/473402300 ━━━━━━━━━━━━━━━━━━━━ 4s 0us/step
276840448/473402300 ━━━━━━━━━━━━━━━━━━━━ 4s 0us/step
279625728/473402300 ━━━━━━━━━━━━━━━━━━━━ 4s 0us/step
282525696/473402300 ━━━━━━━━━━━━━━━━━━━━ 4s 0us/step
285581312/473402300 ━━━━━━━━━━━━━━━━━━━━ 4s 0us/step
288645120/473402300 ━━━━━━━━━━━━━━━━━━━━ 4s 0us/step
291733504/473402300 ━━━━━━━━━━━━━━━━━━━━ 4s 0us/step
294682624/473402300 ━━━━━━━━━━━━━━━━━━━━ 4s 0us/step
297795584/473402300 ━━━━━━━━━━━━━━━━━━━━ 4s 0us/step
300851200/473402300 ━━━━━━━━━━━━━━━━━━━━ 4s 0us/step
303955968/473402300 ━━━━━━━━━━━━━━━━━━━━ 4s 0us/step
306798592/473402300 ━━━━━━━━━━━━━━━━━━━━ 3s 0us/step
309846016/473402300 ━━━━━━━━━━━━━━━━━━━━ 3s 0us/step
312926208/473402300 ━━━━━━━━━━━━━━━━━━━━ 3s 0us/step
315990016/473402300 ━━━━━━━━━━━━━━━━━━━━ 3s 0us/step
319053824/473402300 ━━━━━━━━━━━━━━━━━━━━ 3s 0us/step
322134016/473402300 ━━━━━━━━━━━━━━━━━━━━ 3s 0us/step
325099520/473402300 ━━━━━━━━━━━━━━━━━━━━ 3s 0us/step
328187904/473402300 ━━━━━━━━━━━━━━━━━━━━ 3s 0us/step
331251712/473402300 ━━━━━━━━━━━━━━━━━━━━ 3s 0us/step
334364672/473402300 ━━━━━━━━━━━━━━━━━━━━ 3s 0us/step
337477632/473402300 ━━━━━━━━━━━━━━━━━━━━ 3s 0us/step
340598784/473402300 ━━━━━━━━━━━━━━━━━━━━ 3s 0us/step
343130112/473402300 ━━━━━━━━━━━━━━━━━━━━ 3s 0us/step
345554944/473402300 ━━━━━━━━━━━━━━━━━━━━ 3s 0us/step
347570176/473402300 ━━━━━━━━━━━━━━━━━━━━ 2s 0us/step
350224384/473402300 ━━━━━━━━━━━━━━━━━━━━ 2s 0us/step
352436224/473402300 ━━━━━━━━━━━━━━━━━━━━ 2s 0us/step
355393536/473402300 ━━━━━━━━━━━━━━━━━━━━ 2s 0us/step
357179392/473402300 ━━━━━━━━━━━━━━━━━━━━ 2s 0us/step
359858176/473402300 ━━━━━━━━━━━━━━━━━━━━ 2s 0us/step
362045440/473402300 ━━━━━━━━━━━━━━━━━━━━ 2s 0us/step
364281856/473402300 ━━━━━━━━━━━━━━━━━━━━ 2s 0us/step
364298240/473402300 ━━━━━━━━━━━━━━━━━━━━ 2s 0us/step
364306432/473402300 ━━━━━━━━━━━━━━━━━━━━ 2s 0us/step
364314624/473402300 ━━━━━━━━━━━━━━━━━━━━ 2s 0us/step
364322816/473402300 ━━━━━━━━━━━━━━━━━━━━ 2s 0us/step
364331008/473402300 ━━━━━━━━━━━━━━━━━━━━ 2s 0us/step
364339200/473402300 ━━━━━━━━━━━━━━━━━━━━ 2s 0us/step
364347392/473402300 ━━━━━━━━━━━━━━━━━━━━ 2s 0us/step
364355584/473402300 ━━━━━━━━━━━━━━━━━━━━ 2s 0us/step
364363776/473402300 ━━━━━━━━━━━━━━━━━━━━ 2s 0us/step
364371968/473402300 ━━━━━━━━━━━━━━━━━━━━ 2s 0us/step
364380160/473402300 ━━━━━━━━━━━━━━━━━━━━ 2s 0us/step
364396544/473402300 ━━━━━━━━━━━━━━━━━━━━ 2s 0us/step
364445696/473402300 ━━━━━━━━━━━━━━━━━━━━ 2s 0us/step
364601344/473402300 ━━━━━━━━━━━━━━━━━━━━ 2s 0us/step
365084672/473402300 ━━━━━━━━━━━━━━━━━━━━ 2s 0us/step
366510080/473402300 ━━━━━━━━━━━━━━━━━━━━ 2s 0us/step
369491968/473402300 ━━━━━━━━━━━━━━━━━━━━ 2s 0us/step
372400128/473402300 ━━━━━━━━━━━━━━━━━━━━ 2s 0us/step
375521280/473402300 ━━━━━━━━━━━━━━━━━━━━ 2s 0us/step
378535936/473402300 ━━━━━━━━━━━━━━━━━━━━ 2s 0us/step
381558784/473402300 ━━━━━━━━━━━━━━━━━━━━ 2s 0us/step
384475136/473402300 ━━━━━━━━━━━━━━━━━━━━ 2s 0us/step
387571712/473402300 ━━━━━━━━━━━━━━━━━━━━ 2s 0us/step
390463488/473402300 ━━━━━━━━━━━━━━━━━━━━ 2s 0us/step
393551872/473402300 ━━━━━━━━━━━━━━━━━━━━ 2s 0us/step
396632064/473402300 ━━━━━━━━━━━━━━━━━━━━ 2s 0us/step
399704064/473402300 ━━━━━━━━━━━━━━━━━━━━ 1s 0us/step
402767872/473402300 ━━━━━━━━━━━━━━━━━━━━ 1s 0us/step
405790720/473402300 ━━━━━━━━━━━━━━━━━━━━ 1s 0us/step
408854528/473402300 ━━━━━━━━━━━━━━━━━━━━ 1s 0us/step
411975680/473402300 ━━━━━━━━━━━━━━━━━━━━ 1s 0us/step
414982144/473402300 ━━━━━━━━━━━━━━━━━━━━ 1s 0us/step
418045952/473402300 ━━━━━━━━━━━━━━━━━━━━ 1s 0us/step
421167104/473402300 ━━━━━━━━━━━━━━━━━━━━ 1s 0us/step
423878656/473402300 ━━━━━━━━━━━━━━━━━━━━ 1s 0us/step
426999808/473402300 ━━━━━━━━━━━━━━━━━━━━ 1s 0us/step
430112768/473402300 ━━━━━━━━━━━━━━━━━━━━ 1s 0us/step
433053696/473402300 ━━━━━━━━━━━━━━━━━━━━ 1s 0us/step
436125696/473402300 ━━━━━━━━━━━━━━━━━━━━ 0s 0us/step
439189504/473402300 ━━━━━━━━━━━━━━━━━━━━ 0s 0us/step
442286080/473402300 ━━━━━━━━━━━━━━━━━━━━ 0s 0us/step
445063168/473402300 ━━━━━━━━━━━━━━━━━━━━ 0s 0us/step
448118784/473402300 ━━━━━━━━━━━━━━━━━━━━ 0s 0us/step
451166208/473402300 ━━━━━━━━━━━━━━━━━━━━ 0s 0us/step
454262784/473402300 ━━━━━━━━━━━━━━━━━━━━ 0s 0us/step
457293824/473402300 ━━━━━━━━━━━━━━━━━━━━ 0s 0us/step
460275712/473402300 ━━━━━━━━━━━━━━━━━━━━ 0s 0us/step
463011840/473402300 ━━━━━━━━━━━━━━━━━━━━ 0s 0us/step
466018304/473402300 ━━━━━━━━━━━━━━━━━━━━ 0s 0us/step
469057536/473402300 ━━━━━━━━━━━━━━━━━━━━ 0s 0us/step
472145920/473402300 ━━━━━━━━━━━━━━━━━━━━ 0s 0us/step
473402300/473402300 ━━━━━━━━━━━━━━━━━━━━ 12s 0us/step
我们可以使用 trimesh
包来读取和可视化 .off
网格文件。
mesh = trimesh.load(os.path.join(DATA_DIR, "chair/train/chair_0001.off")) # 加载网格文件
mesh.show() # 显示网格