Skip to content

ShapeNet

ShapeNet(
    categories: Optional[Union[str, List[str]]] = None,
    include_normals: bool = True,
    split: SHAPENET_SPLITS = "trainval",
    base_dir: Optional[str] = None,
    pre_transform: Optional[Callable] = None,
    transform: Optional[Callable] = None,
)

Bases: Dataset

The ShapeNet part level segmentation dataset from the "A Scalable Active Framework for Region Annotation in 3D Shape Collections" paper, containing about 17,000 3D shape point clouds from 16 shape categories. Each category is annotated with 2 to 6 parts (50 part labels in total).

Each graph is a point cloud with positions pos of shape [N, 3], the normals in node_features (if include_normals), the part label of each point in node_labels, its category index in category and no edges.

The original download (shapenet.cs.stanford.edu) is offline: the archive is downloaded from a mirror on the Hugging Face Hub and checked against its SHA-256 hash.

Parameters:

Name Type Description Default
categories Optional[Union[str, List[str]]]

The category names (see category_ids) to include. Default: None (all of them).

None
include_normals bool

Whether to store the normals as node features. Default: True

True
split SHAPENET_SPLITS

"train", "val", "test" or "trainval". Default: "trainval"

'trainval'
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 ShapeNet

dataset = ShapeNet(categories=["Airplane"], split="train")
>>> dataset[0]
GraphData(
    edge_index(shape=[2, 0], int32)
    node_features(shape=[2518, 3], float32)
    node_labels(shape=[2518], int32)
    pos(shape=[2518, 3], float32)
    category(shape=[1], int32))

Attributes:

Name Type Description
num_classes int

The number of part labels (50).

Source code in mlx_graphs/datasets/shapenet.py
def __init__(
    self,
    categories: Optional[Union[str, List[str]]] = None,
    include_normals: bool = True,
    split: SHAPENET_SPLITS = "trainval",
    base_dir: Optional[str] = None,
    pre_transform: Optional[Callable] = None,
    transform: Optional[Callable] = None,
):
    if categories is None:
        categories = list(self.category_ids)
    if isinstance(categories, str):
        categories = [categories]
    unknown = [c for c in categories if c not in self.category_ids]
    if unknown:
        raise ValueError(f"Unknown categories {unknown}")
    if split not in ("train", "val", "test", "trainval"):
        raise ValueError(
            f"Split {split} found, but expected either train, val, trainval "
            "or test"
        )
    self.categories = list(categories)
    self.include_normals = include_normals
    self.split = split
    super().__init__(
        name="ShapeNet",
        base_dir=base_dir,
        pre_transform=pre_transform,
        transform=transform,
    )
    if not include_normals:
        for graph in self.graphs:
            graph.node_features = None
    mask = np.zeros((len(self.seg_classes), 50), dtype=bool)
    for i, labels in enumerate(self.seg_classes.values()):
        mask[i, labels] = True
    self.y_mask = mx.array(mask)

num_classes property

num_classes: int

The number of part labels (50).

from mlx_graphs.datasets import ShapeNet · mlx_graphs/datasets/shapenet.py