qubvel / segmentation_models.pytorch

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

I can't run "cars segmentation (camvid).ipynb" example #886

Open atekgul opened 3 weeks ago

atekgul commented 3 weeks ago

Hi. As I understand the below code in cars segmentation (camvid).ipynb should be changed. Because I can't run it. Am I right? Do you plan to update the examples?

  1. There is no utils under smp.

    • smp.utils.losses.DiceLoss() => smp.losses.DiceLoss()
    • smp.utils.metrics.IOU(threshold=0.5) => smp.metrics_iou_score(tp, fp, fn, tn)
  2. TrainEpoch and ValidEpoch are not valid anymore.

Code: //Dice/F1 score - https://en.wikipedia.org/wiki/S%C3%B8rensen%E2%80%93Dice_coefficient //IoU/Jaccard score - https://en.wikipedia.org/wiki/Jaccard_index

loss = smp.utils.losses.DiceLoss() metrics = [smp.utils.metrics.IoU(threshold=0.5),] optimizer = torch.optim.Adam([dict(params=model.parameters(), lr=0.0001),])

//create epoch runners //it is a simple loop of iterating over dataloader`s samples train_epoch = smp.utils.train.TrainEpoch(model, loss=loss, metrics=metrics, optimizer=optimizer, device=DEVICE, verbose=True,)

valid_epoch = smp.utils.train.ValidEpoch(model, loss=loss, metrics=metrics, device=DEVICE, verbose=True,)

qubvel commented 3 weeks ago

Hi, thanks for the issue, yes, the utils code is deprecated and going to be removed. I am planning to update example in favor to use PyTorch lightning. As for now you can refer to binary segmentation example.

P.S. utils is still accessible, but should be imported as from segmentation_models_pytorch import utils

atekgul commented 3 weeks ago

Thanks.