How to use monai.transforms (Dictionary Transforms) when there are more than 2 keys? #6903
-
Hi! Thanks for your great work MONAI!
I already know how to solve a dataset like {"image1":xxx, "label1":xxx} and did not get any error, but still don't know how to do on dataset like {"image1":xxx, "image2":xxx, "label1":xxx}. I have a dicom datasets which is like:
ps. img1 and img2 are the raw image from same patient but different view/shape, img1 and label1 have the same shape. I pack my input as: train_files = [{'image1': image_1, 'image2': image_2, 'label1': label_1} for image_1, image_2, label_1 in zip(img1_train_files, img2_train_files, label1_train_files)] data transforms I used are: train_transform = transforms.Compose(
[
transforms.LoadImaged(keys=["image1", "image2", "label1"], image_only=True),
transforms.RandCropByPosNegLabeld(
keys=["image1", "image2", "label1"],
label_key="label_1",
spatial_size=(args.roi_x, args.roi_y),
pos=1,
neg=1,
num_samples=args.num_samples,
image_key="image1",
image_threshold=0,
),
transforms.RandFlipd(keys=["image1", "image2", "label1"], prob=args.RandFlipd_prob, spatial_axis=0),
transforms.RandFlipd(keys=["image1", "image2", "label1"], prob=args.RandFlipd_prob, spatial_axis=1),
transforms.RandRotate90d(keys=["image1", "image2", "label1"], prob=args.RandRotate90d_prob, max_k=3),
transforms.ToTensord(keys=["image1", "image2", "label1"]),
]
) But I got some errors and don't know how to change my code.
ps. If I comment out the code about Hope someone could help me, thanks a lot!!! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
if it's caused by the inconsistent shape of |
Beta Was this translation helpful? Give feedback.
if it's caused by the inconsistent shape of
image1
andimage2
, I think you can try adding amonai.transforms.ResampleToMatchd("image2", "image1"),
after loadimage. (converting this to a discussion for now)