diff --git a/_modules/myria3d/callbacks/comet_callbacks.html b/_modules/myria3d/callbacks/comet_callbacks.html index c1108311..19b0ff84 100644 --- a/_modules/myria3d/callbacks/comet_callbacks.html +++ b/_modules/myria3d/callbacks/comet_callbacks.html @@ -238,16 +238,17 @@
from torch import nn
from torch_geometric.data import Batch
from torch_geometric.nn import knn_interpolate
-from torchmetrics.classification import MulticlassJaccardIndex
-from myria3d.callbacks.comet_callbacks import log_comet_cm
-from myria3d.metrics.iou import iou
from myria3d.models.modules.pyg_randla_net import PyGRandLANet
from myria3d.utils import utils
@@ -198,14 +195,12 @@ Source code for myria3d.models.model
[docs]class Model(LightningModule):
- """This LightningModule implements the logic for model trainin, validation, tests, and prediction.
+ """Model training, validation, test and prediction of point cloud semantic segmentation.
- It is fully initialized by named parameters for maximal flexibility with hydra configs.
+ During training and validation, metrics are calculed based on sumbsampled points only.
+ At test time, metrics are calculated considering all the points.
- During training and validation, IoU is calculed based on sumbsampled points only, and is therefore
- an approximation.
- At test time, IoU is calculated considering all the points. To keep this module light, a callback
- takes care of the interpolation of predictions between all points.
+ To keep this module light, a callback takes care of metric computations.
Read the Pytorch Lightning docs:
@@ -216,7 +211,7 @@ Source code for myria3d.models.model
def __init__(self, **kwargs):
"""Initialization method of the Model lightning module.
- Everything needed to train/test/predict with a neural architecture, including
+ Everything needed to train/evaluate/test/predict with a neural architecture, including
the architecture class name and its hyperparameter.
See config files for a list of kwargs.
@@ -234,22 +229,6 @@ Source code for myria3d.models.model
self.softmax = nn.Softmax(dim=1)
self.criterion = kwargs.get("criterion")
-[docs] def on_fit_start(self) -> None:
- self.criterion = self.criterion.to(self.device)
- self.train_iou = MulticlassJaccardIndex(self.hparams.num_classes).to(self.device)
- self.val_iou = MulticlassJaccardIndex(self.hparams.num_classes).to(self.device)
-
-[docs] def on_test_start(self) -> None:
- self.test_iou = MulticlassJaccardIndex(self.hparams.num_classes).to(self.device)
-
- def log_all_class_ious(self, confmat, phase: str):
- ious = iou(confmat)
- for class_iou, class_name in zip(ious, self.hparams.classification_dict.values()):
- metric_name = f"{phase}/iou_CLASS_{class_name}"
- self.log(
- metric_name, class_iou, on_step=False, on_epoch=True, metric_attribute=metric_name
- )
-
[docs] def forward(self, batch: Batch) -> torch.Tensor:
"""Forward pass of neural network.
@@ -291,8 +270,6 @@ Source code for myria3d.models.model
[docs] def training_step(self, batch: Batch, batch_idx: int) -> dict:
"""Training step.
- Makes a model pass. Then, computes loss and predicted class of subsampled points to log loss and IoU.
-
Args:
batch (torch_geometric.data.Batch): Batch of data including x (features), pos (xyz positions),
and y (targets, optionnal) in (B*N,C) format.
@@ -305,25 +282,11 @@ Source code for myria3d.models.model
self.criterion = self.criterion.to(logits.device)
loss = self.criterion(logits, targets)
self.log("train/loss", loss, on_step=True, on_epoch=True, prog_bar=False)
-
- with torch.no_grad():
- preds = torch.argmax(logits.detach(), dim=1)
- self.train_iou(preds, targets)
-
return {"loss": loss, "logits": logits, "targets": targets}
-[docs] def on_train_epoch_end(self) -> None:
- iou_epoch = self.train_iou.to(self.device).compute()
- self.log("train/iou", iou_epoch, on_step=False, on_epoch=True, prog_bar=True)
- self.log_all_class_ious(self.train_iou.confmat, "train")
- log_comet_cm(self, self.train_iou.confmat, "train")
- self.train_iou.reset()
-
[docs] def validation_step(self, batch: Batch, batch_idx: int) -> dict:
"""Validation step.
- Makes a model pass. Then, computes loss and predicted class of subsampled points to log loss and IoU.
-
Args:
batch (torch_geometric.data.Batch): Batch of data including x (features), pos (xyz positions),
and y (targets, optionnal) in (B*N,C) format.
@@ -337,26 +300,8 @@ Source code for myria3d.models.model
self.criterion = self.criterion.to(logits.device)
loss = self.criterion(logits, targets)
self.log("val/loss", loss, on_step=True, on_epoch=True)
-
- preds = torch.argmax(logits.detach(), dim=1)
- self.val_iou = self.val_iou.to(preds.device)
- self.val_iou(preds, targets)
-
return {"loss": loss, "logits": logits, "targets": targets}
-[docs] def on_validation_epoch_end(self) -> None:
- """At the end of a validation epoch, compute the IoU.
-
- Args:
- outputs : output of validation_step
-
- """
- iou_epoch = self.val_iou.to(self.device).compute()
- self.log("val/iou", iou_epoch, on_step=False, on_epoch=True, prog_bar=True)
- self.log_all_class_ious(self.val_iou.confmat, "val")
- log_comet_cm(self, self.val_iou.confmat, "val")
- self.val_iou.reset()
-
[docs] def test_step(self, batch: Batch, batch_idx: int):
"""Test step.
@@ -372,26 +317,8 @@ Source code for myria3d.models.model
self.criterion = self.criterion.to(logits.device)
loss = self.criterion(logits, targets)
self.log("test/loss", loss, on_step=False, on_epoch=True)
-
- preds = torch.argmax(logits, dim=1)
- self.test_iou = self.test_iou.to(preds.device)
- self.test_iou(preds, targets)
-
return {"loss": loss, "logits": logits, "targets": targets}
-[docs] def on_test_epoch_end(self) -> None:
- """At the end of a validation epoch, compute the IoU.
-
- Args:
- outputs : output of test
-
- """
- iou_epoch = self.test_iou.to(self.device).compute()
- self.log("test/iou", iou_epoch, on_step=False, on_epoch=True, prog_bar=True)
- self.log_all_class_ious(self.test_iou.confmat, "test")
- log_comet_cm(self, self.test_iou.confmat, "test")
- self.test_iou.reset()
-
[docs] def predict_step(self, batch: Batch) -> dict:
"""Prediction step.
diff --git a/apidoc/configs.html b/apidoc/configs.html
index 6fe588a8..79f51139 100644
--- a/apidoc/configs.html
+++ b/apidoc/configs.html
@@ -367,6 +367,9 @@ Default configuration mode: min
patience: 6
min_delta: 0
+ model_detailed_metrics:
+ _target_: myria3d.callbacks.metric_callbacks.ModelMetrics
+ num_classes: ${model.num_classes}
model:
optimizer:
_target_: functools.partial
diff --git a/apidoc/myria3d.callbacks.html b/apidoc/myria3d.callbacks.html
index b63d65c8..063f81fb 100644
--- a/apidoc/myria3d.callbacks.html
+++ b/apidoc/myria3d.callbacks.html
@@ -207,8 +207,9 @@ Submodules
-myria3d.callbacks.comet_callbacks.log_comet_cm(lightning_module, confmat, phase)[source]
-
+myria3d.callbacks.comet_callbacks.log_comet_cm(pl_module, confmat, phase, class_names)[source]
+Method used in the metric logging callback.
+
diff --git a/apidoc/myria3d.model.html b/apidoc/myria3d.model.html
index 727eee0f..db17dcc4 100644
--- a/apidoc/myria3d.model.html
+++ b/apidoc/myria3d.model.html
@@ -172,12 +172,10 @@ myria3d.models
class myria3d.models.model.Model(**kwargs)[source]
-This LightningModule implements the logic for model trainin, validation, tests, and prediction.
-It is fully initialized by named parameters for maximal flexibility with hydra configs.
-During training and validation, IoU is calculed based on sumbsampled points only, and is therefore
-an approximation.
-At test time, IoU is calculated considering all the points. To keep this module light, a callback
-takes care of the interpolation of predictions between all points.
+Model training, validation, test and prediction of point cloud semantic segmentation.
+During training and validation, metrics are calculed based on sumbsampled points only.
+At test time, metrics are calculated considering all the points.
+To keep this module light, a callback takes care of metric computations.
- Read the Pytorch Lightning docs:
https://pytorch-lightning.readthedocs.io/en/latest/common/lightning_module.html
@@ -214,67 +212,6 @@ myria3d.models
--
-on_fit_start() None [source]
-Called at the very beginning of fit.
-If on DDP it is called on every process
-
-
-
--
-on_test_epoch_end() None [source]
-At the end of a validation epoch, compute the IoU.
-
-- Parameters
-outputs¶ – output of test
-
-
-
-
-
-
-
--
-on_train_epoch_end() None [source]
-Called in the training loop at the very end of the epoch.
-To access all batch outputs at the end of the epoch, you can cache step outputs as an attribute of the
-LightningModule
and access them in this hook:
-class MyLightningModule(L.LightningModule):
- def __init__(self):
- super().__init__()
- self.training_step_outputs = []
-
- def training_step(self):
- loss = ...
- self.training_step_outputs.append(loss)
- return loss
-
- def on_train_epoch_end(self):
- # do something with all training_step outputs, for example:
- epoch_mean = torch.stack(self.training_step_outputs).mean()
- self.log("training_epoch_mean", epoch_mean)
- # free up the memory
- self.training_step_outputs.clear()
-
-
-
-
-
--
-on_validation_epoch_end() None [source]
-At the end of a validation epoch, compute the IoU.
-
-- Parameters
-outputs¶ – output of validation_step
-
-
-
-
-
predict_step(batch: torch_geometric.data.batch.Batch) dict [source]
@@ -320,7 +257,6 @@ myria3d.models
training_step(batch: torch_geometric.data.batch.Batch, batch_idx: int) dict [source]
Training step.
-Makes a model pass. Then, computes loss and predicted class of subsampled points to log loss and IoU.
- Parameters
@@ -342,7 +278,6 @@ myria3d.models
validation_step(batch: torch_geometric.data.batch.Batch, batch_idx: int) dict [source]
Validation step.
-Makes a model pass. Then, computes loss and predicted class of subsampled points to log loss and IoU.
- Parameters
diff --git a/genindex.html b/genindex.html
index 1c4f0f22..19ae212a 100644
--- a/genindex.html
+++ b/genindex.html
@@ -615,28 +615,12 @@ N
O