@@ -141,19 +141,19 @@ def create_robodm_dataset(self, robodm_dir: str) -> VLADataset:
141141
142142 return dataset
143143
144- def calculate_trajectory_captioning_f1 (self , dataset : VLADataset ):
144+ def calculate_trajectory_captioning_accuracy (self , dataset : VLADataset ):
145145 """
146- Calculate F1 score for trajectory captioning by comparing VLM-generated captions
146+ Calculate accuracy for trajectory captioning by comparing VLM-generated captions
147147 with ground truth language descriptions from metadata using LLM for semantic matching.
148148
149149 Args:
150150 dataset: VLADataset with loaded trajectories
151151
152152 Returns:
153- float: F1 score for caption similarity
153+ float: Accuracy of caption matching
154154 """
155155 print ("\n " + "=" * 60 )
156- print ("TRAJECTORY CAPTIONING F1 CALCULATION" )
156+ print ("TRAJECTORY CAPTIONING ACCURACY CALCULATION" )
157157 print ("=" * 60 )
158158
159159 # Create output directory for captioning results
@@ -339,12 +339,8 @@ def extract_caption_and_description(trajectory: Dict[str, Any]) -> Dict[str, Any
339339 results_dataset = dataset .map (extract_caption_and_description ).materialize ()
340340 results = list (results_dataset .iter_rows ())
341341
342- # Calculate F1 score based on LLM matching
343- true_positives = 0 # VLM correctly identifies matching tasks
344- false_positives = 0 # VLM incorrectly claims match
345- false_negatives = 0 # VLM misses a match
346- true_negatives = 0 # VLM correctly identifies non-match (not applicable here)
347-
342+ # Calculate accuracy based on LLM matching
343+ correct_matches = 0 # Number of correct caption matches
348344 valid_comparisons = 0
349345 skipped_trajectories = 0
350346
@@ -360,63 +356,47 @@ def extract_caption_and_description(trajectory: Dict[str, Any]) -> Dict[str, Any
360356 valid_comparisons += 1
361357
362358 # Get the match result
363- predicted_match = result ["is_match" ]
364-
365- # In this context, we assume ground truth is that captions SHOULD match
366- # (since VLM is describing the same trajectory)
367- actual_match = True
359+ is_match = result ["is_match" ]
368360
369- if predicted_match and actual_match :
370- true_positives += 1
371- elif not predicted_match and actual_match :
372- false_negatives += 1
361+ # Count correct matches (we expect captions to match ground truth)
362+ if is_match :
363+ correct_matches += 1
373364
374- status = "✅" if predicted_match else "❌"
375- print (f"{ status } { result ['trajectory_name' ]} : { 'MATCH' if predicted_match else 'NO MATCH' } " )
365+ status = "✅" if is_match else "❌"
366+ print (f"{ status } { result ['trajectory_name' ]} : { 'MATCH' if is_match else 'NO MATCH' } " )
376367 print (f" Explanation: { result ['comparison_explanation' ]} " )
377368 print ()
378369
379- # Calculate metrics
370+ # Calculate accuracy
380371 if valid_comparisons > 0 :
381- # Precision: Of all predicted matches, how many were correct?
382- precision = true_positives / (true_positives + false_positives ) if (true_positives + false_positives ) > 0 else 0
383-
384- # Recall: Of all actual matches, how many did we find?
385- recall = true_positives / (true_positives + false_negatives ) if (true_positives + false_negatives ) > 0 else 0
386-
387- # F1 Score
388- f1_score = 2 * (precision * recall ) / (precision + recall ) if (precision + recall ) > 0 else 0
372+ accuracy = correct_matches / valid_comparisons
389373 else :
390- precision = recall = f1_score = 0
374+ accuracy = 0
391375 print ("⚠️ No valid comparisons found (missing ground truth or captions)" )
392376
393377 print (f"\n Overall Captioning Metrics:" )
394378 print (f"Total trajectories: { len (results )} " )
395379 print (f"Successful trajectories processed: { valid_comparisons } " )
396380 print (f"Failed trajectories skipped: { skipped_trajectories } " )
397- print (f"Matches (True Positives): { true_positives } " )
398- print (f"No Matches (False Negatives): { false_negatives } " )
399- print (f"Precision: { precision :.3f} " )
400- print (f"Recall: { recall :.3f} " )
401- print (f"F1 Score: { f1_score :.3f} " )
381+ print (f"Correct matches: { correct_matches } " )
382+ print (f"Incorrect matches: { valid_comparisons - correct_matches } " )
383+ print (f"Accuracy: { accuracy :.3f} ({ correct_matches } /{ valid_comparisons } )" )
402384
403385 # Summary of results
404- summary_filename = caption_output_dir / "captioning_f1_summary .txt"
386+ summary_filename = caption_output_dir / "captioning_accuracy_summary .txt"
405387 with open (summary_filename , 'w' ) as f :
406- f .write (f"Trajectory Captioning F1 Summary\n " )
407- f .write (f"================================\n " )
388+ f .write (f"Trajectory Captioning Accuracy Summary\n " )
389+ f .write (f"===================================== \n " )
408390 f .write (f"Total trajectories: { len (results )} \n " )
409391 f .write (f"Successful trajectories processed: { valid_comparisons } \n " )
410392 f .write (f"Failed trajectories skipped: { skipped_trajectories } \n " )
411- f .write (f"Matches (True Positives): { true_positives } \n " )
412- f .write (f"No Matches (False Negatives): { false_negatives } \n " )
413- f .write (f"Precision: { precision :.3f} \n " )
414- f .write (f"Recall: { recall :.3f} \n " )
415- f .write (f"F1 Score: { f1_score :.3f} \n " )
393+ f .write (f"Correct matches: { correct_matches } \n " )
394+ f .write (f"Incorrect matches: { valid_comparisons - correct_matches } \n " )
395+ f .write (f"Accuracy: { accuracy :.3f} ({ correct_matches } /{ valid_comparisons } )\n " )
416396
417397 print (f"\n ✅ Results saved to { caption_output_dir } /" )
418398
419- return f1_score
399+ return accuracy
420400
421401 def calculate_f1_matrix (self , dataset : VLADataset ):
422402 """
@@ -617,10 +597,10 @@ def main():
617597 # print("\n5. Calculating F1 Matrix...")
618598 # detector.calculate_f1_matrix(dataset)
619599
620- # Step 6: Calculate Trajectory Captioning F1
621- print ("\n 6. Calculating Trajectory Captioning F1 ..." )
622- captioning_f1 = detector .calculate_trajectory_captioning_f1 (dataset )
623- print (f"\n Final Trajectory Captioning F1 Score : { captioning_f1 :.3f} " )
600+ # Step 6: Calculate Trajectory Captioning Accuracy
601+ print ("\n 6. Calculating Trajectory Captioning Accuracy ..." )
602+ captioning_accuracy = detector .calculate_trajectory_captioning_accuracy (dataset )
603+ print (f"\n Final Trajectory Captioning Accuracy : { captioning_accuracy :.3f} " )
624604
625605 # Cleanup Ray
626606 if ray .is_initialized ():
0 commit comments