-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_classification
150 lines (128 loc) · 4.32 KB
/
run_classification
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
#!/bin/bash
# Version 0.1
# license http://creativecommons.org/licenses/by-nc-sa/4.0/
home="$(cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"/
miniconda=~/miniconda3/etc/profile.d/conda.sh
keras="keras"
keras_version_expected="2.4.3"
# Check the miniconda3 installation
if [[ -f $miniconda ]]; then
echo "$miniconda exists."
source $miniconda
else
echo -e "[error]\tCould not find miniconda installation."
exit 1
fi
# Check the Leaf-disc-install folder
if [[ -d "$home" ]]; then
echo -e "[info]\tRunning from $home."
else
echo -e "CNN home not found. Make sure to adjust line 4 in the run_classification script."
exit 1
fi
plot_coords=$home"plot_coords.R"
plot_pheno=$home"plot_pheno.R"
classify_leaf_disc=$home"classify_leaf_disc.py"
helpFunction()
{
echo ""
echo "Usage: $( basename -- "$0" ) -f path/to/leaf/disc/dir/ -e Inoculation1 -l model_l_vs_b.h5 -s model_s_vs_no-s.h5 -e keras"
echo -e "\t-f Path to leaf disc containing folder. Don't forget the / at the end"
echo -e "\t-e Give your experiment a name"
echo -e "\t-l Path to custom Keras model: leaf vs background (if not supplied standard model will be used)"
echo -e "\t-s Path to custom Keras model: sporangia vs no-sporangia (if notsupplied standard model will be used)"
echo -e "\t-k name of the conda environment with Leaf-disc-scoring dependencies installed (default: keras)"
echo -e ""
exit 1
}
while getopts "e:f:l:s:k:" opt
do
case "$opt" in
e ) parameterE="$OPTARG" ;;
f ) parameterF="$OPTARG" ;;
l ) parameterL="$OPTARG" ;;
s ) parameterS="$OPTARG" ;;
k ) parameterK="$OPTARG" ;;
? ) helpFunction ;;
esac
done
if [ -z "$parameterK" ]
then
echo -e "[warning] No conda environment name given. Defaulting to: keras"
parameterK="keras"
fi
conda activate $parameterK
# Get the version number of the installed Keras
keras_version=$(python -c 'import keras; print(keras.__version__)' 2> /dev/null)
# Check if it is installed
if [ -z $keras_version ]
then
echo $keras_version
echo -e "\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo -e "\t!!No Keras installation found in conda environment !!"
echo -e "\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
exit 1
else
# Check if the right version is installed
if [ "$keras_version" != "$keras_version_expected" ]
then
echo -e "[error]\tWrong Keras version found. Make sure to install Keras v2.4.3"
exit 1
else
echo -e "[info]\tRunning Keras in version: "$keras_version
fi
fi
# Check if the specified folder with leaf disc images exists
if [[ -d "$parameterF" ]]; then
echo -e "[info]\tLeaf disc folder exists."
else
helpFunction
fi
# Check if there was a name given for the experiment
if [ -z "$parameterE" ]
then
echo -e "[info]\tNo experiment name supplied. Using: Inoculation1"
parameterE=Inoculation1
else
echo -e "[info]\tExperiment name : "$parameterE
fi
# Check if an alternative CNN1 model was supplied
if [ -z "$parameterL" ]
then
echo -e "[info]\tNo -l option. Using standard model: CNN1_model.h5";
parameterL=$home"CNN1_model.h5"
fi
#Check if an alternative CNN2 model was supplied
if [ -z "$parameterS" ]
then
echo -e "[info]\tNo -S option. Using standard model: CNN2_model.h5";
parameterS=$home"CNN2_model.h5"
fi
# Create directories and output files
mkdir $parameterF"results"
mkdir $parameterF"spo"
touch $parameterF"classify_results.txt"
touch $parameterF"error.log"
# Start the python script for clasification
echo -e "[info]\tRunning classify_leaf_disc.py. This might take some time."
python $classify_leaf_disc $parameterF $parameterL $parameterS $parameterE 2> $parameterF"error.log"
# Plotting the data on the RGB images
echo -e "[info]\tRunning plot_coords.R"
coords=$parameterF*.jpg
for f in $coords
do
echo -e "[info]\t\tPlotting "$(basename -- $f )
Rscript $plot_coords -c $f"spo_coord.txt" 2>> $parameterF"error.log"
done
# Plotting the results overview
Rscript $plot_pheno -r $parameterF"classify_results.txt" 2>> $parameterF"error.log"
# Moving everything to a folder
mkdir $parameterF$parameterE
mv $parameterF"results" $parameterF$parameterE
mv $parameterF"spo" $parameterF$parameterE
mv $parameterF"classify_results.txt" $parameterF$parameterE
mv $parameterF"error.log" $parameterF$parameterE
for f in $parameterF*_coord.txt
do
mv $f $parameterF$parameterE
done