-
Notifications
You must be signed in to change notification settings - Fork 0
/
run
executable file
·91 lines (75 loc) · 2.89 KB
/
run
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
#!/bin/bash
#
# template based on: https://github.com/scitran-apps/fsl-bet/blob/master/run
#
#
CONTAINER="[deepliif-predict]"
echo -e "$(date -u) $CONTAINER Initiated"
###############################################################################
## Built to flywheel-v0 spec.
FLYWHEEL_BASE=/flywheel/v0
OUTPUT_DIR=$FLYWHEEL_BASE/output
im_DIR=$FLYWHEEL_BASE/input/image
MANIFEST=$FLYWHEEL_BASE/manifest.json
CONFIG_FILE=$FLYWHEEL_BASE/config.json
###############################################################################
## Configure the ENV
export USER=Flywheel
###############################################################################
## Execute the main processes
function jsonValue() {
KEY=$1
num=$2
awk -F"[,:}]" '{for(i=1;i<=NF;i++){if($i~/'$KEY'\042/){print $(i+1)}}}' | tr -d '"' | sed -n ${num}p
}
## get all user configurations
if [[ -f $CONFIG_FILE ]]; then # if there's a user config file, use it, otherwise use manifest defaults
echo "$(date -u) $CONTAINER $CONFIG_FILE found. Loading config..."
tile_size="$(cat $CONFIG_FILE | jsonValue tile_size)"
region_size="$(cat $CONFIG_FILE | jsonValue region_size)"
wsi="$(cat $CONFIG_FILE | jsonValue wsi)"
output_results_pickle="$(cat $CONFIG_FILE | jsonValue output_results_pickle)"
else
echo "$(date -u) $CONTAINER $CONFIG_FILE not found. Loading defaults from $MANIFEST..."
tile_size="$(cat $MANIFEST | jsonValue tile_size default)"
region_size="$(cat $MANIFEST | jsonValue region_size default)"
wsi="$(cat $MANIFEST | jsonValue wsi default)"
output_results_pickle="$(cat $MANIFEST | jsonValue output_results_pickle default)"
fi
## Find the input files
im_file=$(find $im_DIR/* -maxdepth 0 -type f)
# out_path="output/"
# out_path+=$output_fn
# out_path="$(echo -e "${out_path}" | tr -d '[:space:]')" # strip spaces
## If necessary input files are found, run the thing
if [[ -f $im_file ]] ; then
if [[ ! -d $OUTPUT_DIR ]] ; then
mkdir $OUTPUT_DIR
fi
if $wsi ; then
echo "$(date -u) $CONTAINER Running DeepLIIF inference (tile size: $tile_size; region size $region_size)"
deepliif test --input-dir $im_DIR --output-dir $OUTPUT_DIR --tile-size ${tile_size} --region-size ${region_size} --model-dir DeepLIIF_Latest_Model
# restructure output files
mv $OUTPUT_DIR/*/* $OUTPUT_DIR/
if ! $output_results_pickle ; then
rm $OUTPUT_DIR/results.pickle
fi
else
echo "$(date -u) $CONTAINER Running DeepLIIF inference (tile size: $tile_size)"
deepliif test --input-dir $im_DIR --output-dir $OUTPUT_DIR --tile-size ${tile_size} --model-dir DeepLIIF_Latest_Model
fi
################# Finish up #################
STATUS=$?
else
echo "$(date -u) $CONTAINER Input files not found!"
exit 1
fi
# Check exit status
if [[ $STATUS == 0 ]]
then
echo -e "$(date -u) $CONTAINER Done!"
else
echo "$(date -u) $CONTAINER command returned a non-zero exit code = [$STATUS]."
exit 1
fi
exit 0