Hello Community!
I am working on an object detect project and need to create a ground truth annotation. I used Roboflow to do this, however, when I download the dataset using COCO format I realised that the annotations/bounding boxes are displaced. This is causing a significant issue regarding the precision, recall and f1 score while deploying a model. I have attached the screenshot of the image when running on python.
The image is as below when using python. We can see the significance differences in the bounding box and the objects it’s detecting (not so accurately) . Second image is from Roboflow.
The Python code used:
Setting the image path
image_path = ‘xxxxxx/downloads/Od123/valid/0000255_jpg.rf.63fd9d6b07e3e30f344aa710bd322ac1.jpg’
Load ground truth annotations (COCO format JSON)
with open(‘/xxxxxxxxx/downloads/Od123/valid/_annotations.coco.json’, ‘r’) as f:
coco_gt = json.load(f)
Extract image filename without extension
image_filename = image_path.split(‘/’)[-1].split(‘.’)[0]
Find annotations for the specific image filename
gt_annotations = [ann for ann in coco_gt[‘annotations’] if coco_gt[‘images’][ann[‘image_id’]][‘file_name’].split(‘.’)[0] == image_filename]
Read the image
frame = cv2.imread(image_path)
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
Draw the image with ground truth bounding boxes
for gt_annotation in gt_annotations:
bbox = gt_annotation[‘bbox’]
x, y, w, h = map(int, bbox)
cv2.rectangle(frame_rgb, (x, y), (x + w, y + h), (0, 255, 0), 2) # Green color for ground truth
Display the image with only ground truth bounding boxes
cv2.imshow(‘Ground Truth Bounding Boxes’, frame_rgb)
cv2.waitKey(0)
cv2.destroyAllWindows()
Has anyone experienced a similar problem? Would really appreciate any help.
Thank you!
- Object Detection:
- macOS - Safari:
- Od123 Object Detection Dataset by City University of London