I am trying to use albumentations for my image recognition task but I have a little bit of problem while using this library. I have followed the documentation of albumentation in implementing this but I see the following error. ValueError: in user code:
File "/var/folders/ty/5qvxn8z53dg29rj28z94qmjr0000gn/T/ipykernel_1549/3096662177.py", line 3, in set_shapes *
label.set_shape([])
ValueError: Shapes must be equal rank, but are 1 and 0
Below are my code blocks
images = tf.keras.utils.image_dataset_from_directory(
data_dir,
labels='inferred',
shuffle=True,
image_size=(img_height, img_weight),
)
transforms = Compose([
Rotate(limit=40),
RandomBrightness(limit=0.1),
JpegCompression(quality_lower=85, quality_upper=100, p=0.5),
# HueSaturationValue(hue_shift_limit=20, sat_shift_limit=30, val_shift_limit=20, p=0.5),
RandomContrast(limit=0.2, p=0.5),
HorizontalFlip(),
])
def aug_fn(image, img_size):
data = {"image":image}
aug_data = transforms(**data)
aug_img = aug_data["image"]
aug_img = tf.cast(aug_img, tf.float32)
return aug_img
def process_data(image, label, img_size):
aug_img = tf.numpy_function(func=aug_fn, inp=[image, img_size], Tout=tf.float32)
return aug_img, label
aug_images= images.map(partial(process_data, img_size=112), num_parallel_calls=AUTOTUNE).prefetch(AUTOTUNE)
aug_images
def set_shapes(img, label, img_shape=(112,112,3)):
img.set_shape(img_shape)
label.set_shape([])
return img, label
aug_images2= aug_images.map(set_shapes, num_parallel_calls=AUTOTUNE).prefetch(AUTOTUNE)
aug_images2
I get this error while trying to set the shapes back to the original form