question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to do inference using grid sampler and how does it exactly work?

See original GitHub issue

Hi All,

I want to perform inference on a multi modal data using the grid sampler. However, I am not able to wrap my head around the working of the grid sampler in this link: https://torchio.readthedocs.io/data/patch_inference.html?highlight=gridsample

Here, it says that:

grid_sampler = torchio.inference.GridSampler(
    sample,
    patch_size,
    patch_overlap,
)

Here the sample is one individual object of the Subject class? I was just wondering if this would become a little clumsy while performing inference on a list of subjects?Or do I just create a list of grid_samplers and iterate through them?

It would be great if you could point me to an example which does inference for an entire list of images.

Thanks you!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
meghbhaleraocommented, Aug 8, 2020

Hi @fepegar, Thanks a lot for your explanation. I understood it.

0reactions
fepegarcommented, Aug 8, 2020

What I would do is something like:

for subject in dataset:
    subject_grid_sampler = GridSampler(subject, ...)  # the patches positions are computed here
    aggregator = GridAggregator(subject_grid_sampler)  # the aggregator checks the sampler to take decisions about overlap or padding
    loader = DataLoader(subject_grid_sampler, batch_size=B)
    for batch in loader:
        inputs, locations = prepare_batch(batch)
        outputs = model(input)    
        aggregator.add_batch(outputs, locations)
    output_tensor = aggregator.get_output_tensor()

Why would you need a data loader for the subjects? Would you like to load them in parallel? In that case, you can use a DataLoader with collate_fn=lambda x: x and the subjects data loader will return a list of instances of Subject that you can iterate through, using another data loader to run the inference on multiple patches at the same time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Grid Sampler and Aggregator do not take the Protected ...
I'm currently setting my dataset up for inference and stumbled across the Grid Sampler and Aggregator (as stated by the Tutorials on Colab)....
Read more >
Inference - TorchIO - Read the Docs
Grid samplers are useful to perform inference using all patches from a volume. It is often used with a GridAggregator . Parameters: subject...
Read more >
Computing probability distributions on a grid
And in more than 1 or 2 or 3 dimensions, using the entire grid is almost never practical, so sampling works as a...
Read more >
Module 7: Introduction to Gibbs Sampling
Suppose p(x,y) is a p.d.f. or p.m.f. that is difficult to sample from directly. ... We will use Gibbs sampling to perform inference...
Read more >
Chapter 4 Approximate inference | Bayesian Inference 2019
Simulation: generate a random sample from the posterior distribution, and use its empirical distribution function as an approximation of the posterior.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found