Giter Site home page Giter Site logo

Comments (6)

fepegar avatar fepegar commented on July 24, 2024

Idea:

subject_1 = {
    'image': {
        'T1': path,
        'T2': path,
    },
    'label': path,
}
subject_2 = {
    'image': {
        'T1': path,
        'T2': path,
    },
    'label': path,
}
paths = [subject_1, subject_2]

And then

CHANNELS_DIMENSION = 1
t1_tensor = batch['image']['T1']
t2_tensor = batch['image']['T2']
model_input = torch.cat((t1_tensort2_tensor), dim=CHANNELS_DIMENSION)

from torchio.

fepegar avatar fepegar commented on July 24, 2024

@romainVala

from torchio.

romainVala avatar romainVala commented on July 24, 2024

yes sound good, I see the point
may be the code could understand the 2 possibles data structure, (just by testing if subject_1['image'] is a dict, so that for the case of single modality one could stay with the previous simpler definition.
but we can also force the user to use this description.... as you want

from torchio.

romainVala avatar romainVala commented on July 24, 2024

Actually an other possibility is to just use on "dictionary" level but with specific keyword: (containing the "image" string)
for instance:
suj1={
'image_1' : path,
'image_2' : path,
'label' : path,}

the in the code, you can do something like
image_keys = [ll for ll in batch if 'image' in ll]
all_images = [batch[ik].squeeze() for ik in image_keys]
model_input = np.stack( all_images)

the code is more vebose, but the input structure more simple ... it is just a convention choice

from torchio.

romainVala avatar romainVala commented on July 24, 2024

Actually I need something very similar for the label definition. In the case I want to learn from probability labels (and not binairy ones) I need to have the label concatenate in the channel dimension

this is what I added in the getitem from ImagesDataset :
after line 56 (when the sample dict is filled)

    label_name = [kk for kk in sample if ('label' in kk) ]
    if len(label_name) > 1:
        list_label = [sample[kkk].squeeze() for kkk in label_name]
        for kkk in label_name : 
            del sample[kkk]  #remove label_1 label_2 ... entery
        sample['label'] = np.stack(list_label)

from torchio.

fepegar avatar fepegar commented on July 24, 2024

I ended up using this design: https://github.com/fepegar/torchio/blob/master/examples/example_multimodal.py#L37-L54

I think it's clear, generic and not too hard-coded. Please let me know what you think.

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.