GeorgeBatch / kvasir-seg

[MediaEval Medico Challenge'2020]: Real-time polyp segmentation using U-Net with IoU loss
15 stars 3 forks source link

The checkpoint file download link is disabled #3

Closed LingsiDS closed 1 year ago

LingsiDS commented 1 year ago

The checkpoint file download link is disabled. Can you reopen the download link. Many thanks

GeorgeBatch commented 1 year ago

@LingsiDS, I checked the folder on OneDrive that the checkpoints are supposed to be in. The folder is indeed empty. I will try to find the weights.

If you are planning to use the code in the folder, I think it should not be hard to reproduce the weights by just running the notebooks on the data with the same train/val split.

Let me know if you need any help - I will gladly provide it. As I said, I will try to find the weights, and if I don't - I will try to reproduce them myself.

LingsiDS commented 1 year ago

Yes, it is not difficult to reproduce the results, I will try myself first. Thanks again

Buy the way, there are some mistakes in the code. https://github.com/GeorgeBatch/kvasir-seg/blob/b64e0c5767e08fdfb876317aec96ec983ec04985/utils/metrics.py#L345 should be if


sample = self.transforms(sample) In unet-baseline notebook

train_transforms = transforms.Compose([
                           transforms.Resize(_size, interpolation=0),
                           transforms.RandomRotation(180),
                           transforms.RandomHorizontalFlip(0.5),
                           transforms.RandomCrop(_size, padding = 10), # needed after rotation (with original size)
                       ])

test_transforms = transforms.Compose([
                           transforms.Resize(_size, interpolation=0),
                       ])

this transforms utils from torchvision seems only accept PIL Image as argument

GeorgeBatch commented 1 year ago

The metrics file has some metrics you won't see anywhere in the code. Only the metrics already used in the notebooks have been tested properly.

Pushing these untested metrics into the main/master branch was a mistake. As you can see, they have mistakes, such as you found with the elif statement without an if statement.

GeorgeBatch commented 1 year ago

I think whether the transforms work or not depends on the versions of torch and torchvision. If you make it work with the current versions (not the outdated versions from 2020, which I used back when the code was written) before I have time to update it, please make a pull request. I think adding a file describing the environment and package versions used will also be helpful.

GeorgeBatch commented 1 year ago

@LingsiDS

I updated the training code (put all in a script). The information about the environment is in the README. It all works for me now.

LingsiDS commented 1 year ago

Last week I tried to modify your code and train on kvasir-seg, but strange, the loss is negative, maybe my code has some mistakes, thanks for the update, I will try again later.

GeorgeBatch commented 1 year ago

Hi. If you have a look in the metrics file, the loss is defined as https://github.com/GeorgeBatch/kvasir-seg/blob/70a00b190ad2b6d057c6985f326897e1bd378e3f/utils/metrics.py#L261

The idea was that if you want the IoU between the binary mask and the predictions to be as big as possible, then you want the -IoU (or 1-IoU) to be as small as possible. So either can be defined as a loss function. I was told that sometimes one can have problems with optimisation if the loss is negative, but it was fine for me. Either way you want the loss as small as possible.

Note the difference:

  1. in the loss, I only apply sigmoid function to the predictions. I do not binaries the predictions to be either 0 or 1. This is done so the gradients can flow better: predicting 0.9 where the label is 1 should be better than predicting 0.7 for this same pixel.

  2. In a separate function to evaluate IOU for validation batches, I do binarise the predictions after applying sigmoid since this is how the IOU metric is actually calculated. https://github.com/GeorgeBatch/kvasir-seg/blob/70a00b190ad2b6d057c6985f326897e1bd378e3f/utils/metrics.py#L30

GeorgeBatch commented 1 year ago

I updated the link for downloading the best checkpoint from my runs in March 2023.

LingsiDS commented 1 year ago

Hi, George. Yes, as you said, either -IOU or 1-IOU can be used as a loss function. But in most cases it is positive, so at first I thought it was some wrong code. thank you for your enthusiasm and detailed explanation.

GeorgeBatch commented 1 year ago

@LingsiDS, you are welcome!