MCPcopy Create free account
hub / github.com/TIGER-AI-Lab/TheoremExplainAgent / evaluate_sampled_images

Function evaluate_sampled_images

eval_suite/image_utils.py:63–104  ·  view source on GitHub ↗

Evaluate sampled frames from a video using an image evaluation model. Args: model: The image evaluation model to use video_path (str): Path to the input video file description (str, optional): Description of the video content. Defaults to "No description provided"

(model, video_path, description="No description provided", num_chunks=10, output_folder=None)

Source from the content-addressed store, hash-verified

61
62
63def evaluate_sampled_images(model, video_path, description="No description provided", num_chunks=10, output_folder=None):
64 """Evaluate sampled frames from a video using an image evaluation model.
65
66 Args:
67 model: The image evaluation model to use
68 video_path (str): Path to the input video file
69 description (str, optional): Description of the video content. Defaults to "No description provided"
70 num_chunks (int, optional): Number of chunks to divide the video into. Defaults to 10
71 output_folder (str, optional): Directory for temporary files. Defaults to None
72
73 Returns:
74 dict: Dictionary containing evaluation scores and individual frame assessments with keys:
75 - evaluation: Dictionary of averaged scores for each criterion
76 - image_chunks: List of individual frame evaluation results
77 """
78 with tempfile.TemporaryDirectory(dir=output_folder) as temp_dir:
79 key_frames = extract_key_frames(video_path, temp_dir, num_chunks)
80
81 prompt = _image_eval.format(description=description)
82
83 responses = []
84 for key_frame in key_frames:
85 inputs = _prepare_text_image_inputs(prompt, key_frame)
86 response = model(inputs)
87 response_json = extract_json(response)
88 response_json = convert_score_fields(response_json)
89 responses.append(response_json)
90
91 criteria = list(responses[0]["evaluation"].keys())
92 scores_dict = {c: [] for c in criteria}
93 for response in responses:
94 for key, val in response["evaluation"].items():
95 scores_dict[key].append(val["score"])
96
97 res_score = {}
98 for key, scores in scores_dict.items():
99 res_score[key] = {"score": calculate_geometric_mean(scores)}
100
101 return {
102 "evaluation": res_score,
103 "image_chunks": responses
104 }

Callers 1

process_theoremFunction · 0.90

Calls 5

extract_jsonFunction · 0.90
convert_score_fieldsFunction · 0.90
calculate_geometric_meanFunction · 0.90
extract_key_framesFunction · 0.85

Tested by

no test coverage detected