Process a batch of images and questions
(model, batch_images, batch_questions, id_list, all_outputs)
| 73 | json.dump(all_outputs, f, indent=2, ensure_ascii=False) |
| 74 | |
| 75 | def process_batch(model, batch_images, batch_questions, id_list, all_outputs): |
| 76 | """Process a batch of images and questions""" |
| 77 | batch_results = model.count_objects_batch(batch_images, batch_questions) |
| 78 | |
| 79 | for i, result in enumerate(batch_results): |
| 80 | try: |
| 81 | thinking = result["thinking"] |
| 82 | bboxes = result["bboxes"] |
| 83 | pred_count = result["count"] |
| 84 | |
| 85 | all_outputs.append({ |
| 86 | "image_id": id_list[i]["image_id"], |
| 87 | "ann_id": id_list[i]["ann_id"], |
| 88 | "think": thinking, |
| 89 | "pred_count": pred_count, |
| 90 | "gt_count": id_list[i]["gt_count"] |
| 91 | }) |
| 92 | |
| 93 | except Exception as e: |
| 94 | # raise |
| 95 | print(f"Error processing result: {e}") |
| 96 | # Add penalty in this situation |
| 97 | all_outputs.append({ |
| 98 | "image_id": id_list[i]["image_id"], |
| 99 | "ann_id": id_list[i]["ann_id"], |
| 100 | "think": "", |
| 101 | "pred_count": 1, |
| 102 | "gt_count": id_list[i]["gt_count"] |
| 103 | }) |
| 104 | |
| 105 | print(f"Processed batch of {len(batch_images)} images") |
| 106 | |
| 107 | |
| 108 | if __name__ == "__main__": |
no test coverage detected