Open sipie800 opened 1 year ago
when you are passing "bboxes" in label_feilds of A.Bboxparams() then it understands that you have kept your labels just after the bounding box details e.g: your boxes looks like boxes=[[0.1, 0.1, 0.01, 0.01,<your class label>],[0.1, 0.1, 0.01, 0.01,<your class label>]]
but you are not providing the class labels in last of each box hence it trims hence it assumes the last element as class label that is why you are only getting three values in each box in output bboxes.
If you want to provide the labels in seperate list you have to give "class_labels" in the label_feilds. means label_feilds=["class_labels"]
<------------------------------------1st Method--------------------------------------------->
import numpy as np import albumentations as A
album=A.Compose([ A.Resize(height=64, width=64) , A.RandomScale(p=1.0, scale_limit=(-0.5, 0.5)) ],bbox_params=A.BboxParams(format="yolo", label_fields=["class_labels"]))
img=np.random.randint(112, 128, [1280, 1280, 3], dtype=np.uint8)
boxes = [[0.1, 0.1, 0.01, 0.01],[0.3, 0.5, 0.01, 0.01]] cls=[0,1]
r = album(image=img, bboxes=boxes,class_labels=cls, cropping_bbox=boxes[0] ) print("bboxes are : ",r["bboxes"]) print("labels are : ",r["class_labels"])
Output: - bboxes are : [(0.1, 0.1, 0.009999999999999995, 0.009999999999999995), (0.3, 0.5, 0.010000000000000009, 0.010000000000000009)] labels are : [0, 1] <------------------------------------------2nd Method-------------------------------------->
import numpy as np import albumentations as A
album=A.Compose([ A.Resize(height=64, width=64) , A.RandomScale(p=1.0, scale_limit=(-0.5, 0.5)) ],bbox_params=A.BboxParams(format="yolo", label_fields=["bboxes"]))
img=np.random.randint(112, 128, [1280, 1280, 3], dtype=np.uint8)
boxes = [[0.1, 0.1, 0.01, 0.01],[0.3, 0.5, 0.01, 0.01]] cls=[0,1]
boxes=[box+[label] for box,label in zip(boxes,cls)]
r = album(image=img, bboxes=boxes,class_labels=cls, cropping_bbox=boxes[0] ) print("bboxes are : ",r["bboxes"]) print("labels are : ",r["class_labels"])
Output :- bboxes are : [[0.1, 0.1, 0.01, 0.01], [0.3, 0.5, 0.01, 0.01]] labels are : [0, 1] <------------------------------------------------------------------------------------------>
Please visit this link for more details: https://albumentations.ai/docs/getting_started/bounding_boxes_augmentation/
import numpy as np import albumentations as A
album=A.Compose([ A.Resize(height=64, width=64) , A.RandomScale(p=1.0, scale_limit=(-0.5, 0.5)) ],bbox_params=A.BboxParams(format="yolo", label_fields=["bboxes"]))
img=np.random.randint(112, 128, [1280, 1280, 3], dtype=np.uint8) boxes = [[0.1, 0.1, 0.01, 0.01],[0.1, 0.1, 0.01, 0.01]] cls=[0,1]
r = album(image=img, bboxes=boxes, class_labels=cls, cropping_bbox=boxes[0] ) print(r["bboxes"])
[[0.1, 0.1, 0.01], [0.1, 0.1, 0.01]]
why are the boxes cut to only 3 values? I do nothing wrong and it runs.