-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun_inference_spine-generic.sh
95 lines (79 loc) · 3.18 KB
/
run_inference_spine-generic.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
#!/bin/bash
#
# Segment SC and lesions using our nnUNet SCIsegV2 model (part of SCT v6.4) on spine-generic multi-subject T2w iso images
# and generate QC report
#
# Usage:
# sct_run_batch -config config.json
#
# Example of config.json:
# {
# "path_data" : "data-multi-subject",
# "path_output" : "data-multi-subject_2024-08-25",
# "script" : "<PATH_TO_REPO>/model_seg_sci/baselines/run_inference_spine-generic.sh",
# "jobs" : 8
# }
#
#
# Author: Jan Valosek
#
# Uncomment for full verbose
set -x
# Immediately exit if error
set -e -o pipefail
# Exit if user presses CTRL+C (Linux) or CMD+C (OSX)
trap "echo Caught Keyboard Interrupt within script. Exiting now.; exit" INT
# Print retrieved variables from the sct_run_batch script to the log (to allow easier debug)
echo "Retrieved variables from from the caller sct_run_batch:"
echo "PATH_DATA: ${PATH_DATA}"
echo "PATH_DATA_PROCESSED: ${PATH_DATA_PROCESSED}"
echo "PATH_RESULTS: ${PATH_RESULTS}"
echo "PATH_LOG: ${PATH_LOG}"
echo "PATH_QC: ${PATH_QC}"
SUBJECT=$1
echo "SUBJECT: ${SUBJECT}"
# ------------------------------------------------------------------------------
# SCRIPT STARTS HERE
# ------------------------------------------------------------------------------
# get starting time:
start=`date +%s`
# Display useful info for the log, such as SCT version, RAM and CPU cores available
sct_check_dependencies -short
# Go to folder where data will be copied and processed
cd $PATH_DATA_PROCESSED
# Copy source T2w images
# Note: we use '/./' in order to include the sub-folder 'ses-0X'
# We do a substitution '/' --> '_' in case there is a subfolder 'ses-0X/'
# copy only T2w to save space
rsync -Ravzh ${PATH_DATA}/./${SUBJECT}/anat/${SUBJECT//[\/]/_}_*T2w.* .
# Go to subject folder for source images
cd ${SUBJECT}/anat
# ------------------------------------------------------------------------------
# T2w
# ------------------------------------------------------------------------------
# We do a substitution '/' --> '_' in case there is a subfolder 'ses-0X/'
file_t2="${SUBJECT//[\/]/_}"_T2w
# Check if file_t2 exists
if [[ ! -e ${file_t2}.nii.gz ]]; then
echo "File ${file_t2}.nii.gz does not exist" >> ${PATH_LOG}/missing_files.log
echo "ERROR: File ${file_t2}.nii.gz does not exist. Exiting."
exit 1
else
# Segment SC and lesion using SCIsegV2 (part of SCT v6.4)
# Note: a single axial QC report contains both SC and lesion segmentations
# Note: we use CUDA_VISIBLE_DEVICES=0 SCT_USE_GPU=1 to run the inference on GPU 0; details:
# https://github.com/spinalcordtoolbox/spinalcordtoolbox/pull/4421#issuecomment-2263344151
CUDA_VISIBLE_DEVICES=0 SCT_USE_GPU=1 sct_deepseg -i ${file_t2}.nii.gz -task seg_sc_lesion_t2w_sci -qc ${PATH_QC} -qc-subject ${SUBJECT}
fi
# ------------------------------------------------------------------------------
# End
# ------------------------------------------------------------------------------
# Display results (to easily compare integrity across SCT versions)
end=`date +%s`
runtime=$((end-start))
echo
echo "~~~"
echo "SCT version: `sct_version`"
echo "Ran on: `uname -nsr`"
echo "Duration: $(($runtime / 3600))hrs $((($runtime / 60) % 60))min $(($runtime % 60))sec"
echo "~~~"