-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscriptRobustness-Hurt-me-plenty.sh
executable file
·51 lines (43 loc) · 1.35 KB
/
scriptRobustness-Hurt-me-plenty.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
#!/bin/zsh
zmodload -i zsh/mathfunc
##YOUR SIMILARITY PROG NAME
SIMILARYPROG=python3
#nb of source images to test
NBIMGTESTS=10
#nb of noisyfied copies
NBTESTS=20
MAXNOISE=0.3
sum=0.0
variance=0.0
cpt=0.0
for ((i=0; i < $NBIMGTESTS; i++)); do
##Pick a random class
CLASSID=`expr $RANDOM % 61 + 1`
CLASSNAME=`head -$CLASSID classes.csv | tail -1 | sed -e 's/,//'`
echo "Classname: "$CLASSNAME
##Pick a random image in this class
IMGID=`expr $RANDOM % 10 + 1`
IMGNAME=database/$CLASSNAME-$IMGID.pgm
echo $IMGNAME
if [[ -e $IMGNAME ]]; then
for ((j=0; j < $NBTESTS; j+=1)); do
##Random scale+rotation
ANGLE=$((rand48()*3.1415))
SCALE=$((rand48()*3))
NOISE=$((rand48()*MAXNOISE))
./bin/imgRotate -i $IMGNAME -o tmp.pgm -a $ANGLE 2>/dev/null
./bin/imgScale -i tmp.pgm -o tmp2.pgm -s $SCALE 2>/dev/null
./bin/imgAddNoise -i tmp2.pgm -o tmp.pgm -n $NOISE 2>/dev/null
DIST=`$SIMILARYPROG distance.py $IMGNAME tmp.pgm`
sum=$(( $sum + $DIST))
variance=$(( $variance + $DIST*$DIST ))
echo "Similarity= "$DIST
cpt=$(($cpt + 1.0))
done
fi
done
echo
echo "Average similarity= " $(( $sum / $cpt ))
echo "Variance= " $(( $variance / $cpt - ($sum / $cpt)*($sum / $cpt) ))
rm tmp.pgm
rm tmp2.pgm