gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
I have the output of the detection model (Detectron2) in this form: [code] I need you to…
- User
I have the output of the detection model (Detectron2) in this form:
from detectron2.structures.boxes import Boxes from detectron2.structures.instances import Instances import torch predictions = self.model([inputs])[0] predictions is {'instances': Instances(num_instances=17, image_height=894, image_width=1956, fields=[pred_boxes: Boxes(tensor([[1342.8580, 567.1672, 1440.2976, 804.7666], [1026.9825, 495.4417, 1087.2439, 719.9641], [ 936.6356, 501.3313, 996.4190, 726.0863], [ 808.8970, 473.9571, 900.1006, 771.8304], [ 804.9727, 475.3264, 894.3956, 774.0923], [ 936.0687, 501.3820, 996.1431, 725.1507], [1026.8501, 496.5339, 1088.0425, 720.0636], [ 807.6366, 475.4641, 899.3647, 768.4396], [1027.5870, 494.4926, 1087.9760, 717.1454], [1343.2396, 558.3358, 1439.8544, 805.7205], [ 977.0064, 484.8623, 1059.6536, 722.5073], [ 920.1732, 515.0617, 975.9795, 716.7766], [ 936.4705, 500.2601, 995.0935, 718.4519], [ 936.6356, 501.3313, 996.4190, 726.0863], [1387.0321, 535.3624, 1493.3464, 806.8454], [ 988.8755, 511.1911, 1035.1339, 715.1887], [1341.1382, 571.3450, 1425.8055, 704.0261]])), scores: tensor([0.9617, 0.7202, 0.7060, 0.6041, 0.6024, 0.4157, 0.3545, 0.1761, 0.1729, 0.1587, 0.0746, 0.0713, 0.0688, 0.0630, 0.0615, 0.0550, 0.0530]), pred_classes: tensor([0, 1, 0, 1, 0, 1, 0, 2, 2, 1, 1, 0, 2, 3, 0, 0, 0])])}I need you to implement a method for post-processing that will filter out the boxes that are below the threshold of 0.5 by scores.
you should save the output format in the same form as the input format
- Assistant
Sure! Here's a simple implementation of a post-processing method that filters out boxes below the threshold and returns the output format in the same form as the input format:
from detectron2.structures.boxes import BoxMode from detectron2.structures.instances import Instances import torch def post_process(predictions, score_threshold=0.5): # Get the predicted boxes, scores, and classes pred_boxes = predictions['instances'].pred_boxes.tensor scores = predictions['instances'].scores pred_classes = predictions['instances'].pred_classes # Filter out boxes below the score threshold filter_indices = scores >= score_threshold pred_boxes = pred_boxes[filter_indices] scores = scores[filter_indices] pred_classes = pred_classes[filter_indices] # Create Instances object with the filtered boxes, scores, and classes instances = Instances((predictions['instances'].image_height, predictions['instances'].image_width)) instances.pred_boxes = BoxMode.convert(pred_boxes, BoxMode.XYXY_ABS, BoxMode.XYXY_ABS) instances.scores = scores instances.pred_classes = pred_classes # Return the post-processed predictions in the same form as the input format return {'instances': instances}
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.