File size: 2,462 Bytes
7c34b66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import os
import sys
import json
import pandas as pd
import cv2

sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from predict import run_prediction

def debug_flowers():
    test_cases = [
        "manual_test/failure_cases/real/real 1.jpeg",
        "manual_test/failure_cases/real/real 2.jpeg",
        "manual_test/failure_cases/screen/fake 1.jpeg",
        "manual_test/failure_cases/screen/fake 2.jpeg"
    ]
    
    results = []
    
    for case in test_cases:
        path = os.path.join(os.path.dirname(__file__), '..', case)
        if not os.path.exists(path):
            print(f"Skipping {path} - not found.")
            continue
            
        img = cv2.imread(path)
        if img is None:
            continue
            
        res = run_prediction(img, no_rules=False)
        
        row = {
            'image': os.path.basename(case),
            'true_label': 'real' if 'real' in case else 'screen',
            'raw_score': res['raw_model_score'],
            'rule_boost': res['rule_boost_total'],
            'final_score': res['final_score'],
            'predicted_label': res['predicted_label'],
            'boosts': json.dumps(res.get('individual_rule_boosts', {})),
        }
        
        for k, v in res.get('features', {}).items():
            row[k] = v
            
        results.append(row)
        
    if not results:
        print("No test cases found.")
        return
        
    df = pd.DataFrame(results)
    
    os.makedirs(os.path.join(os.path.dirname(__file__), '..', 'reports'), exist_ok=True)
    df.to_csv(os.path.join(os.path.dirname(__file__), '..', 'reports', 'flower_failure_debug.csv'), index=False)
    
    with open(os.path.join(os.path.dirname(__file__), '..', 'reports', 'flower_failure_summary.md'), 'w') as f:
        f.write("# Flower Failure Debug Summary\n\n")
        
        summary_cols = ['image', 'true_label', 'raw_score', 'rule_boost', 'final_score', 'boosts']
        f.write("## Prediction Summary\n")
        f.write(df[summary_cols].to_markdown(index=False))
        f.write("\n\n")
        
        f.write("## Feature Values\n")
        feature_cols = [c for c in df.columns if c not in summary_cols and c != 'predicted_label']
        # Transpose for easier reading
        feature_df = df[['image'] + feature_cols].set_index('image').T
        f.write(feature_df.to_markdown())
        f.write("\n")

if __name__ == "__main__":
    debug_flowers()