Process a batch of images and questions
(model, batch_images, batch_questions, id_list, all_outputs)
| 79 | json.dump(all_outputs, f, indent=2, ensure_ascii=False) |
| 80 | |
| 81 | def process_batch(model, batch_images, batch_questions, id_list, all_outputs): |
| 82 | """Process a batch of images and questions""" |
| 83 | batch_results = model.answer_questions_batch_math(batch_images, batch_questions) |
| 84 | |
| 85 | for i, result in enumerate(batch_results): |
| 86 | try: |
| 87 | thinking = result["thinking"] |
| 88 | answer = result["answer"] |
| 89 | |
| 90 | all_outputs.append({ |
| 91 | "text": id_list[i]["text"], |
| 92 | "think": thinking, |
| 93 | "prediction": id_list[i]['choices'][ord(answer.strip().lower()[0]) - ord('a')] if id_list[i]['choices'] is not None else answer, |
| 94 | "ground_truth": id_list[i]['answer'], |
| 95 | "choices": id_list[i]['choices'] if 'choices' in id_list[i] else None |
| 96 | }) |
| 97 | |
| 98 | except Exception as e: |
| 99 | print(f"Error processing result: {e}, Raw answer is {answer}") |
| 100 | # Add penalty in this situation |
| 101 | all_outputs.append({ |
| 102 | "text": id_list[i]["text"], |
| 103 | "think": "", |
| 104 | "prediction": "", |
| 105 | "ground_truth": id_list[i]['answer'], |
| 106 | "choices": id_list[i]['choices'] if 'choices' in id_list[i] else None |
| 107 | }) |
| 108 | |
| 109 | if __name__ == "__main__": |
| 110 | main() |
no test coverage detected