inferer
Abstract base class for test-time inference strategies.
Classes:
-
InfererβBase class for test-time inference strategies.
Inferer [source] ΒΆ
Base class for test-time inference strategies.
An Inferer decouples how a model is run at test time from the model itself. The model only knows how to map a batch of points to per-point logits; the Inferer decides whether that happens in a single forward pass, over cropped windows, tiled blocks, or repeated under augmentation, and how partial predictions are stitched back into one per-point output. This keeps evaluation code identical regardless of scene size or protocol.
Subclasses implement forward; __call__ delegates to it, mirroring torch.nn.Module. To use an inferer, call the instance directly:
import torch
import torch_pointcloud as tp
from torch_pointcloud.inferers import SimpleInferer
model = tp.create_model("pointnet.s3dis-area5").eval()
data = {"pos": torch.rand(4096, 3) * 10, "x": torch.rand(4096, 9), "batch": torch.zeros(4096, dtype=torch.long)}
inferer = SimpleInferer()
logits = inferer(data, predictor=lambda d: model(d["x"], d["pos"], d["batch"]))
data is a packed-batch dict (at minimum containing position and batch indices). predictor is any callable taking such a dict and returning per-point logits of shape \((N, C_\text{out})\). Inferers keep nothing of the scene, so one instance can be reused across scenes and wrapped by another inferer.
Inferers that draw random numbers take a seed. None follows the global generator, like the transforms do, so one torch.manual_seed (or seed_everything) seeds the whole evaluation. An int gives the inferer its own stream, offset by the number of calls the instance has made: successive calls (e.g. TTAInferer votes) draw different numbers, and a fresh instance replays the same sequence.
The softmax parameter controls whether partial predictions are converted to softmax probabilities before aggregation, and aggregate how they are combined:
| Inferer | softmax | Aggregated quantity |
|---|---|---|
SimpleInferer | False | predictor output as-is |
SlidingWindowInferer | False | raw logits per block; always probabilities ("max" / "vote") |
KNNWindowInferer | False | raw logits ("mean"); always probabilities ("ema") |
VoxelPartitionInferer | False | raw logits per pass |
PotentialSphereInferer | none | always an EMA of softmax probabilities |
TTAInferer | False | base output as-is |
PartRefinementInferer | none | one-hot refined labels of the base output's argmax |
When the input scene is empty (\(N = 0\)), inferers that never call the predictor return a \((0, 0)\) tensor (the channel count cannot be inferred without a predictor call); SimpleInferer and TTAInferer return whatever the predictor / base inferer produces for the empty input.
To add a custom strategy, subclass Inferer and implement forward:
from torch_pointcloud.inferers import Inferer
class MyInferer(Inferer):
def forward(self, data, predictor):
return predictor(data)
Methods:
-
forwardβRun the inference strategy.
forward abstractmethod [source] ΒΆ
Run the inference strategy.
Parameters:
-
data(Dict[str, Any]) βPacked-batch dict. Must contain
posandbatchkeys (the exact names are configurable on subclasses that exposepos_key/batch_key). -
predictor(Callable[[Dict[str, Any]], Tensor]) βCallable taking a packed dict and returning per-point logits of shape \((N, C_\text{out})\).
Returns:
-
TensorβPer-point output tensor of shape \((N, C_\text{out})\).