Skip to content

Instantly share code, notes, and snippets.

@calebrob6
Last active March 7, 2024 00:20
Show Gist options
  • Save calebrob6/4d7fc311045c4f9015e401100e34ed38 to your computer and use it in GitHub Desktop.
Save calebrob6/4d7fc311045c4f9015e401100e34ed38 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@robmarkcole
Copy link

Running with torchgeo 0.5.0 will give:

TypeError: SemanticSegmentationTask.__init__() got an unexpected keyword argument 'segmentation_model'

The necessary update:

task = CustomSemanticSegmentationTask(
    model="unet",
    backbone="resnet18",
    weights=True,
    in_channels=6,
    num_classes=2,
    loss="ce",
    ignore_index=None,
    lr=learning_rate,
    patience=10
)

@robmarkcole
Copy link

Then on running trainer.fit you will get

TypeError: `model` must be a `LightningModule` or `torch._dynamo.OptimizedModule`, got `CustomSemanticSegmentationTask`

It is necessary to use the new lightning format for imports:

from lightning.pytorch.callbacks import EarlyStopping, ModelCheckpoint
from lightning.pytorch import Trainer, seed_everything
from lightning.pytorch.loggers import TensorBoardLogger, WandbLogger
from lightning.pytorch import LightningDataModule

@robmarkcole
Copy link

You will next get:

AttributeError: 'CustomSemanticSegmentationTask' object has no attribute 'loss'

It is necessary in the custom trainer to use:

    loss: Tensor = self.criterion(y_hat, y)

@mustafaemre2
Copy link

| Name | Type | Params

0 | criterion | CrossEntropyLoss | 0
1 | train_metrics | MetricCollection | 0
2 | val_metrics | MetricCollection | 0
3 | test_metrics | MetricCollection | 0
4 | model | Unet | 14.3 M

14.3 M Trainable params
0 Non-trainable params
14.3 M Total params
57.351 Total estimated model params size (MB)
Sanity Checking: | | 0/? [00:00<?, ?it/s]

It remains at this stage, what could be the problem?

@calebrob6
Copy link
Author

Hey @mustafaemre2 -- are you running on the GPU?

@calebrob6
Copy link
Author

calebrob6 commented Jan 11, 2024

Updated with @robmarkcole's fixes (and ensured that the notebook runs end-to-end) for torchgeo 0.5.1 (thanks Robin!)

@mustafaemre2
Copy link

Yes, I used your codes exactly
My GPU's RTX 3060 laptop @calebrob6

@mustafaemre2
Copy link

You are using a CUDA device ('NVIDIA GeForce RTX 3060 Laptop GPU') that has Tensor Cores. To properly utilize them, you should set torch.set_float32_matmul_precision('medium' | 'high') which will trade-off precision for performance. For more details, read https://pytorch.org/docs/stable/generated/torch.set_float32_matmul_precision.html#torch.set_float32_matmul_precision
LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]

i get this message @calebrob6

@nadeem-git-coder
Copy link

nadeem-git-coder commented Feb 27, 2024

Download the dataset and see how many images are in the train and test splits

train_dataset = LEVIRCDPlus(root="data/LEVIRCDPlus", split="train", download=True, checksum=True)
test_dataset = LEVIRCDPlus(root="data/LEVIRCDPlus", split="test", download=True, checksum=True)
len(train_dataset), len(test_dataset)

Its give error :-
RuntimeError: The MD5 checksum of the download file data/LEVIRCDPlus/LEVIR-CD+.zip does not match the one on record.Please delete the file and try again. If the issue persists, please report this to torchvision at https://github.com/pytorch/vision/issues.

i get this msg @calebrob6

@ProtikBose
Copy link

@nadeem-git-coder Have you found any solution for that?

@nadeem-git-coder
Copy link

nadeem-git-coder commented Mar 7, 2024

@ProtikBose I have downloaded the dataset mannually and use it .
Have you encountered the error?
What the error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment