Following the requirements provided by Beetz et al. for Mesh VAE: https://github.com/marcel-beetz/cardiac-mesh-vae
- Install the mesh processing libraries described in the following Github repository: https://github.com/MPI-IS/mesh
- Create a new virtual environment and install required packages:
- virtualenv mesh_vae_venv
- source mesh_vae_venv/bin/activate
- pip install -r mesh_vae_requirements.txt
You can train the model on end-diastolic (ED) data or end-systolic (ES) data.
-
Adjust the following parameters in main.cfg depending on the data (ED or ES) you want to use:
- data_dir - where dataset is located
- checkpoint_dir - where checkpoints will be saved
- template_fname - a blueprint mesh used for processing meshes (it is already provided and it was created with the following code: data_processing/template_mesh.py)
- checkpoint_file - pretrained model
-
Training Mesh VAE (the autoencoder part of the Mesh LDM):
- In main.cfg change parameter: eval=False
- python meshLDM/main.py --conf main.cfg
-
Evaluate Mesh VAE (the autoencoder part of the Mesh LDM):
- In main.cfg change parameter: eval=True
- python meshLDM/main.py --conf main.cfg
-
Encode meshes into latent space using the encoder from VAE:
-
Adjust paths in encode_decode.cfg:
- data_dir - path where dataset is located
- checkpoint_dir - path where checkpoints will be saved
- template_fname - a blueprint mesh used for processing meshes (it is already provided and it was created with the following code: data_processing/template_mesh.py)
- mesh_to_fill_path - a random mesh used for getting the mesh structure (already provided)
- checkpoint_file - pretrained model
- encoded_output_dir - where the encoded data will be saved
- denoised_dir - where denoised data will be read from in the decoding phase
- decoded_output_dir - where the decoded data (3D meshes) will be saved
-
python meshLDM/encode.py --conf encode_decode.cfg
-
-
Train a denoising model: Code: diffusion.ipynb. It was run in a code editor using a separate virtual environment (Why? Some versions of libraries used for Mesh VAE aren't compatible with the diffusers library)
-
Virtual environment for diffusion.ipynb:
- virtualenv diffusion_venv
- source diffusion_venv/bin/activate
- pip install -r diffusion_requirements.txt
- deactivate
- Change kernel to diffusion_venv for diffusion.ipynb (In VSCode the option is located in the upper right corner.)
-
Adjust parameters in diffusion.ipynb:
- cardiac_phase - "ED" for end-distolic, "ES" for end-systolic
- encoded_output_dir - same path as in encode_decode.cfg
- denoised_output_dir - same path as in encode_decode.cfg
-
Run all cells
-
-
Decode data from the latent space into mesh shapes using a decoder from Mesh VAE:
- source mesh_vae_venv/bin/activate
- python meshLDM/decode.py --conf encode_decode.cfg
-
The generated meshes are located in the "decoded_output_dir" folder (e.g. data/decoded/)
Code in folder: clinical_metrics
-
Convert .ply -> .vtk -> .vtk polydata:
- Adjust parameter in convert_ply_to_vtk.py:
- ply_dir - path to the decoded meshes
- python convert_ply_to_vtk.py
- matlab -nosplash -nodesktop -r "run('convert_unstructured_to_polydata.m');"
- Adjust parameter in convert_ply_to_vtk.py:
-
Calculate left ventricule (LV) volume & mass:
- Adjust parameter in calculate_volume_mass.m
- MeshSampleFile - choose reference mesh depending on ED or ES data
- matlab -nosplash -nodesktop -r "run('calculate_volume_mass.m');"
- Adjust parameter in calculate_volume_mass.m
After VAE training and data encoding: Get mean and std of the latent space distribution: meshLDM/mean_std_training_data.py
Parts of this code are based on software from other repositories. Please see the Acknowledgements file for more details.