Replies: 2 comments 12 replies
-
I am thinking about something like this: import numpy as np
import monai
from monai.data import Dataset
from monai.transforms import LoadImage, Compose, Spacing, EnsureChannelFirst
class CustomDataset(Dataset):
def __init__(self, image_files, labels, transform=None):
self.image_files = image_files
self.labels = labels
self.transform = transform
def __len__(self):
return len(self.image_files)
def __getitem__(self, index):
img_paths = self.image_files[index]
img_list = [self.transform(path) for path in img_paths]
label = self.labels[index]
return img_list, label
transform = Compose([LoadImage(reader="PydicomReader", image_only=True, dtype=np.float32),
EnsureChannelFirst(channel_dim='no_channel'),
Spacing(pixdim=[RESIZE_DIM]*3),
])
check_ds = CustomDataset(image_files=paths, labels=labels, transform=transform)
im, label = check_ds[0]
print(type(im), [i.shape for i in im], label, label.shape) Any advise or more elegant solution would be appreciated! |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hi @grudloff, I think you can directly use Hope it helps, thanks! |
Beta Was this translation helpful? Give feedback.
12 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am fairly new to monai, so keep that in mind.
I am working with a classification task. The inputs are volumes (Height, Width, Depth), that are loaded by passing folder paths.
The classification are done over a patient, which can have multiple sessions (multiple volumes). Given the constraint of ImageDataset only accepting a single path for each label, the dataset obtained with the code bellow points to training the model on a per session manner.
Is there an straightforward way in monai to construct a dataset that accepts as input a list of lists of strs, and outputs a list of tensors? Or should I just build my own logic with a custom dataset that internally uses LoadImage?
In summary, I need a CustomDataset like this:
Beta Was this translation helpful? Give feedback.
All reactions