ValueError: Expected x_min for bbox (-0.0005000000000000004, 0.5085, 0.0385, 0.7675, 1) to be in the range [0.0, 1.0], got -0.0005000000000000004

63 views Asked by At

I annotated my images on cvat and export it in yolo format. Then, I tried using albumentations for augmenting my images. However, I have been tackling this problem where I even tried rounding the floating point number to just 1 digit after point, but still couldn't fixed it. a Here is my code :

augmentor = alb.Compose([ # Croppping
                        alb.ShiftScaleRotate(shift_limit=0.1, scale_limit=0.1, rotate_limit=30, p=0.2), # Shear
                        alb.RandomScale(scale_limit=0.2, p=0.2),
                        alb.HorizontalFlip(p=0.35),
                        alb.RandomBrightnessContrast(p=0.5),
                        alb.RandomGamma(p=0.5),
                        alb.RGBShift(p=0.2),
                        alb.VerticalFlip(p=0.5),
                        alb.Normalize(),],
                        bbox_params=alb.BboxParams(format='yolo', label_fields=['class_labels']))


augmented_images = []

for image_dir, label_dir in zip(os.listdir(imagesDir), os.listdir(labelsDir)):
    if image_dir != ".ipynb_checkpoints" and label_dir != ".ipynb_checkpoints":
        imageDir = os.path.join(imagesDir, image_dir)
        labelDir = os.path.join(labelsDir, label_dir)

        for images_file in os.listdir(imageDir):
            labels_file = os.path.join(labelDir,images_file.split("/")[-1][:-3] + 'txt')
            print("##########################")
            print(images_file)
            print(labels_file)
            print("##########################")
            
            image = cv2.imread(os.path.join(imageDir, images_file))
            image = cv2.resize(image,(480,480))
            image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
            
            with open(os.path.join(labels_file), "r") as label:
                labels = []
                bboxes = []
                for annotation in label.read().splitlines():
                    annotate = annotation.split(" ")
                    labels.append(int(annotate[0]))
                    x_min = round(float(annotate[1]), 3)
                    y_min = round(float(annotate[2]), 3)
                    width = round(float(annotate[3]), 3)
                    height =  round(float(annotate[4]), 3)

                    bboxes.append([x_min, y_min, width,height])
                    
            try:
                transformed = augmentor(image=image, bboxes=bboxes,class_labels=labels)
                augmented_images.append(transformed)
            except:
                print(f"Invalid Transformation for {str(bboxes)}")
            
                

Jupyter Cell output :

##########################
0004.jpg
./Dataset/labels/validation/0004.txt
##########################
Invalid Transformation for [[0.991, 0.283, 0.019, 0.17], [0.715, 0.457, 0.03, 0.036], [0.241, 0.328, 0.04, 0.157], [0.127, 0.227, 0.033, 0.108], [0.923, 0.415, 0.054, 0.207]]
##########################
0000.jpg
./Dataset/labels/validation/0000.txt
##########################
##########################
0169.jpg
./Dataset/labels/validation/0169.txt
##########################
Invalid Transformation for [[0.119, 0.358, 0.044, 0.172], [0.343, 0.243, 0.042, 0.151], [0.397, 0.255, 0.03, 0.143], [0.319, 0.571, 0.062, 0.296], [0.495, 0.454, 0.05, 0.213], [0.587, 0.426, 0.048, 0.156], [0.597, 0.536, 0.067, 0.14], [0.973, 0.621, 0.055, 0.299], [0.7, 0.078, 0.033, 0.113], [0.486, 0.505, 0.029, 0.062]]
##########################
0036.jpg
./Dataset/labels/validation/0036.txt
##########################
Invalid Transformation for [[0.183, 0.4, 0.072, 0.203], [0.303, 0.469, 0.049, 0.185], [0.473, 0.46, 0.045, 0.211], [0.551, 0.499, 0.053, 0.196], [0.55, 0.649, 0.08, 0.232], [0.677, 0.727, 0.062, 0.262], [0.976, 0.85, 0.04, 0.301], [0.891, 0.372, 0.041, 0.166]]
##########################

We can't see none of the xmin,ymin,height or width is outside the range [0,1].

Please help.

0

There are 0 answers