I am using Detectron2 for object detection. I have registered pascalvoc dataset and trained a model for detection. How can I calculate Mean IOU of my test dataset ? I know that detection2 has a predefined function for calculating IOU i.e. detectron2.structures.pairwise_iou
I have the ground truth bounding boxes for test images in a csv file. The csv file contains (filename,width,height,class,xmin,ymin,xmax,ymax). How can I parse both the bounding boxes in IOU function and display it in google colab.
This is my code where I am generating a prediction bounding box
from detectron2.utils.visualizer import ColorMode
import random
dataset_dicts = DatasetCatalog.get('/content/test')
for d in random.sample(dataset_dicts, 5):
im = cv2.imread(d["file_name"])
outputs = predictor(im)
v = Visualizer(im[:, :, ::-1], metadata=microcontroller_metadata, scale=0.8)
v = v.draw_instance_predictions(outputs["instances"].to("cpu"))
plt.figure(figsize = (14, 10))
plt.imshow(cv2.cvtColor(v.get_image()[:, :, ::-1], cv2.COLOR_BGR2RGB))
plt.show()
You need to do what Alexander said. So let's say that for a given image you have the ground truth boxes. These you can be represented as an
N,4
numpy array. Let's call itbboxes_gt
. and let's say your prediction gives youM
bounding boxes.Now you can convert
bboxes_gt
into aBox
oobject and then usestructures.pairwise_iou()
to compute all IOUs in a pariwise fashion. This will give you anN,M
matrix with all these IOUs. It would look something like this: