Skip to content
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

Improve label sampler efficiency #6

Closed
fepegar opened this issue Dec 6, 2019 · 10 comments · Fixed by #175
Closed

Improve label sampler efficiency #6

fepegar opened this issue Dec 6, 2019 · 10 comments · Fixed by #175
Assignees
Labels
enhancement New feature or request

Comments

@fepegar
Copy link
Owner

fepegar commented Dec 6, 2019

No description provided.

@fepegar fepegar self-assigned this Dec 6, 2019
@fepegar fepegar added the enhancement New feature or request label Dec 6, 2019
@romainVala
Copy link
Contributor

I see the warning from the doc, but did not look at the code yet,

Actually I was looking for a sampler, that contains the center of the patch within the label. (it is a more conservative alternative to the current setting "at least one non background voxel")

The implementation just need to randomly sample (for the patch center) the coordinate of the label mask ... it should be fast ?

@fepegar
Copy link
Owner Author

fepegar commented Mar 16, 2020

Yes I think that's the way to go. That's how NiftyNet works as well. I'll add a more generic weighted sampler. Then a label map can be used as sampler.

I need to think how to handle sampler images, though. That's why I also added a torchio.SAMPLER attribute. I guess the easiest is to treat them as torchio.LABEL and apply all spatial transforms using nearest neighbor interpolation. I'll try to work on this after the MICCAI deadline.

@romainVala
Copy link
Contributor

ok
it makes sens to indeed treat them as LABEL

@GFabien
Copy link
Contributor

GFabien commented May 12, 2020

Hi @fepegar, we will probably use the LabelSampler soon so I was wondering if there were any news regarding this issue.

I thought we could use the same signature with an extra argument that would be a list of probabilities for the different values in the label with default as [1/n] * n with n the number of different values. Checks would be added to make sure the length of the given list is equal to n and that probabilities sum to 1.

For the implementation itself, we could just draw a random number that decide which label value to focus on, then choose randomly a corresponding voxel from the label and return the patch centered on this voxel (with padding if needed).

Would that be enough or am I missing a deeper design choice that would lead to a different solution? In any case I would be happy to provide a PR if needed.

@fepegar
Copy link
Owner Author

fepegar commented May 15, 2020

I'll take a look at this next week. Before I forget, this is related to #50.

I think we can follow NiftyNet's approach, i.e. using weighted samplers. Then a label sampler would be a specific case, where the label map can be used as a weight map. They can be tricky, this needs to be done carefully (NifTK/NiftyNet#432).

@GFabien
Copy link
Contributor

GFabien commented May 26, 2020

Hi @fepegar! Any update on this issue?

@fepegar
Copy link
Owner Author

fepegar commented May 27, 2020

Sorry, I've been busy. I'll hopefully look into it on Friday.

@GFabien
Copy link
Contributor

GFabien commented May 27, 2020

No problem!

@fepegar fepegar mentioned this issue May 29, 2020
9 tasks
@fepegar
Copy link
Owner Author

fepegar commented May 29, 2020

I just spent some hours on this. See #175.

@fepegar fepegar linked a pull request May 31, 2020 that will close this issue
9 tasks
@fepegar
Copy link
Owner Author

fepegar commented Jun 1, 2020

Let me know if that implementation would work for you and I'll merge the changes ASAP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants