CFM#
Lightning wrapper for CFM (Cross-modal Feature Mapping).
- class anomalib.models.image.cfm.lightning_model.CFM(lr=0.0001, rgb_backbone='vit_base_patch8_224.dino', group_size=128, num_group=1024, pointmae_weights=None, pre_processor=True, post_processor=True, evaluator=True, visualizer=True)#
Bases:
AnomalibModuleAnomalibModule wrapper for CFM model.
- Parameters:
lr (
float) – Learning rate.rgb_backbone (
str) – Name of the backbone DINO for RGB.group_size (
int) – Dimension of the groups for PointTransformer.num_group (
int) – Number of groups for PointTransformer.pointmae_weights (
str|Path|None) – Path to Point-MAE pretrained weights. IfNone, weights are automatically downloaded to the anomalib cache.pre_processor (
PreProcessor|bool) – Pre-processor used to transform input data before passing to model.post_processor (
PostProcessor|bool) – Post-processor used to process model predictions.evaluator (
Evaluator|bool) – Evaluator used to compute metrics.visualizer (
Visualizer|bool) – Visualizer used to create visualizations.
Note
Use a depth datamodule such as
MVTec3Dand setcategoryto train on a single object class. Seeexamples/configs/model/cfm.yaml.Example
>>> from anomalib.models import CFM >>> model = CFM(lr=1e-4, num_group=512)
- configure_optimizers()#
Configuration of the optimizer (Adam) for trainable modules.
- Return type:
- static configure_pre_processor(image_size=None)#
Configure the pre-processor dynamically based on config/data.
- Return type:
- forward(batch, *_args, **_kwargs)#
Forward pass used by predict/export code paths.
- Return type:
Notes
AnomalibModule’s default forward assumes single-input models and calls self.model(image). CFM is multimodal, so we override forward to require a Batch or mapping with both ‘image’ and ‘point_cloud’/’depth_map’ keys.
- property learning_type: LearningType#
Returns the model’s learning type (One-Class).
- predict_step(batch, batch_idx, dataloader_idx=0)#
Same as
validation_step(multimodal; do not use the image-only base implementation).
- test_step(batch, batch_idx, *args, **kwargs)#
Same as
validation_step(multimodal; do not use the image-only base implementation).
- training_step(batch, _batch_idx, *_args, **_kwargs)#
Executes a training step evaluating the loss between multimodal projections.
- Return type:
PyTorch model implementation for CFM.
- class anomalib.models.image.cfm.torch_model.CFMModel(rgb_backbone='vit_base_patch8_224.dino', group_size=128, num_group=1024, pointmae_weights=None)#
Bases:
ModuleCrossmodal Feature Mapping (CFM) model.
Model learns from the correspondence between geometry(3D) and appearance (2D).
- compute_losses(rgb_feat, xyz_feat, pred_rgb, pred_xyz)#
Evaluates the loss based on discrepancy between real and mapped features.
- extract_features(rgb, xyz)#
Extract the real features from the sensors(2D e 3D).
- forward(rgb, xyz)#
It manages the data flow based on the model’s status.
- Return type:
dict[str,Tensor] |InferenceBatch