本模型适用于OpenVINO
示例代码
#!/usr/bin/python3
from pathlib import Path
from typing import Union
import numpy as np
import matplotlib.pyplot as plt
import openvino as ov
def load_data(point_file: Union[str, Path]):
"""
Load the point cloud data and convert it to ndarray
Parameters:
point_file: string, path of .pts data
Returns:
point_set: point clound represented in np.array format
"""
point_set = np.loadtxt(point_file).astype(np.float32)
# normailization
point_set = point_set - np.expand_dims(np.mean(point_set, axis=0), 0) # center
dist = np.max(np.sqrt(np.sum(point_set**2, axis=1)), 0)
point_set = point_set / dist # scale
return point_set
def visualize(point_set: np.ndarray):
"""
Create a 3D view for data visualization
Parameters:
point_set: np.ndarray, the coordinate data in X Y Z format
"""
fig = plt.figure(dpi=192, figsize=(4, 4))
ax = fig.add_subplot(111, projection="3d")
X = point_set[:, 0]
Y = point_set[:, 2]
Z = point_set[:, 1]
# Scale the view of each axis to adapt to the coordinate data distribution
max_range = np.array([X.max() - X.min(), Y.max() - Y.min(), Z.max() - Z.min()]).max() * 0.5
mid_x = (X.max() + X.min()) * 0.5
mid_y = (Y.max() + Y.min()) * 0.5
mid_z = (Z.max() + Z.min()) * 0.5
ax.set_xlim(mid_x - max_range, mid_x + max_range)
ax.set_ylim(mid_y - max_range, mid_y + max_range)
ax.set_zlim(mid_z - max_range, mid_z + max_range)
plt.tick_params(labelsize=5)
ax.set_xlabel("X", fontsize=10)
ax.set_ylabel("Y", fontsize=10)
ax.set_zlabel("Z", fontsize=10)
return ax
core = ov.Core()
# Read model
model = core.read_model(model="chair_100.xml")
point_data_path = Path(".") / "chair.pts"
points = load_data(str(point_data_path))
X = points[:, 0]
Y = points[:, 2]
Z = points[:, 1]
ax = visualize(points)
ax.scatter3D(X, Y, Z, s=5, cmap="jet", marker="o", label="chair")
ax.set_title("3D Visualization")
plt.legend(loc="upper right", fontsize=8)
plt.show(block=False)
# Parts of a chair
classes = ["back", "seat", "leg", "arm"]
# Preprocess the input data
point = points.transpose(1, 0)
point = np.expand_dims(point, axis=0)
# Print info about model input and output shape
print(f"input shape: {model.input(0).partial_shape}")
print(f"output shape: {model.output(0).partial_shape}")
##device = "CPU"
device = "GPU"
# Inference
compiled_model = core.compile_model(model=model, device_name=device)
output_layer = compiled_model.output(0)
result = compiled_model([point])[output_layer]
# Find the label map for all points of chair with highest confidence
pred = np.argmax(result[0], axis=1)
ax = visualize(point)
for i, name in enumerate([0, 1, 2, 3]):
XCur = []
YCur = []
ZCur = []
for j, nameCur in enumerate(pred):
if name == nameCur:
XCur.append(X[j])
YCur.append(Y[j])
ZCur.append(Z[j])
XCur = np.array(XCur)
YCur = np.array(YCur)
ZCur = np.array(ZCur)
# add current point of the part
ax.scatter(XCur, YCur, ZCur, s=5, cmap="jet", marker="o", label=classes[i])
ax.set_title("3D Segmentation Visualization")
plt.legend(loc="upper right", fontsize=8)
plt.show()
运行结果
/home/rainhenry/AIGC/20251208_3dpoint/model/./../infer2.py:71: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
ax.scatter3D(X, Y, Z, s=5, cmap="jet", marker="o", label="chair")
input shape: [1,3,?]
output shape: [1,?,4]
/home/rainhenry/AIGC/20251208_3dpoint/model/./../infer2.py:113: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
ax.scatter(XCur, YCur, ZCur, s=5, cmap="jet", marker="o", label=classes[i])
然后会有两个图表:

环境依赖参考
Package Version
------------------ -----------
contourpy 1.3.3
cycler 0.12.1
filelock 3.19.1
fonttools 4.61.0
fsspec 2025.9.0
Jinja2 3.1.6
kiwisolver 1.4.9
MarkupSafe 2.1.5
matplotlib 3.10.7
mpmath 1.3.0
networkx 3.5
numpy 2.2.6
openvino 2025.4.0
openvino-telemetry 2025.2.0
packaging 25.0
pillow 12.0.0
pip 24.0
pyparsing 3.2.5
python-dateutil 2.9.0.post0
setuptools 70.2.0
six 1.17.0
sympy 1.14.0
torch 2.9.1+cpu
tqdm 4.67.1
typing_extensions 4.15.0
其他参考
https://github.com/openvinotoolkit/openvino_notebooks/blob/latest/notebooks/3D-segmentation-point-clouds/3D-segmentation-point-clouds.ipynb