-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_visual_report.py
More file actions
292 lines (272 loc) · 10.1 KB
/
create_visual_report.py
File metadata and controls
292 lines (272 loc) · 10.1 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
import pandas as pd
import base64
from pathlib import Path
import random
def create_html_report(num_samples=50):
"""Create interactive HTML report with images and captions"""
print("Creating visual evaluation report...")
# Load results
df = pd.read_csv('test_results_detailed.csv')
# Sort by BLEU score
df_sorted = df.sort_values('bleu4', ascending=False)
# Get samples: best, worst, and random
best_samples = df_sorted.head(15)
worst_samples = df_sorted.tail(15)
random_samples = df.sample(n=min(20, len(df)))
# Combine
samples = pd.concat([best_samples, worst_samples, random_samples]).drop_duplicates()
samples = samples.head(num_samples)
# Create HTML
html = """
<!DOCTYPE html>
<html>
<head>
<title>Image Caption Evaluation - Visual Report</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
max-width: 1400px;
margin: 0 auto;
padding: 20px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.header {
background: white;
padding: 30px;
border-radius: 15px;
margin-bottom: 30px;
box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}
h1 {
color: #667eea;
text-align: center;
margin: 0;
}
.stats {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 15px;
margin-top: 20px;
}
.stat-box {
background: #f8f9fa;
padding: 15px;
border-radius: 10px;
text-align: center;
}
.stat-value {
font-size: 2em;
font-weight: bold;
color: #667eea;
}
.stat-label {
color: #666;
font-size: 0.9em;
margin-top: 5px;
}
.image-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(450px, 1fr));
gap: 20px;
margin-top: 20px;
}
.image-card {
background: white;
border-radius: 15px;
overflow: hidden;
box-shadow: 0 5px 15px rgba(0,0,0,0.2);
transition: transform 0.3s;
}
.image-card:hover {
transform: translateY(-5px);
box-shadow: 0 10px 25px rgba(0,0,0,0.3);
}
.image-container {
width: 100%;
height: 300px;
overflow: hidden;
background: #f0f0f0;
display: flex;
align-items: center;
justify-content: center;
}
.image-container img {
max-width: 100%;
max-height: 100%;
object-fit: contain;
}
.caption-container {
padding: 20px;
}
.score-badge {
display: inline-block;
padding: 5px 15px;
border-radius: 20px;
font-weight: bold;
margin-bottom: 10px;
}
.score-excellent { background: #10b981; color: white; }
.score-good { background: #3b82f6; color: white; }
.score-fair { background: #f59e0b; color: white; }
.score-poor { background: #ef4444; color: white; }
.prediction {
background: #e0e7ff;
padding: 12px;
border-radius: 8px;
margin: 10px 0;
border-left: 4px solid #667eea;
}
.reference {
background: #dcfce7;
padding: 12px;
border-radius: 8px;
margin: 10px 0;
border-left: 4px solid #10b981;
}
.label {
font-weight: bold;
font-size: 0.85em;
color: #666;
margin-bottom: 5px;
}
.filter-buttons {
text-align: center;
margin: 20px 0;
}
.filter-btn {
padding: 10px 20px;
margin: 0 5px;
border: none;
border-radius: 8px;
background: white;
cursor: pointer;
font-weight: bold;
transition: all 0.3s;
}
.filter-btn:hover {
transform: scale(1.05);
}
.filter-btn.active {
background: #667eea;
color: white;
}
</style>
</head>
<body>
<div class="header">
<h1>🖼️ Image Caption Generator - Test Set Evaluation</h1>
<p style="text-align: center; color: #666; margin-top: 10px;">
Visual comparison of predicted vs reference captions on unseen test data
</p>
<div class="stats">
<div class="stat-box">
<div class="stat-value">""" + str(len(df)) + """</div>
<div class="stat-label">Test Images</div>
</div>
<div class="stat-box">
<div class="stat-value">""" + f"{df['bleu4'].mean():.3f}" + """</div>
<div class="stat-label">Mean BLEU-4</div>
</div>
<div class="stat-box">
<div class="stat-value">""" + f"{(df['bleu4'] >= 0.3).sum()}" + """</div>
<div class="stat-label">Excellent (≥0.3)</div>
</div>
<div class="stat-box">
<div class="stat-value">""" + f"{((df['bleu4'] >= 0.2) & (df['bleu4'] < 0.3)).sum()}" + """</div>
<div class="stat-label">Good (0.2-0.3)</div>
</div>
</div>
</div>
<div class="filter-buttons">
<button class="filter-btn active" onclick="filterImages('all')">Show All</button>
<button class="filter-btn" onclick="filterImages('excellent')">Excellent</button>
<button class="filter-btn" onclick="filterImages('good')">Good</button>
<button class="filter-btn" onclick="filterImages('poor')">Poor</button>
</div>
<div class="image-grid" id="imageGrid">
"""
# Add image cards
for idx, row in samples.iterrows():
img_path = f"data/Images/{row['image']}"
# Encode image to base64
try:
with open(img_path, 'rb') as img_file:
img_data = base64.b64encode(img_file.read()).decode()
img_src = f"data:image/jpeg;base64,{img_data}"
except:
img_src = ""
# Determine score class
score = row['bleu4']
if score >= 0.3:
score_class = "score-excellent"
score_label = "Excellent"
elif score >= 0.2:
score_class = "score-good"
score_label = "Good"
elif score >= 0.1:
score_class = "score-fair"
score_label = "Fair"
else:
score_class = "score-poor"
score_label = "Poor"
html += f"""
<div class="image-card" data-category="{score_class}">
<div class="image-container">
<img src="{img_src}" alt="{row['image']}">
</div>
<div class="caption-container">
<span class="score-badge {score_class}">
{score_label} - BLEU: {score:.3f}
</span>
<div class="prediction">
<div class="label">🤖 MODEL PREDICTION:</div>
{row['prediction']}
</div>
<div class="reference">
<div class="label">✅ GROUND TRUTH:</div>
{row['reference_1']}
</div>
<div style="font-size: 0.8em; color: #999; margin-top: 10px;">
{row['image']}
</div>
</div>
</div>
"""
html += """
</div>
<script>
function filterImages(category) {
const cards = document.querySelectorAll('.image-card');
const buttons = document.querySelectorAll('.filter-btn');
// Update button states
buttons.forEach(btn => btn.classList.remove('active'));
event.target.classList.add('active');
// Filter cards
cards.forEach(card => {
if (category === 'all') {
card.style.display = 'block';
} else if (category === 'excellent') {
card.style.display = card.dataset.category === 'score-excellent' ? 'block' : 'none';
} else if (category === 'good') {
card.style.display = card.dataset.category === 'score-good' ? 'block' : 'none';
} else if (category === 'poor') {
card.style.display = card.dataset.category === 'score-poor' ? 'block' : 'none';
}
});
}
</script>
</body>
</html>
"""
# Save HTML
with open('test_evaluation_report.html', 'w', encoding='utf-8') as f:
f.write(html)
print(f"\n✓ Visual report created: test_evaluation_report.html")
print(f"✓ Showing {len(samples)} sample images")
print("\nOpen the HTML file in your browser to see:")
print(" - Images with predicted vs ground truth captions")
print(" - Color-coded by performance (excellent/good/fair/poor)")
print(" - Interactive filtering")
print("\nTo view: firefox test_evaluation_report.html")
if __name__ == "__main__":
create_html_report(num_samples=50)