Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to apply volumentations to dataset for semantic segmentation #23

Open
kenbridge6 opened this issue Feb 6, 2023 · 2 comments
Open

Comments

@kenbridge6
Copy link

Hi, thanks for sharing this variable tool!
I'm tring to use volumentations to augment 3d images for semantic segmentation, but I've got an error.
The code is like this:

#21 images and masks with the size of 64*64*64 voxels
#image_list.shape: (21, 64, 64, 64, 1) 
#mask_list.shape: (21, 64, 64, 64, 1) 

def get_augmentation(patch_size):
    return Compose([
        Rotate((-5, 5), (-5, 5), (-5, 5), p=0.5),
        Flip(0, p=0.5),
    ], p=1.0)

aug = get_augmentation((64, 64, 64))

def aug_image_mask(image, mask):    
    aug_data = aug(**{'image':image, 'mask':mask})
    img, msk = aug_data['image'], aug_data['mask']
    return img, msk

@tf.function
def aug_dataset(image, mask):
    aug_image, aug_mask = tf.numpy_function(func=aug_image_mask, inp=[image, mask], Tout=tf.float32)
    return aug_image, aug_mask

train_dataset = tf.data.Dataset.from_tensor_slices((image_list, mask_list))
aug_train_dataset = train_dataset.map(aug_dataset)

And I've got a following error message:
OperatorNotAllowedInGraphError: Iterating over a symbolic tf.Tensor is not allowed: AutoGraph did convert this function. This might indicate you are trying to use an unsupported feature.

I'd like to know how to make an augmented dataset.

Thanks for your help in advance!

@ZFTurbo
Copy link
Owner

ZFTurbo commented Feb 6, 2023

From error message I can see you try to apply function to tf.Tensor. Please check if you give on input of function numpy arrays.

@kenbridge6
Copy link
Author

Thank you for your comment!
Finally I could augment images offline by applying the function to original numpy arrays:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants