-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SegmentationDataset [feature proposal and demo] #1330
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1330 +/- ##
=========================================
- Coverage 65.78% 65.6% -0.19%
=========================================
Files 79 75 -4
Lines 5834 5814 -20
Branches 887 892 +5
=========================================
- Hits 3838 3814 -24
- Misses 1726 1734 +8
+ Partials 270 266 -4
Continue to review full report at Codecov.
|
Hello there, I made this pull request which I believe could be simple and generic enough. Looks like there are several pull requests on the same topic... Sorry for spamming. |
Thanks for the PR @Noiredd and sorry for the delay in replying! This is a very important discussion to have, I'm glad that you've opened this PR. Following my comment in #1345, I think that we should provide some examples in torchvision on how to use the current abstractions that we have in order to easily build those datasets. You example in #1345 (comment) is how I would start, with some slight changes: class BundleDataset(object):
def __init__(self, *datasets):
self.datasets = datasets
# here go sanity checks like asserting that all datasets are equal length
def __getitem__(self, index):
output = tuple(dataset[index] for dataset in self.datasets)
if self.transforms is not None:
output = self.transforms(*output)
return output
def __len__(self):
return len(self.datasets[0]) Those kind of generic datasets could potentially live somewhere (maybe in torchvision, maybe in PyTorch, maybe in As such, I think we are not going to be moving forward with this approach, but we should definitely find a common ground solution which is generic, modular and simple, similar to Let me know your thoughts. |
Do we want maximum abstraction and generality, or a solution to a specific problem? In the above example you merge multiple datasets and iterate over them. But as you noticed in this #1345 comment, we need to ensure the mapping between files in constituent folders. Where should that code live? Should Personally, I don't care much if I have to write: src = tv.datasets.folder.SegmentationDataset(
root='path/to/my_dataset',
transforms=tfs
) or src_img = tv.datasets.folder.ImageFolder(root='path/to/my_dataset/images')
src_lab = tv.datasets.folder.ImageFolder(root='path/to/my_dataset/labels', loader=label_loader)
src = whatever.BundleDataset((src_img, src_lab), transforms=tfs) as long as I don't have to copy&paste lines 255-275 (from this PR) every single time I want to run a segmentation task. |
The assumption in #1345 was that the user is responsible for making sure that when python sorts the filenames (this line and the next one ) they are in the proper order for all folders. This allows folders with names such as img1, img2... and label1, label2... to be mapped together in a simple way and we only need to check for the number of files. |
Hello @Noiredd and sorry for the very long delay in getting a new update. It looks like this PR and the #1345 one have been useful to discuss some of the requested segmentation and object detection features. Not yet sure how this could be implemented best or if it is enough to add some documentation using existing tools (for example @pmeier What do you think is best to do in this situation? There are some visualization tools here for example but nothing directly linked to segmentation datasets or maybe I haven't looked close enough. @Noiredd Is this something you are still thinking about or maybe you found an alternative? Please let us know if things have evolved. Many thanks in advance for your feedback and sorry for taking that long to get news. |
IMO the main issue is that there is no "agreed" file structure for segmentation datasets. Thus, we would need to enforce one, which in turn might clash with some datasets or other libraries that also provide dataset wrappers. In such a case I prefer to not provide a builtin solution. @Noiredd We are refactoring our datasets to use vision/torchvision/prototype/datasets/_folder.py Lines 44 to 49 in c67a583
Expanding that to whatever layout you have locally is not hard. Let me know if you disagree. @yassineAlouini Thanks for the follow-up. |
In addition to #1315, I propose a new dataset subclass for loading samples compatible with the processing pipeline. In essence, if we have a root folder containing
images
andlabels
subfolders, this class loads and returns samples in form of tuples(image, label)
. We can pass aSegmentationCompose
directly to it, immediately allowing data preprocessing/augmentations, just like withImageFolder
andCompose
.This is just a proposal/prototype, so some desired features are missing (e.g. checking for file validity, size matching assertions, etc.). Yes, I know that the normal flow for feature proposals is to start with an issue, but since I've already written it (as I need something like this in my own work), I decided to open a PR. I hope you don't mind and we can discuss it here - besides, that might be easier with a code example ;)
Example usage:
But with #1315 we could take this a step further: