This repository has code for creating a docker container for fetal brain segmentation as part of feta 2022 challenge. This is only the code for running trained model on a test data. The entire code is available at brainseg inside feta_2022
subdirectory.
Here are the steps for building docker image from the data.
-
Download this github respositry.
-
Download the trained weights epoch66.pth and place it in subdirectory trained_model. The path of the file on your computer should be
fetal_seg_docker/trained_model/epoch66.pth
-
Open terminal and cd fetal_seg_docker directory. Type
docker build . -t feta_challenge/ajoshiusc
This will build a docker image
- Save docker image to tar.gz file
docker save feta_challenge/ajoshiusc:latest|gzip>feta_challenge_ajoshiusc_ver1.tar.gz
-
Download the Docker image from Google Drive Link
-
Load the docker image docker
docker load <feta_challenge_ajoshiusc_ver1.tar.gz
- Run the docker image to make it into container:
docker run -dit -v <input_dir>/:/input_img/:ro -v <meta_dir>/:/input_meta/:ro -v /output feta_challenge/ajoshiusc
e.g.
docker run -dit -v /deneb_disk/feta_2022/test/sub-026/:/input_img/:ro -v /deneb_disk/feta_2022/test/:/input_meta/:ro -v /output feta_challenge/ajoshiusc
Check the name of the running container using docker ps
.
- The docker assumes that the fetal image that you want to segment is with the path
<input_dir>/anat/<subname>_T2w.nii.gz
. For reference, the corresponding lines of code are as follows:
T2wImagePath = glob.glob(os.path.join(input_img_dir, 'anat', '*_T2w.nii.gz'))[0]
sub = os.path.split(T2wImagePath)[1].split('_')[0] # to split the input directory and to obtain the suject name
This might tell you how the directory structure should be for the input data.
- Run the segmentation code
docker exec <container name> python feta_seg/fetal_seg_nii.py
You will see a slidebar showing the slices of 3d image being processed. It should take about a min or two. Message will show that the segmentation is done and output is saved (within the container).
- Copy the output from the container to an output directory using the command
docker cp <container_name>:/output <local_output_dir>
Now you can inspect the files in the output directory <local_output_dir>
.
- Clean up:
docker stop <container name>
docker rm -v <container name>