forked from Evolving-AI-Lab/synthesizing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
5_activate_output_GoogLeNet.sh
executable file
·104 lines (85 loc) · 2.63 KB
/
5_activate_output_GoogLeNet.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
#/bin/bash
# Take in an unit number
#if [ "$#" -ne "1" ]; then
# echo "Provide 1 output unit number e.g. 945 for bell pepper."
# exit 1
#fi
# Get label for each unit
path_labels="misc/synset_words.txt"
IFS=$'\n' read -d '' -r -a labels < ${path_labels}
opt_layer=fc6
act_layer="loss3/classifier"
units="643 624 304 629 437" #"${1}"
xy=0
# Net
net_weights="nets/googlenet/bvlc_googlenet.caffemodel"
net_definition="nets/googlenet/bvlc_googlenet_updated.prototxt"
# Hyperparam settings for visualizing GoogLeNet
# Note that the learnign rate is different from that for AlexNet
iters="200"
weights="99"
rates="2.0"
end_lr=1e-10
# Clipping
clip=0
multiplier=3
bound_file=act_range/${multiplier}x/${opt_layer}.txt
init_file="None"
# Debug
debug=0
if [ "${debug}" -eq "1" ]; then
rm -rf debug
mkdir debug
fi
# Output dir
output_dir="output"
#rm -rf ${output_dir}
mkdir -p ${output_dir}/${act_layer}
list_files=""
# Sweeping across hyperparams
for unit in ${units}; do
# Get label for each unit
label_1=`echo ${labels[unit]} | cut -d "," -f 1 | cut -d " " -f 2`
label_2=`echo ${labels[unit]} | cut -d "," -f 1 | cut -d " " -f 3`
label="${label_1} ${label_2}"
for seed in {0..0}; do
#for seed in {0..8}; do
for n_iters in ${iters}; do
for w in ${weights}; do
for lr in ${rates}; do
L2="0.${w}"
# Optimize images maximizing fc8 unit
python ./act_max.py \
--act_layer ${act_layer} \
--opt_layer ${opt_layer} \
--unit ${unit} \
--xy ${xy} \
--n_iters ${n_iters} \
--start_lr ${lr} \
--end_lr ${end_lr} \
--L2 ${L2} \
--seed ${seed} \
--clip ${clip} \
--bound ${bound_file} \
--debug ${debug} \
--output_dir ${output_dir} \
--init_file ${init_file} \
--net_weights ${net_weights} \
--net_definition ${net_definition}
# Add a category label to each image
unit_pad=`printf "%04d" ${unit}`
f=${output_dir}/${act_layer}_${unit_pad}_${n_iters}_${L2}_${lr}__${seed}.jpg
convert $f -gravity south -splice 0x10 $f
convert $f -append -gravity Center -pointsize 30 label:"$label" -bordercolor white -border 0x0 -append $f
list_files="${list_files} ${f}"
done
done
done
done
done
# Make a collage
output_file=${output_dir}/example5.jpg
montage ${list_files} -tile 5x1 -geometry +1+1 ${output_file}
convert ${output_file} -trim ${output_file}
echo "=============================="
echo "Result of example 5: [ ${output_file} ]"