-
Notifications
You must be signed in to change notification settings - Fork 347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add PixelwiseRegressionTask #1241
Add PixelwiseRegressionTask #1241
Conversation
Not sure if this belongs in |
I vote for |
dd2f9a0
to
6a2c519
Compare
@@ -35,8 +36,10 @@ class RegressionTask(LightningModule): # type: ignore[misc] | |||
print(timm.list_models()) | |||
""" | |||
|
|||
def config_task(self) -> None: | |||
"""Configures the task based on kwargs parameters.""" | |||
target_key: str = "label" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allows to not have to duplicate all the train/val/test steps just to change label
to mask
. Let me know if you have any other suggestions.
tests/trainers/test_regression.py
Outdated
("inria", InriaAerialImageLabelingDataModule, 1, "mse"), | ||
("inria", InriaAerialImageLabelingDataModule, 2, "mae"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing regression on Inria binary [0, 1] masks for now since we don't have a readily available pixelwise regression datamodule.
y_hat = self(x) | ||
|
||
loss = F.mse_loss(y_hat, y) | ||
if y_hat.ndim != y.ndim: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If num_outputs=1
the target variable ground truth is missing the necessary channel dim e.g.
- (b,) instead of (b, 1)
- (b, h, w) instead of (b, 1, h, w)
while the output of the models will be:
- (b, 1)
- (b, 1, h, w)
self.log("train_loss", loss) # logging to TensorBoard | ||
self.train_metrics(y_hat, y) | ||
self.train_metrics(y_hat, y.to(torch.float)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cast to float only for loss and metrics in case the plotting expects a different dtype
e05a3b5
to
d71a252
Compare
…rchgeo into trainers/dense-regression
Looks like pixel-wise regression won the poll. Can you rebase and use the new hydra-style configs? |
Dimension stuff looks super confusing. Wonder if there's a way to simplify that. We should consider abstracting the segmentation model stuff into a shared utility. Will update things to the new style in a separate PR. |
The dimension lines are essentially the same as the
except it only does it if necessary. It's a result of not adding a channel dimension to the output from the dataset targets. |
This PR adds a
PixelwiseRegressionTask
which can be used for regression on 2D imagery, e.g. height estimation or other continuous per-pixel variables. It's basically a mixture of the currentRegressionTask
andSemanticSegmentationTask
in that it performs regression but uses smp models e.g. U-Net with a single output channel and L1 or L2 loss for training.Unless I'm mistaken, we don't have any datasets to actually test this on.
Closes #849