Code Monkey home page Code Monkey logo

Comments (7)

fepegar avatar fepegar commented on July 23, 2024 1

Fixed in #981. Thanks @jmlipman for your detailed report and code to reproduce.

from torchio.

fepegar avatar fepegar commented on July 23, 2024

Thanks for reporting, @jmlipman. This is bad. I've reproduced with the following code:

from collections import Counter

import numpy as np
from rich import print
import torch
from torch.utils.data import DataLoader
import torchio as tio


torch.manual_seed(42)
image_size = 10, 10, 10
patch_size = 10, 10, 1
batch_size = 10
num_subjects = 10
samples_per_volume = 8
max_queue_length = 50

subjects = []
for sub_id in range(num_subjects):
    data = np.random.random((1, *image_size))
    params = {
        "im": tio.ScalarImage(tensor=data),
        "info": sub_id,
    }
    subjects.append(tio.Subject(**params))


dataset = tio.SubjectsDataset(subjects)
sampler = tio.data.UniformSampler(patch_size)
queue = tio.Queue(
    dataset,
    max_length=max_queue_length,
    samples_per_volume=samples_per_volume,
    sampler=sampler,
    verbose=True,
)

tr_loader = DataLoader(
    queue,
    batch_size=batch_size,
    shuffle=False,
)

# One epoch of training
all_patch_ids = []
for patch in tr_loader:
    ids = patch["info"].tolist()
    print(ids)
    all_patch_ids.extend(ids)

print()

counter = Counter(all_patch_ids)
for key in sorted(counter):
    print(f'{key}: {counter[key]}')

Output:

Creating subjects loader with 0 workers
Patches list is empty.
[4, 4, 3, 6, 7, 4, 4, 4, 5, 3]
[7, 4, 7, 6, 2, 5, 0, 4, 6, 7]
[7, 2, 3, 6, 3, 7, 5, 5, 6, 6]
[2, 4, 7, 5, 3, 0, 6, 7, 3, 2]
[3, 2, 3, 2, 6, 5, 2, 5, 2, 5]
Patches list is empty.
Queue is empty:

Creating subjects loader with 0 workers
[8, 8, 1, 4, 4, 3, 3, 5, 5, 3]
[4, 5, 5, 4, 8, 3, 0, 3, 3, 1]
[1, 5, 5, 1, 5, 8, 8, 3, 5, 1]

0: 3
1: 5
2: 8
3: 15
4: 12
5: 16
6: 8
7: 8
8: 5

I'll debug it and come back to you.

from torchio.

fepegar avatar fepegar commented on July 23, 2024

It's independent of the "new" behavior, so I've edited the code above to use the queue normally.

from torchio.

fepegar avatar fepegar commented on July 23, 2024

Here's the output for 8ee2ab2 (#795):

Creating subjects loader with 0 workers
Patches list is empty.
/Users/fernando/git/torchio/torchio/data/queue.py:219: RuntimeWarning: Queue length (50) not divisible by the number of patches per volume (8)
  warnings.warn(message, RuntimeWarning)
Filling queue from 6 subjects...
[3, 5, 5, 3, 7, 5, 2, 5, 6, 2]
[7, 4, 3, 2, 4, 3, 4, 6, 7, 7]
[3, 6, 4, 5, 2, 5, 3, 5, 2, 6]
[7, 4, 7, 6, 3, 6, 4, 6, 2, 2]
Patches list is empty.
Filling queue from 6 subjects...
  0%|                                                                                                                                                          | 0/6 [00:00<?, ?it/s]Queue is empty:

Creating subjects loader with 0 workers
[7, 7, 2, 3, 5, 4, 4, 6, 8, 8]
[0, 8, 9, 9, 1, 0, 1, 1, 8, 9]
[1, 8, 9, 1, 8, 1, 0, 9, 1, 9]
[8, 0, 1, 8, 1, 1, 0, 8, 8, 0]

0: 6
1: 10
2: 8
3: 8
4: 8
5: 8
6: 8
7: 8
8: 10
9: 6

And for max queue length 40:

Creating subjects loader with 0 workers
Patches list is empty.
Filling queue from 5 subjects...
[7, 4, 2, 6, 6, 3, 7, 3, 3, 7]
[7, 2, 2, 3, 4, 4, 2, 7, 4, 6]
[6, 2, 4, 7, 6, 4, 3, 6, 4, 3]
[2, 3, 6, 3, 6, 2, 4, 2, 7, 7]
Patches list is empty.
Filling queue from 5 subjects...
[9, 8, 0, 5, 5, 9, 5, 1, 1, 8]
[8, 1, 9, 8, 9, 0, 1, 9, 0, 9]
[9, 0, 5, 1, 0, 1, 8, 0, 5, 5]
[1, 5, 8, 0, 5, 0, 9, 8, 1, 8]

0: 8
1: 8
2: 8
3: 8
4: 8
5: 8
6: 8
7: 8
8: 8
9: 8

So it's been broken at some point since then.

from torchio.

fepegar avatar fepegar commented on July 23, 2024

git bisect says we did break it in #795:

8ee2ab2f0caf66f4a1338b115fab1d014c754f6e is the first bad commit

from torchio.

fepegar avatar fepegar commented on July 23, 2024

For max queue length 41:

Creating subjects loader with 0 workers
Patches list is empty.
[7, 4, 7, 4, 6, 2, 4, 7, 2, 6]
[4, 3, 3, 6, 2, 7, 5, 7, 6, 2]
[3, 3, 3, 2, 4, 7, 3, 6, 6, 4]
[7, 3, 6, 4, 3, 2, 7, 2, 6, 4]
Patches list is empty.
Queue is empty:

Creating subjects loader with 0 workers
[2, 8, 0, 9, 0, 0, 9, 0, 8, 9]
[1, 9, 1, 1, 0, 0, 9, 0, 8, 0]
[0, 8, 8, 8, 0, 1, 0, 0, 1, 8]
[0, 8, 9, 0, 1, 9, 0, 0, 9, 8]

0: 16
1: 6
2: 8
3: 8
4: 8
5: 1
6: 8
7: 8
8: 9
9: 8

from torchio.

fepegar avatar fepegar commented on July 23, 2024

I think I got it. It only took me three hours 😅

from torchio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.