/fetal_seg_docker

Primary LanguagePythonGNU General Public License v3.0GPL-3.0

Docker submission for Feta 2022 competition: fetal_seg_docker

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.

  1. Download this github respositry.

  2. 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

  3. Open terminal and cd fetal_seg_docker directory. Type

docker build . -t feta_challenge/ajoshiusc

This will build a docker image

  1. Save docker image to tar.gz file
docker save feta_challenge/ajoshiusc:latest|gzip>feta_challenge_ajoshiusc_ver1.tar.gz

Download and Run the Docker Image

  1. Download the Docker image from Google Drive Link

  2. Load the docker image docker

docker load <feta_challenge_ajoshiusc_ver1.tar.gz
  1. 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.

  1. 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.

  1. 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).

  1. 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>.

  1. Clean up:
docker stop <container name>
docker rm -v <container name>