Closed LingsiDS closed 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.
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
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.
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.
@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.
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.
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:
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.
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
I updated the link for downloading the best checkpoint from my runs in March 2023.
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.
@LingsiDS, you are welcome!
The checkpoint file download link is disabled. Can you reopen the download link. Many thanks