How to run the code ?¶
This note explains in a nutshell how to install the requirements for this project, and then how to use the code to run simulations.
Running your own experiments¶
STEP 0: Import the files containing the fingerprints
We need first to import the files containing the data and to save them in the folder MRF/Offline/loading_data/chosen_name where chosen_name is the name chosen to describe this particular dataset. You should save several files containing the data (typically, I saved around 400 different files each one containing 4096 fingerprints). We need to save different types of files:
Files named
fingerprints1.npy
,fingerprints2.npy
, etc. Each one of this file should contain a numpy array of size(number of fingerprints chosen) x (length of a fingerprint)
. Each fingerprint should be computed solving the Bloch equation for a proton density equals to 1.Files named
params1.npy
,params2.npy
, etc. Each one of this file should contain a numpy array of size(number of fingerprints chosen) x (5)
. Each line should contain the parameters \(m_{0}^s\), \(T_1^f\), \(T_2^f\), \(R\) and \(T_{2}^s\) in this order.If your loss function required the definition of the Cramer Rao Bound, you should also save files
CRBs1.npy
,CRBs2.npy
, etc. Each one of this file should contain a numpy array of size(number of fingerprints chosen) x (6)
. Each line should contain the CRBS for the parameters \(m_{0}^s\), \(T_1^f\), \(T_2^f\), \(R\), \(T_{2}^s\) and \(M_0\) in this order and considering a proton density equals to 1.
Remark: You could be disturbed by the fact that the CRBs and the fingerprints are saved with proton densities equal to 1. This is normal since at each epoch, new proton densities are sampled to change the scale of the loaded fingerprints. The CRBs loaded are also modified to take into account the proton densities sampled.
STEP 1: Compute a reduced basis for the manifold of the Bloch equation using an online PCA algorithm (optional: basis already computed for you)
If you use a fixed first linear layer supposed to perform the projection of the input onto a lower dimensional subspace, you should take a look at the script
online_PCA.py
located in the folderonline_PCA.py
. This script will compute a reduced basis supposed to approximate the whole manifold of the solutions of the Bloch equation. Note that you need to specify in the code the script allowing to generate the fingerprints from a given set of parameters. The specific line that needs to be modified is explicitly given in the functiongenerate_random_signal
. The most updated version of the code we used to generate fingerprints is located here. Please note that in the folderpaper_data
, we provide with the filebasis_for_compress.mat
the basis functions we used for our paper.STEP 2: Define the desired settings for the training
Open the notebook offline_training_settings.ipynb to save easily a pickle file containing all the settings you want. In particular you will be asked to specify a name for this settings file. You will use this name to launch your job in the next step.
STEP 3: Launch your job
On your laptop
python main_offline.py --save_name **chosen_name**
On a remote cluster
Here I give an example of the command line I used to launch my jobs on a remote cluster. I used one GPU to perform the training.
srun -t160:00:00 --gres=gpu:1 --mem=100GB --jobname=**chosen_name** python main_offline.py --save_name **chosen_name**