-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_visualization.sh
More file actions
executable file
·222 lines (192 loc) · 7.06 KB
/
Copy pathrun_visualization.sh
File metadata and controls
executable file
·222 lines (192 loc) · 7.06 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
#!/bin/bash
# DefectFill 实验结果自动化可视化脚本
# 自动检测评估结果并生成可视化图表
#
# 生成的图表:
# - heatmaps.png/pdf: KID 和 IC-LPIPS 性能矩阵热力图
# - scatter_tradeoff.png/pdf: 质量-多样性权衡散点图
# - grouped_bar_charts.png/pdf: 各配置分组柱状图
# - summary_statistics.csv: 汇总统计表
#
# 使用方法:
# ./run_visualization.sh # 自动检测实验目录
# ./run_visualization.sh test # 仅可视化测试实验
# ./run_visualization.sh full # 仅可视化完整实验
# ./run_visualization.sh /path/to/csv # 指定 CSV 文件路径
set -e
# 获取脚本所在目录(相对路径支持)
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
DEBUG_DIR="${PROJECT_DIR}/outputs/debug/evaluation"
FULL_DIR="${PROJECT_DIR}/outputs/evaluation"
# 颜色输出
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
print_header() {
echo -e "${BLUE}=========================================="
echo -e "$1"
echo -e "==========================================${NC}"
}
print_success() {
echo -e "${GREEN}✅ $1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
print_error() {
echo -e "${RED}❌ $1${NC}"
}
print_info() {
echo -e "${BLUE}ℹ️ $1${NC}"
}
# 可视化函数
run_visualization() {
local csv_path="$1"
local output_dir="$2"
local experiment_name="$3"
if [[ ! -f "${csv_path}" ]]; then
print_error "CSV file not found: ${csv_path}"
return 1
fi
# 检查 CSV 是否为空(只有表头)
local line_count=$(wc -l < "${csv_path}")
if [[ ${line_count} -le 1 ]]; then
print_warning "CSV file is empty (only header): ${csv_path}"
return 1
fi
print_header "Visualizing: ${experiment_name}"
echo "CSV file: ${csv_path}"
echo "Output directory: ${output_dir}"
echo "Start time: $(date '+%Y-%m-%d %H:%M:%S')"
echo ""
# 创建输出目录
mkdir -p "${output_dir}"
# 运行可视化脚本
python "${PROJECT_DIR}/visualize_results.py" \
--csv_path "${csv_path}" \
--output_dir "${output_dir}"
local status=$?
if [[ ${status} -eq 0 ]]; then
print_success "Visualization completed for ${experiment_name}"
echo ""
echo "Generated files:"
ls -la "${output_dir}"/*.png "${output_dir}"/*.pdf "${output_dir}"/*.csv 2>/dev/null || true
else
print_error "Visualization failed for ${experiment_name}"
return 1
fi
echo ""
return 0
}
# 主程序
main() {
print_header "DefectFill Experiment Results Visualization"
echo "Start time: $(date '+%Y-%m-%d %H:%M:%S')"
echo ""
local mode="${1:-auto}"
local visualized_count=0
case "${mode}" in
test)
# 仅可视化测试实验
print_info "Mode: Test experiments only"
if [[ -f "${DEBUG_DIR}/evaluation_results.csv" ]]; then
run_visualization \
"${DEBUG_DIR}/evaluation_results.csv" \
"${DEBUG_DIR}/figures" \
"Test Experiments"
((visualized_count++)) || true
else
print_warning "Test experiment results not found"
fi
;;
full)
# 仅可视化完整实验
print_info "Mode: Full experiments only"
if [[ -f "${FULL_DIR}/evaluation_results.csv" ]]; then
run_visualization \
"${FULL_DIR}/evaluation_results.csv" \
"${FULL_DIR}/figures" \
"Full Experiments"
((visualized_count++)) || true
else
print_warning "Full experiment results not found"
fi
;;
auto)
# 自动检测并可视化所有可用的实验结果
print_info "Mode: Auto-detect all experiments"
echo ""
# 检查测试实验
if [[ -f "${DEBUG_DIR}/evaluation_results.csv" ]]; then
run_visualization \
"${DEBUG_DIR}/evaluation_results.csv" \
"${DEBUG_DIR}/figures" \
"Test Experiments"
((visualized_count++)) || true
else
print_warning "Test experiment results not found: ${DEBUG_DIR}/evaluation_results.csv"
fi
echo ""
# 检查完整实验
if [[ -f "${FULL_DIR}/evaluation_results.csv" ]]; then
run_visualization \
"${FULL_DIR}/evaluation_results.csv" \
"${FULL_DIR}/figures" \
"Full Experiments"
((visualized_count++)) || true
else
print_warning "Full experiment results not found: ${FULL_DIR}/evaluation_results.csv"
fi
;;
*)
# 指定 CSV 文件路径
if [[ -f "${mode}" ]]; then
print_info "Mode: Custom CSV file"
local csv_dir=$(dirname "${mode}")
local figures_dir="${csv_dir}/figures"
run_visualization \
"${mode}" \
"${figures_dir}" \
"Custom Experiment"
((visualized_count++)) || true
else
print_error "Invalid argument or file not found: ${mode}"
echo ""
echo "Usage:"
echo " $0 # Auto-detect experiment directories"
echo " $0 test # Visualize test experiments only"
echo " $0 full # Visualize full experiments only"
echo " $0 /path/to/csv # Specify custom CSV file path"
exit 1
fi
;;
esac
echo ""
print_header "Visualization Summary"
echo "End time: $(date '+%Y-%m-%d %H:%M:%S')"
echo ""
if [[ ${visualized_count} -gt 0 ]]; then
print_success "Successfully visualized ${visualized_count} experiment(s)"
echo ""
echo "Result interpretation:"
echo " - KID: Lower is better (closer distribution to real defect images)"
echo " - IC-LPIPS: Higher is better (more diverse generated images)"
echo ""
echo "Expected findings based on experiment design:"
echo " - Config TEX should perform better on Texture classes"
echo " - Config OBJ should perform better on Object classes"
else
print_warning "No experiments were visualized"
echo ""
echo "Please run the following scripts first:"
echo " 1. scripts/run_train_test.sh # Train models"
echo " 2. scripts/run_inference_test.sh # Generate images"
echo " 3. scripts/run_evaluation_test.sh # Evaluate results"
echo " 4. scripts/run_visualization.sh # Visualize (this script)"
fi
}
# 执行主程序
main "$@"