module
Lightning modules for classification, segmentation, and detection training.
Classes:
-
LitModelβShared base for the task-specific Lightning wrappers.
-
LitClassificationModelβLightningModule for a point cloud classification model, built from the registry.
-
LitSemanticSegmentationModelβLightningModule for a point cloud semantic segmentation model, built from the registry.
-
LitPartSegmentationModelβLightningModule for a part segmentation model, built from the registry.
-
LitDetectionModelβLightningModule for a 3D object detection model, built from the registry.
LitModel [source] ΒΆ
LitModel(
name: str,
task: Task,
*,
optimizer: Optional[Callable[..., Optimizer]] = None,
scheduler: Optional[Callable[..., Any]] = None,
criterion: Optional[Module] = None,
inferer: Optional[Inferer] = None,
input_keys: Optional[Sequence[str]] = None,
target_key: str = LABEL,
metric_input_keys: Sequence[str] = (),
scheduler_interval: str = "epoch",
param_groups: Optional[Dict[str, Any]] = None,
**kwargs: Any,
)
Bases: LightningModule
Shared base for the task-specific Lightning wrappers.
The task-specific subclasses build their model through create_model; this base only holds the built model (and its registered evaluation transform) and implements the shared train/val/test loop. input_keys, target_key and scheduler_interval are read from self.hparams, which the subclass populates via save_hyperparameters. Without an optimizer the module is evaluation-only (benchmark mode): Trainer.test works and Trainer.fit raises.
Parameters:
-
name(str) βRegistered model name; built via
create_model(name, task=...). -
task(Task) βRegistry of the model (
"classification","semantic-segmentation","part-segmentation","detection"); set by the subclass. -
optimizer(Optional[Callable[..., Optimizer]], default:None) βA callable that takes parameters and returns an optimizer (a
_partial_target). -
scheduler(Optional[Callable[..., Any]], default:None) βAn optional callable that takes an optimizer and returns a learning-rate scheduler.
-
criterion(Optional[Module], default:None) βThe loss module; defaults to
CrossEntropyLoss. -
inferer(Optional[Inferer], default:None) βTest-time inference strategy (e.g.
TTAInferer,SlidingWindowInferer) run in place of the plain forward on test batches; defaults toSimpleInferer(one forward on the whole batch), so every test prediction goes through an inferer. Training and validation are unaffected. The inferer may return probabilities instead of logits (torchmetrics handles both), so notest/lossis logged. -
input_keys(Optional[Sequence[str]], default:None) βBatch-dict keys passed positionally to the model's forward (see
select_inputs);None(the default) uses the registeredinput_keysof the model. -
target_key(str, default:LABEL) βBatch-dict key for the per-cloud label.
-
metric_input_keys(Sequence[str], default:()) βBatch-dict keys copied as-is into the
validation_step/test_stepoutput dict, alongside the predictions and targets, for metrics whoseupdateconsumes extra inputs (MetricCallbackforwards the keys each metric declares). A listed key missing from the batch raises. -
scheduler_interval(str, default:'epoch') βWhether the scheduler steps per
"epoch"or"step". -
param_groups(Optional[Dict[str, Any]], default:None) βOptional dict of kwargs forwarded to
torch_pointcloud.optim.generate_param_groups. -
**kwargs(Any, default:{}) βForwarded to
create_model(e.g.pretrained=True, or registry-hparam overrides).
Methods:
-
predictβForward the batch and return the logits tensor (the predictor handed to the inferer).
-
stepβPredict the batch, log the criterion loss, and return the logits, targets and loss.
-
training_stepβRun the shared
stepand return the loss to optimize. -
validation_stepβReturn the evaluation predictions and targets, plus the batch's
metric_input_keys. -
test_stepβReturn the inferer's predictions and targets, plus the batch's
metric_input_keys. -
configure_optimizersβBuild the configured optimizer (over
param_groupswhen given) and its optional scheduler.
predict [source] ΒΆ
Forward the batch and return the logits tensor (the predictor handed to the inferer).
step [source] ΒΆ
Predict the batch, log the criterion loss, and return the logits, targets and loss.
validation_step [source] ΒΆ
Return the evaluation predictions and targets, plus the batch's metric_input_keys.
LitClassificationModel [source] ΒΆ
Bases: LitModel
LightningModule for a point cloud classification model, built from the registry.
Parameters:
-
name(str) βRegistered classification model name (e.g.
pointnet2-ssg.modelnet40.xu-yan); built viacreate_model(name, task="classification"). -
**kwargs(Any, default:{}) βForwarded to the base
LitModel(e.g.optimizer,scheduler,criterion) andcreate_model(e.g.pretrained=True, or registry-hparam overrides).
Methods:
-
predictβForward the batch and return the logits tensor (the predictor handed to the inferer).
-
stepβPredict the batch, log the criterion loss, and return the logits, targets and loss.
-
training_stepβRun the shared
stepand return the loss to optimize. -
validation_stepβReturn the evaluation predictions and targets, plus the batch's
metric_input_keys. -
test_stepβReturn the inferer's predictions and targets, plus the batch's
metric_input_keys. -
configure_optimizersβBuild the configured optimizer (over
param_groupswhen given) and its optional scheduler.
predict [source] ΒΆ
Forward the batch and return the logits tensor (the predictor handed to the inferer).
step [source] ΒΆ
Predict the batch, log the criterion loss, and return the logits, targets and loss.
validation_step [source] ΒΆ
Return the evaluation predictions and targets, plus the batch's metric_input_keys.
LitSemanticSegmentationModel [source] ΒΆ
LitSemanticSegmentationModel(
name: str,
inverse_key: Optional[str] = None,
origin_target_key: Optional[str] = None,
target_key: str = SEGMENT,
**kwargs: Any,
)
Bases: _LitSegmentationModel
LightningModule for a point cloud semantic segmentation model, built from the registry.
Parameters:
-
name(str) βRegistered semantic segmentation model name; built via
create_model(name, task="semantic-segmentation"). -
inverse_key(Optional[str], default:None) βBatch-dict key of the source-to-predictor row map written by the transform (
inverse; see the transforms module docs on sampling keys). When set, eval predictions are broadcast to source resolution (preds[batch[inverse_key]]) and scored againstorigin_target_key; the loss stays at predictor resolution againsttarget_key. Multi-scene batches need the key in the loader'scat_keysso the per-scene maps can be offset into the packed layout; the datamodule adds it. -
origin_target_key(Optional[str], default:None) βBatch-dict key of the source-resolution labels scored with
inverse_key; required with it. -
target_key(str, default:SEGMENT) βBatch-dict key of the per-point labels.
-
**kwargs(Any, default:{}) βForwarded to the base
LitModel(e.g.inferer,optimizer,criterion) andcreate_model(e.g.pretrained=True, or registry-hparam overrides).
Methods:
-
predictβForward the batch and return the logits tensor (the predictor handed to the inferer).
-
stepβPredict the batch, log the criterion loss, and return the logits, targets and loss.
-
training_stepβRun the shared
stepand return the loss to optimize. -
validation_stepβReturn the evaluation predictions and targets, plus the batch's
metric_input_keys. -
test_stepβReturn the inferer's predictions and targets, plus the batch's
metric_input_keys. -
configure_optimizersβBuild the configured optimizer (over
param_groupswhen given) and its optional scheduler.
predict [source] ΒΆ
Forward the batch and return the logits tensor (the predictor handed to the inferer).
step [source] ΒΆ
Predict the batch, log the criterion loss, and return the logits, targets and loss.
validation_step [source] ΒΆ
Return the evaluation predictions and targets, plus the batch's metric_input_keys.
LitPartSegmentationModel [source] ΒΆ
LitPartSegmentationModel(
name: str,
inverse_key: Optional[str] = None,
origin_target_key: Optional[str] = None,
target_key: str = SEGMENT,
**kwargs: Any,
)
Bases: _LitSegmentationModel
LightningModule for a part segmentation model, built from the registry.
The model also reads the one-hot object category, which the registered input_keys of part segmentation models list (("x", "pos", "batch", "category")).
Parameters:
-
name(str) βRegistered part segmentation model name; built via
create_model(name, task="part-segmentation"). -
inverse_key(Optional[str], default:None) βBatch-dict key of the source-to-predictor row map written by the transform (
inverse; see the transforms module docs on sampling keys). When set, eval predictions are broadcast to source resolution (preds[batch[inverse_key]]) and scored againstorigin_target_key; the loss stays at predictor resolution againsttarget_key. Multi-scene batches need the key in the loader'scat_keysso the per-scene maps can be offset into the packed layout; the datamodule adds it. -
origin_target_key(Optional[str], default:None) βBatch-dict key of the source-resolution labels scored with
inverse_key; required with it. -
target_key(str, default:SEGMENT) βBatch-dict key of the per-point labels.
-
**kwargs(Any, default:{}) βForwarded to the base
LitModel(e.g.inferer,optimizer,criterion) andcreate_model(e.g.pretrained=True, or registry-hparam overrides).
Methods:
-
predictβForward the batch and return the logits tensor (the predictor handed to the inferer).
-
stepβPredict the batch, log the criterion loss, and return the logits, targets and loss.
-
training_stepβRun the shared
stepand return the loss to optimize. -
validation_stepβReturn the evaluation predictions and targets, plus the batch's
metric_input_keys. -
test_stepβReturn the inferer's predictions and targets, plus the batch's
metric_input_keys. -
configure_optimizersβBuild the configured optimizer (over
param_groupswhen given) and its optional scheduler.
predict [source] ΒΆ
Forward the batch and return the logits tensor (the predictor handed to the inferer).
step [source] ΒΆ
Predict the batch, log the criterion loss, and return the logits, targets and loss.
validation_step [source] ΒΆ
Return the evaluation predictions and targets, plus the batch's metric_input_keys.
LitDetectionModel [source] ΒΆ
LitDetectionModel(
name: str,
*,
criterion: Union[
Module, Callable[..., Module], None
] = None,
score_threshold: float = 0.05,
nms_iou: float = 0.25,
nms_rotated: bool = False,
min_points: Optional[int] = None,
label_key: str = LABEL,
ignore_mask_key: Optional[str] = None,
**kwargs: Any,
)
Bases: LitModel
LightningModule for a 3D object detection model, built from the registry.
Detection breaks the shared classification/segmentation loop in three places, so this subclass overrides them and reuses the base for everything else (model construction, forward, optimizer wiring, training_step):
- the loss is either a ready-built
nn.Module(the general case: an anchor / center / set-matching loss whose geometry params are set explicitly in config) or a factory completed at build time with the model's head-geometry params (theVoteNetLosscarve-out, which readsnum_heading_bins,num_size_clusters,num_classes,mean_sizesoff the model); without acriterionthe module is evaluation-only (no loss is logged, training raises); step(training only) feeds the whole forward output and the batch to the loss, which returns a dict of named components (each logged), and reports the totalloss;- the eval steps are metric-driven, not loss-driven: they run the model's raw
decode, postprocess it (optionalmin_pointsfilter, drop boxes belowscore_threshold, per-class 3Dnms3datnms_iouon the rotated BEV IoU whennms_rotated, and the indoor per-class expansion whendecodeemitsclass_probs), and pair the result with the ground truth for aMetricCallback(e.g.BoxMeanAveragePrecision,BoxAveragePrecision); any other per-boxdecodeentry (e.g. the nuScenes heads'velocity) is filtered alongside the boxes and kept in the predictions dict, and when the batch carriesDataKeys.CALIB/DataKeys.IMAGE_SHAPE(stacked per-frame \((B, 3, 4)\) / \((B, 2)\)) the sub-25 pxprojected_ignore_maskof the surviving boxes is attached as the predictions'ignore_mask(the KITTI min-height rule); the ground-truth boxes areDataKeys.BOXpacked as \((K, 7)\) rows \([c_x, c_y, c_z, d_x, d_y, d_z, \theta]\) (full extents, counter-clockwise heading \(\theta\)), with per-box classes underlabel_key. No loss is computed at validation, so a two-stage detector whose inference forward differs from its training forward (its eval output carries decoded proposals, not loss targets) validates cleanly.
A model is swappable as long as it returns a prediction dict from forward and a raw Detection3D from decode(output), and (for training) is paired with a criterion(output, data).
Parameters:
-
name(str) βRegistered detection model name; built via
create_model(name, task="detection"). -
criterion(Union[Module, Callable[..., Module], None], default:None) βThe training loss, in one of two forms. A ready-built
nn.Moduleis used as-is (the general case: instantiate it in config with its geometry params, e.g.AnchorHeadLoss). A callable factory is completed with the model's head-geometry params, i.e. called ascriterion(num_heading_bins=..., num_size_clusters=..., num_classes=..., mean_sizes=...)(theVoteNetLosscarve-out). Either way itsforward(output, data)returns a dict whoselossentry is the total to optimize. LeaveNoneto benchmark a detector whose training loss is not ported. -
score_threshold(float, default:0.05) βMinimum score to keep a decoded box in the eval postprocess.
-
nms_iou(float, default:0.25) βIoU threshold of the per-class 3D NMS in the eval postprocess.
-
nms_rotated(bool, default:False) βSuppress on the exact rotated BEV IoU instead of the axis-aligned 3D IoU (see
nms3d); the KITTI outdoor protocol. -
min_points(Optional[int], default:None) βOptional minimum number of points inside a decoded box for it to be kept (the VoteNet / 3DETR indoor protocol uses \(5\)).
-
label_key(str, default:LABEL) βBatch-dict key of the per-box ground-truth class labels (defaults to
DataKeys.LABEL). -
ignore_mask_key(Optional[str], default:None) βOptional batch-dict key of a per-box ignore mask forwarded to the metric with the ground truth (KITTI-style ignore regions).
-
**kwargs(Any, default:{}) βForwarded to
create_modeland the base (e.g.optimizer,scheduler,input_keys). The base'sinfererdoes not apply: detection eval is the decode / postprocess path above.
Methods:
-
stepβForward the batch, log every named loss component, and return the output and the total loss.
-
predictβForward the batch and return the logits tensor (the predictor handed to the inferer).
-
training_stepβRun the shared
stepand return the loss to optimize. -
validation_stepβReturn the evaluation predictions and targets, plus the batch's
metric_input_keys. -
test_stepβReturn the inferer's predictions and targets, plus the batch's
metric_input_keys. -
configure_optimizersβBuild the configured optimizer (over
param_groupswhen given) and its optional scheduler.
step [source] ΒΆ
Forward the batch, log every named loss component, and return the output and the total loss.
predict [source] ΒΆ
Forward the batch and return the logits tensor (the predictor handed to the inferer).
validation_step [source] ΒΆ
Return the evaluation predictions and targets, plus the batch's metric_input_keys.