-
Notifications
You must be signed in to change notification settings - Fork 2
/
eval.sh
381 lines (245 loc) · 12.5 KB
/
eval.sh
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
experiment_name='2023-11-23T11-18-37_full_1' # the trained experiment dir name
classes=cat_dog # the input image
pretrained_model_path=checkpoints/v1-5-pruned.ckpt
datapath=datasets/images/$classes
newtoken=2 # the number of new tokens
seed=1
save_path=DisenDiff/$classes
# save the changed params
python src/get_deltas.py --path $save_path/$experiment_name --newtoken $newtoken
prompts_global_path=datasets/prompts/${classes}_global.txt
prompts_subject1_path=datasets/prompts/${classes}_subject1.txt
prompts_subject2_path=datasets/prompts/${classes}_subject2.txt
global_file_name=val_global
python sample.py --delta_ckpt $save_path/$experiment_name/checkpoints/delta_epoch\=000004.ckpt --ckpt $pretrained_model_path --ddim_steps 50 --skip_grid --n_samples 4 --from-file $prompts_global_path --n_iter 4 --file_name $global_file_name
subject1_file_name=val_subject1
python sample.py --delta_ckpt $save_path/$experiment_name/checkpoints/delta_epoch\=000004.ckpt --ckpt $pretrained_model_path --ddim_steps 50 --skip_grid --n_samples 4 --from-file $prompts_subject1_path --n_iter 4 --file_name $subject1_file_name
subject2_file_name=val_subject2
python sample.py --delta_ckpt $save_path/$experiment_name/checkpoints/delta_epoch\=000004.ckpt --ckpt $pretrained_model_path --ddim_steps 50 --skip_grid --n_samples 4 --from-file $prompts_subject2_path --n_iter 4 --file_name $subject2_file_name
all_eval_file_path=$save_path/$experiment_name/global_subject1_subject2.txt
touch $all_eval_file_path
echo '#################################global###############################' >> $all_eval_file_path
#### global
evaluate_path=$save_path/$experiment_name/evaluate_$global_file_name
sample_path=$save_path/$experiment_name/$global_file_name
mkdir $evaluate_path
real_data_dir=datasets/data_eval/${classes}/global
################### text align score
file_count=0
while read line
do
################################### change the logic
# prompt=$(echo "$line" | sed 's/<new1>//g')
prompt=$(echo "$line" | sed 's/<new[0-9]\+>//g' | tr -s ' ' | sed 's/^ //;s/ $//')
filename_=${line// /_}
file_name=$(echo $filename_ | sed 's/ /_/g' | sed 's/<//g' | sed 's/>//g')
# file_name=$(echo $filename_ | sed 's/<background>//g')
mkdir $evaluate_path/$file_name
dest_dir=$evaluate_path/$file_name
file_count_max=$(echo "$file_count + 15" | bc)
# for i in {0..49}
for i in $(seq $file_count $file_count_max);
do
image_name=$(printf "%05d" "$i").png
cp "$sample_path/$image_name" "$dest_dir"
done
file_count_max_minus1=$(($file_count_max - 1))
echo "{$(for i in $(seq $file_count $file_count_max_minus1);do image_name=$(printf "%05d" "$i"); echo "\"$image_name\":\"$prompt\",";done)" > $evaluate_path/$file_name.json
image_name=$(printf "%05d" "$file_count_max"); echo "\"$image_name\":\"$prompt\"}" >> $evaluate_path/$file_name.json # last json element
python utils/clipscore/clipscore.py $evaluate_path/$file_name.json $evaluate_path/$file_name
file_count=$(($file_count + 16))
done < $prompts_global_path
# read last line
line=$(tail -n 1 $prompts_global_path)
prompt=$(echo "$line" | sed 's/<new[0-9]\+>//g' | tr -s ' ' | sed 's/^ //;s/ $//')
# prompt=$(echo "$line" | sed 's/<new1>//g')
filename_=${line// /_}
file_name=$(echo $filename_ | sed 's/ /_/g' | sed 's/<//g' | sed 's/>//g')
mkdir $evaluate_path/$file_name
dest_dir=$evaluate_path/$file_name
file_count_max=$(echo "$file_count + 15" | bc)
# # for i in {0..49}
for i in $(seq $file_count $file_count_max);
do
image_name=$(printf "%05d" "$i").png
cp "$sample_path/$image_name" "$dest_dir"
done
file_count_max_minus1=$(($file_count_max - 1))
echo "{$(for i in $(seq $file_count $file_count_max_minus1);do image_name=$(printf "%05d" "$i"); echo "\"$image_name\":\"$prompt\",";done)" > $evaluate_path/$file_name.json
image_name=$(printf "%05d" "$file_count_max"); echo "\"$image_name\":\"$prompt\"}" >> $evaluate_path/$file_name.json # last json element
python utils/clipscore/clipscore.py $evaluate_path/$file_name.json $evaluate_path/$file_name
# !/bin/bash
content=$(cat $evaluate_path/text_alignment.txt)
arr=($content)
sum=0
for num in ${arr[@]}
do
sum=$(echo "$sum + $num" | bc)
done
average=$(echo "$sum ${#arr[@]}" | awk '{print $1 / $2}')
echo $average >> $evaluate_path/text_alignment.txt
#################### image align score
python utils/clip_eval.py --real_data_dir $real_data_dir --fake_data_dir $evaluate_path --prompts_path $prompts_global_path
cat $evaluate_path/text_alignment.txt >> $all_eval_file_path
echo '#################################subject1###############################' >> $all_eval_file_path
#### subject1
evaluate_path=$save_path/$experiment_name/evaluate_$subject1_file_name
sample_path=$save_path/$experiment_name/$subject1_file_name
mkdir $evaluate_path
real_data_dir=datasets/data_eval/${classes}/subject1
################### text align score
file_count=0
while read line
do
################################### change the logic
# prompt=$(echo "$line" | sed 's/<new1>//g')
prompt=$(echo "$line" | sed 's/<new[0-9]\+>//g' | tr -s ' ' | sed 's/^ //;s/ $//')
filename_=${line// /_}
file_name=$(echo $filename_ | sed 's/ /_/g' | sed 's/<//g' | sed 's/>//g')
# file_name=$(echo $filename_ | sed 's/<background>//g')
mkdir $evaluate_path/$file_name
dest_dir=$evaluate_path/$file_name
file_count_max=$(echo "$file_count + 15" | bc)
# for i in {0..49}
for i in $(seq $file_count $file_count_max);
do
image_name=$(printf "%05d" "$i").png
cp "$sample_path/$image_name" "$dest_dir"
done
file_count_max_minus1=$(($file_count_max - 1))
echo "{$(for i in $(seq $file_count $file_count_max_minus1);do image_name=$(printf "%05d" "$i"); echo "\"$image_name\":\"$prompt\",";done)" > $evaluate_path/$file_name.json
image_name=$(printf "%05d" "$file_count_max"); echo "\"$image_name\":\"$prompt\"}" >> $evaluate_path/$file_name.json # last json element
python utils/clipscore/clipscore.py $evaluate_path/$file_name.json $evaluate_path/$file_name
file_count=$(($file_count + 16))
done < $prompts_subject1_path
# read last line
line=$(tail -n 1 $prompts_subject1_path)
prompt=$(echo "$line" | sed 's/<new[0-9]\+>//g' | tr -s ' ' | sed 's/^ //;s/ $//')
# prompt=$(echo "$line" | sed 's/<new1>//g')
filename_=${line// /_}
file_name=$(echo $filename_ | sed 's/ /_/g' | sed 's/<//g' | sed 's/>//g')
mkdir $evaluate_path/$file_name
dest_dir=$evaluate_path/$file_name
file_count_max=$(echo "$file_count + 15" | bc)
# # for i in {0..49}
for i in $(seq $file_count $file_count_max);
do
image_name=$(printf "%05d" "$i").png
cp "$sample_path/$image_name" "$dest_dir"
done
file_count_max_minus1=$(($file_count_max - 1))
echo "{$(for i in $(seq $file_count $file_count_max_minus1);do image_name=$(printf "%05d" "$i"); echo "\"$image_name\":\"$prompt\",";done)" > $evaluate_path/$file_name.json
image_name=$(printf "%05d" "$file_count_max"); echo "\"$image_name\":\"$prompt\"}" >> $evaluate_path/$file_name.json # last json element
python utils/clipscore/clipscore.py $evaluate_path/$file_name.json $evaluate_path/$file_name
# !/bin/bash
content=$(cat $evaluate_path/text_alignment.txt)
arr=($content)
sum=0
for num in ${arr[@]}
do
sum=$(echo "$sum + $num" | bc)
done
average=$(echo "$sum ${#arr[@]}" | awk '{print $1 / $2}')
echo $average >> $evaluate_path/text_alignment.txt
#################### image align score
python utils/clip_eval.py --real_data_dir $real_data_dir --fake_data_dir $evaluate_path --prompts_path $prompts_subject1_path
cat $evaluate_path/text_alignment.txt >> $all_eval_file_path
echo '#################################subject2###############################' >> $all_eval_file_path
########################### subject2
evaluate_path=$save_path/$experiment_name/evaluate_$subject2_file_name
sample_path=$save_path/$experiment_name/$subject2_file_name
mkdir $evaluate_path
real_data_dir=datasets/data_eval/${classes}/subject2
################### text align score
file_count=0
while read line
do
################################### change the logic
# prompt=$(echo "$line" | sed 's/<new1>//g')
prompt=$(echo "$line" | sed 's/<new[0-9]\+>//g' | tr -s ' ' | sed 's/^ //;s/ $//')
filename_=${line// /_}
file_name=$(echo $filename_ | sed 's/ /_/g' | sed 's/<//g' | sed 's/>//g')
# file_name=$(echo $filename_ | sed 's/<background>//g')
mkdir $evaluate_path/$file_name
dest_dir=$evaluate_path/$file_name
file_count_max=$(echo "$file_count + 15" | bc)
# for i in {0..49}
for i in $(seq $file_count $file_count_max);
do
image_name=$(printf "%05d" "$i").png
cp "$sample_path/$image_name" "$dest_dir"
done
file_count_max_minus1=$(($file_count_max - 1))
echo "{$(for i in $(seq $file_count $file_count_max_minus1);do image_name=$(printf "%05d" "$i"); echo "\"$image_name\":\"$prompt\",";done)" > $evaluate_path/$file_name.json
image_name=$(printf "%05d" "$file_count_max"); echo "\"$image_name\":\"$prompt\"}" >> $evaluate_path/$file_name.json # last json element
python utils/clipscore/clipscore.py $evaluate_path/$file_name.json $evaluate_path/$file_name
file_count=$(($file_count + 16))
done < $prompts_subject2_path
# read last line
line=$(tail -n 1 $prompts_subject2_path)
prompt=$(echo "$line" | sed 's/<new[0-9]\+>//g' | tr -s ' ' | sed 's/^ //;s/ $//')
# prompt=$(echo "$line" | sed 's/<new1>//g')
filename_=${line// /_}
file_name=$(echo $filename_ | sed 's/ /_/g' | sed 's/<//g' | sed 's/>//g')
mkdir $evaluate_path/$file_name
dest_dir=$evaluate_path/$file_name
file_count_max=$(echo "$file_count + 15" | bc)
# # for i in {0..49}
for i in $(seq $file_count $file_count_max);
do
image_name=$(printf "%05d" "$i").png
cp "$sample_path/$image_name" "$dest_dir"
done
file_count_max_minus1=$(($file_count_max - 1))
echo "{$(for i in $(seq $file_count $file_count_max_minus1);do image_name=$(printf "%05d" "$i"); echo "\"$image_name\":\"$prompt\",";done)" > $evaluate_path/$file_name.json
image_name=$(printf "%05d" "$file_count_max"); echo "\"$image_name\":\"$prompt\"}" >> $evaluate_path/$file_name.json # last json element
python utils/clipscore/clipscore.py $evaluate_path/$file_name.json $evaluate_path/$file_name
# !/bin/bash
content=$(cat $evaluate_path/text_alignment.txt)
arr=($content)
sum=0
for num in ${arr[@]}
do
sum=$(echo "$sum + $num" | bc)
done
average=$(echo "$sum ${#arr[@]}" | awk '{print $1 / $2}')
echo $average >> $evaluate_path/text_alignment.txt
#################### image align score
python utils/clip_eval.py --real_data_dir $real_data_dir --fake_data_dir $evaluate_path --prompts_path $prompts_subject2_path
cat $evaluate_path/text_alignment.txt >> $all_eval_file_path
############### global
evaluate_path=$save_path/$experiment_name/evaluate_$global_file_name
result_file_path=$evaluate_path/text_alignment.txt
file=$result_file_path
# 提取倒数第三行的数值
global_num=$(tail -n 3 "$file" | head -n 1)
# 提取倒数第二行的字符串
str=$(tail -n 2 "$file" | head -n 1)
# 提取字符串的第二个子串并转换为数值
second_substring=$(echo "$str" | cut -d ' ' -f 3)
global_num2=$(echo "$second_substring" | tr -d '[:alpha:]')
############### subject1
evaluate_path=$save_path/$experiment_name/evaluate_$subject1_file_name
result_file_path=$evaluate_path/text_alignment.txt
file=$result_file_path
# 提取倒数第三行的数值
subject1_num=$(tail -n 3 "$file" | head -n 1)
# 提取倒数第二行的字符串
str=$(tail -n 2 "$file" | head -n 1)
# 提取字符串的第二个子串并转换为数值
second_substring=$(echo "$str" | cut -d ' ' -f 3)
subject1_num2=$(echo "$second_substring" | tr -d '[:alpha:]')
############### subject2
evaluate_path=$save_path/$experiment_name/evaluate_$subject2_file_name
result_file_path=$evaluate_path/text_alignment.txt
file=$result_file_path
# 提取倒数第三行的数值
subject2_num=$(tail -n 3 "$file" | head -n 1)
# 提取倒数第二行的字符串
str=$(tail -n 2 "$file" | head -n 1)
# 提取字符串的第二个子串并转换为数值
second_substring=$(echo "$str" | cut -d ' ' -f 3)
subject2_num2=$(echo "$second_substring" | tr -d '[:alpha:]')
echo -e "Image-alignment for combined, concept1, concept2:$global_num2\t$subject1_num2\t$subject2_num2" >> "$all_eval_file_path"
echo -e "Text-alignment for combined, concept1, concept2:$global_num\t$subject1_num\t$subject2_num" >> "$all_eval_file_path"
echo -e "$global_num2\t$subject1_num2\t$subject2_num2\t$global_num\t$subject1_num\t$subject2_num" >> "$all_eval_file_path"