eisen-ai / eisen-core

Core functionality of Eisen
MIT License
41 stars 10 forks source link

Eisen trasformation #3

Closed bioinfo-dirty-jobs closed 4 years ago

bioinfo-dirty-jobs commented 4 years ago

I would like to save my input after normalization and resize as numpy. What is the procedure? thanks so much!!

eisen-ai commented 4 years ago

I don't know if I understand correctly... you would like to dump your data to disk right after it gets transformed (pre-processed).

You can do that by creating a new transformation:

import uuid

class DumpAsNumpy:
    def __init__(self, fields, path):
        self.fields = fields
        self.path = path

   def __call__(self, data):
       for field in self.fields:
           f_name = str(uuid.uuid4())
           numpy.save(data[field], os.path.join(self.path, f_name)

           data[self.field + '_file'] = f_name

        return data
eisen-ai commented 4 years ago

Of course this additional transform that dumps data to disk might not have exactly this form. But one instance of this object could be part of the transform chain and therefore save copied of data on the disk.

bioinfo-dirty-jobs commented 4 years ago

thanks so much!! I make some confusion I'm interested to use the data normalizated from you tool for extract radiomics. So, I wan to integrate deep learning model with radiomics. I just wondering how to save the data after trasformation on nifty format.

I have tried this code:

tform = Compose([
    read_tform, 
    resample_tform,
    to_numpy_tform,
    crop,
    map_intensities,
    threshold_labels,
    add_channel,
    DumpAsNumpy(fields=['image', 'label'],path="tmp/")
])

dataset = MSDDataset(
    PATH_DATA, 
    NAME_MSD_JSON, 
    'training', 
    transform=tform
)

I miss something .. how can save?

eisen-ai commented 4 years ago

you would need to write one more transformation which DumpsAsNifti. Right now DumpAsNumpy will dump files into the ./tmp folder (not into /tmp, because you didn't specify '/tmp' but 'tmp/' instead) in numpy format.