-
Create an environment with Anaconda:
conda create -n team6 python=3.10
-
Install all the necessary packages by running the following command in the parent directory:
pip install -r requirements.txt
-
Install the final package:
conda install mpi4py
-
Install
mnist1d:pip install mnist1d
-
See the “#Settings” part for hyperparameter configurations. We primarily experimented with varying depth, but other parameters are also adjustable.
-
Change directory to
mnist1d:cd ../mnist1d -
Run the training script:
python he_test_by_depth_final.py -depth=n
Replace
nwith the desired depth value. -
This code can be resumed since the log is saved in
wandband the model is also saved in a local checkpoint. It also saves intermediate values for the metrics being calculated and the loss trajectory.
-
You need a CSV file with convergence steps and loss before and after training by depth, as well as paths with weight values before and after training.
-
If the paths are specified correctly, run the Jupyter notebook file to calculate the metric values and save the results.
-
Perform the correlation test by fetching the required columns from the results. Columns 8 and 9 store the column-specific correlation coefficient values with depth. Column 8 shows the Spearman test coefficient and column 9 shows the Pearson test coefficient with p-value.
-
Install
pyhessian:pip install pyhessian
-
Download
pyhessianfrom GitHub. -
Change directory to
PyHessian:cd PyHessian -
Run the
loss_landscape_visualization.ipynbnotebook. -
(Please load the model according to the description in the markdown)
- Load the model with the matching depth.
- Ensure the model path is correctly set.
-
Navigate to the
loss-landscapefolder:cd loss-landscape -
Install required packages:
pip install -r requirements.txt
-
Plot the surface:
python plot_surface.py --cuda --model fcnn --x=-1:1:51 --y=-1:1:51 --model_file /home/yeonjoo/deepl/weight/depth1/w__depth_1.pth --dir_type weights --xnorm filter --xignore biasbn --ynorm filter --yignore biasbn --plot --depth 1 --raw_data
- Adding
mpirun -n 4enables parallel processing, but it might not work in some cases, so it is set to default as excluded. xandy: Range to search for the loss landscape. The default-1:1:51samples 51 points between -1 and 1 for each point.model_file: Path to the pre-trained model.depth: The current depth to experiment with.
- Adding
-
Plot the trajectory:
python plot_trajectory.py --dataset mnist1d --model fcnn --model_folder model_save_folder --start_epoch 0 --max_epoch 300 --save_epoch 10 --prefix model_ --suffix .pth --depth 1
- Requires checkpoints saved as
model_{epoch}.pth. Default saves every 10 epochs. model_folder: Folder where models are saved at eachsave_epoch.start_epoch: Starting epoch (default: 0).max_epoch: Last saved epoch (varies by model).save_epoch: Saving interval (default: 10).prefix: Prefix for saved models (default: model_).suffix: Suffix for saved models (default: .pth).depth: Current depth to experiment with.
- Requires checkpoints saved as
-
Plot 2D:
python plot_2D.py --surf_file /home/yeonjoo/deepl/weight/w__depth_3.pth_weights_xignore=biasbn_xnorm=filter_yignore=biasbn_ynorm=filter.h5_[-1.0,1.0,51]x[-1.0,1.0,51].h5 --dir_file /model_folder/PCA_directions.h5 --proj_file /model_folder/PCA_proj_cos.h5
surf_file: The h5 file generated after runningplot_surface.py, e.g.,/home/yeonjoo/deepl/weight/w__depth_3.pth_weights_xignore=biasbn_xnorm=filter_yignore=biasbn_ynorm=filter.h5_[-1.0,1.0,51]x[-1.0,1.0,51].h5.dir_file: Path to thedirections.h5file in thePCA_*folder generated when runningplot_trajectory.py.proj_file: Path to the*_proj_cos.h5file in thePCA_*folder generated when runningplot_trajectory.py.
- MNIST1D: https://github.com/greydanus/mnist1d
- PyHessian: https://github.com/amirgholami/PyHessian
- Loss-landscape: https://github.com/tomgoldstein/loss-landscape