Skip to content

ModelNet

ModelNet(
    name: MODELNET_NAMES = "10",
    train: bool = True,
    base_dir: Optional[str] = None,
    pre_transform: Optional[Callable] = None,
    transform: Optional[Callable] = None,
)

Bases: Dataset

The ModelNet10/40 datasets from the "3D ShapeNets: A Deep Representation for Volumetric Shapes" paper, containing CAD models of 10 and 40 categories, respectively.

Each graph is a mesh with vertex positions pos of shape [N, 3], triangles face of shape [3, num_faces], no edges, and its category in graph_labels. Point clouds are usually sampled from the meshes with SamplePoints.

Note

The raw archives are large (ModelNet10: 0.5 GB, ModelNet40: 2 GB), and processing them takes a few minutes.

Parameters:

Name Type Description Default
name MODELNET_NAMES

"10" for ModelNet10 or "40" for ModelNet40. Default: "10"

'10'
train bool

Whether to load the training or the test split. Default: True

True
base_dir Optional[str]

Directory where to store the dataset. Default: None (.mlx_graphs_data/ in the current directory).

None
pre_transform Optional[Callable]

A transform applied to each graph once, before saving the processed dataset. Default: None

None
transform Optional[Callable]

A transform applied to each graph when accessed. Default: None

None

Example:

from mlx_graphs.datasets import ModelNet
from mlx_graphs.transforms import NormalizeScale, SamplePoints

dataset = ModelNet(
    "10",
    train=True,
    pre_transform=NormalizeScale(),
    transform=SamplePoints(1024),
)
>>> dataset
ModelNet10(num_graphs=3991)
>>> dataset[0]
GraphData(
    edge_index(shape=[2, 0], int32)
    graph_labels(shape=[1], int32)
    pos(shape=[1024, 3], float32))

Attributes:

Name Type Description
categories List[str]

The category names, sorted (the label of a shape is the index of

Source code in mlx_graphs/datasets/modelnet.py
def __init__(
    self,
    name: MODELNET_NAMES = "10",
    train: bool = True,
    base_dir: Optional[str] = None,
    pre_transform: Optional[Callable] = None,
    transform: Optional[Callable] = None,
):
    name = str(name)
    if name not in ("10", "40"):
        raise ValueError(f"name must be '10' or '40', got {name!r}")
    self.modelnet_name = name
    self.train = train
    super().__init__(
        name=f"ModelNet{name}",
        base_dir=base_dir,
        pre_transform=pre_transform,
        transform=transform,
    )

categories property

categories: List[str]

The category names, sorted (the label of a shape is the index of its category).

from mlx_graphs.datasets import ModelNet · mlx_graphs/datasets/modelnet.py