MIC-DKFZ / batchgenerators

A framework for data augmentation for 2D and 3D image classification and segmentation
Apache License 2.0
1.1k stars 221 forks source link

How to do batchgenerator on many images in a folder? #103

Open hiSyukri opened 2 years ago

hiSyukri commented 2 years ago

I would like to know on how can I do batchgenerator on many images in a folder? Because right now in the code example_ipynb.ipynb is using the self._data; which mean the data from skimage. Because I have many datasets to be run.

`class DataLoader(DataLoaderBase): def init(self, data, BATCH_SIZE=2, num_batches=None, seed=False): super(DataLoader, self).init(data, BATCH_SIZE, num_batches, seed)

data is now stored in self._data.

def generate_train_batch(self):
    # usually you would now select random instances of your data. We only have one therefore we skip this
    img = self._data

    # The camera image has only one channel. Our batch layout must be (b, c, x, y). Let's fix that
    img = np.tile(img[None, None], (self.BATCH_SIZE, 1, 1, 1))

    # now construct the dictionary and return it. np.float32 cast because most networks take float
    return {'data':img.astype(np.float32), 'some_other_key':'some other value'}`

this is the code.

Need your guide in this matter.

Thank you.