qubvel-org / segmentation_models.pytorch

Semantic segmentation models with 500+ pretrained convolutional and transformer-based backbones.
https://smp.readthedocs.io/
MIT License
9.51k stars 1.66k forks source link

error in `examples/cars segmentation (camvid).ipynb` #817

Closed kamangir closed 10 months ago

kamangir commented 1 year ago

error in https://github.com/qubvel/segmentation_models.pytorch/blob/master/examples/cars%20segmentation%20(camvid).ipynb

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[16], line 4
      1 # Dice/F1 score - https://en.wikipedia.org/wiki/S%C3%B8rensen%E2%80%93Dice_coefficient
      2 # IoU/Jaccard score - https://en.wikipedia.org/wiki/Jaccard_index
----> 4 loss = smp.utils.losses.DiceLoss()
      5 metrics = [
      6     smp.utils.metrics.IoU(threshold=0.5),
      7 ]
      9 optimizer = torch.optim.Adam([ 
     10     dict(params=model.parameters(), lr=0.0001),
     11 ])

AttributeError: module 'segmentation_models_pytorch' has no attribute 'utils'
Jordan-Pierce commented 1 year ago

The notebooks are outdated; they use a previous version of the library, but when installing via pip, utils causes issues. To use the notebook, you need to include the import

import segmentation_models_pytorch.utils

If you try to use the version of smp installed with pip, then you'll find that things are different enough that the notebook won't easily work. For example, the losses are different and expect different input from the dataloader, and so are the metrics. If you use the notebook version, you cannot also use the most updated version of smp (at least the metrics, you can still use the updated losses after changing the dataloader, but not both)

Jordan-Pierce commented 1 year ago

The reason being is that if you try to use the Trainer class to train and validate per epoch, you have to adjust how you prepare the sample in the dataloader. I'm finding that you have to modify the samples in such a way that they are not compatible such that both the losses, and the metrics can be calculated in Trainer. @qubvel am I mistaken?

github-actions[bot] commented 10 months ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] commented 10 months ago

This issue was closed because it has been stalled for 7 days with no activity.