'label_fields' are not valid even when assigning label fields in Albumentations

425 Views Asked by At

I'm using albumentations with the following code:

 augmentor = alb.Compose([alb.RandomCrop(width=450, height=450),
                             alb.HorizontalFlip(p=0.5),
                             alb.RandomBrightnessContrast(p=0.2),
                             alb.RandomGamma(p=0.2),
                             alb.RGBShift(p=0.2),
                             alb.VerticalFlip(p=.5)],
                             bbox_params=alb.BboxParams(format='albumentations', label_fields=['person']))

"intermediary image-loading code"

img = pyplot.imread("path")
coords = [1,2,3,4]
try:
    augmented = augmentor(image=img, bboxes=[coords], class_labels=['person'])

except Exception as e:
    print(e)

I get the exception: Your 'label_fields' are not valid - them must have same names as params in dict

I looked online and found some other people with the same issue but never found a concrete solution. I also looked at the documentation, and I couldn't decipher how data was supposed to relate to my issue. Any help on this would be much appreciated!

Also, for some reason, pressing "tab" doesn't work on this website, so the indentation might be off.

2

There are 2 best solutions below

0
aSquaredRush On BEST ANSWER

I was a bit stupid. label_fields=['person'] needs to be changed to label_fields=['class_labels']

Also the [1,2,3,4] aren't normalized as in the format that the albumentations format requires. It's purely just there as a placeholder for an actual list.

0
Hadi On
import numpy as np
import albumentations as A

category_id = [0, 1, 2] 
bbox = [[1,2,3,4], [4,5,6,7], [8,9,10,11]]

trans = A.Compose([
    A.HorizontalFlip(p=0.5), 
], bbox_params=A.BboxParams(format='coco', label_fields=['any_name']))

augmented = trans(image=np.array(image), bboxes=bbox, any_name=category_id)

It took me a while to realize the issue is that the label_fields parameter in bbox_params needs to match the key used. "noted by "any_name" "

Just wanted to document this in case others run into the same confusion with these parameters.