This repository provides the code to conduct the experiments of the paper "Convolutional Spectral Kernel Learning with Generalization Guarantees".
- Python 3.7.4
- Pytorch 1.10.0
- NNI 2.5
- CUDA 10.1.168
- cuDnn 7.6.0
- Gpytorch 1.6.0
- GPU: Nvidia RTX 2080Ti 11G
models.pyimplements random features based neural networks, including RFFNet and DSKN, their convoluational versions CRFFNet and CSKN, and their vgg-type versions CRFFNet8 and CSKN8. Meanwhile, models.py implements thetrain()andtest()methods for these models.utils.pyimplements useful tools for loading primal and resized datasets to feed neural networks.densenet.pyis used to implement deep kernel learning (DKL) from Gpytorch.exp_ablation0_*.py,exp_ablation1_layers.py,exp_ablation2_regularizers.py, andexp_ablation3_convolutional.pyare used to explore the effects of non-stationary spectral kernels, the depth of network, additional regularizers, and convolutional filters on the MNIST dataset, respectively.exp_comparison_CSKN.pytrainsCSKN8andCRFFNet8on large image datasets, whileexp_comparison_DKLModel.pyandexp_comparison_PretrainedModels.pyimplement and train DKL and popular CNN networks, respectively.ipy_exp_ablation.ipynbandipy_exp_comparison.ipynbload and illustrate ablation and comparison experimental results, respectively.tune_model.pyandtune_config.ymlare is used to tune hyperparameters vi NNI.datafolder stores all datasets, includingMNIST, FashionMNIST, CIFAR10, CIFAR100, andTinyImagenet.resultsfolder records experimental results andfiguresfolder stores pdf files for illustrating experimental results.
- Run the following scripts for ablation experiments
python3 exp_ablation0_RFFNet.py
python3 exp_ablation0_DSKN.py
python3 exp_ablation1_layers.py --num_layers 1
python3 exp_ablation1_layers.py --num_layers 2
python3 exp_ablation1_layers.py --num_layers 3
python3 exp_ablation1_layers.py --num_layers 4
python3 exp_ablation1_layers.py --num_layers 5
python3 exp_ablation2_regularizers.py
python3 exp_ablation3_convolutional.py --kernel_size 3
python3 exp_ablation3_convolutional.py --kernel_size 5
python3 exp_ablation3_convolutional.py --kernel_size 7
- Run codes in
ipy_exp_ablation.ipynbto illstrate experimental results.
-
Download
TinyImagenetdataset intodatafolder and process it bytinyimagenet_preprocess.py. The other datasetsMNIST, FashionMNIST, CIFAR10, CIFAR100can be downloaded automatically when they are used for the first time. -
Conduct experiments for
CSKN8andCRFFNet8on each dataset
python3 exp_comparison_CSKN.py --model CSKN8 --dataset $dataset_name --epochs 300 --repeates 1
python3 exp_comparison_CSKN.py --model CRFFNet8 --dataset $dataset_name --epochs 300 --repeates 1
- Conduct experiments for
DKLmodels on each dataset
python3 exp_comparison_DKLModel.py --dataset $dataset_name --epochs 300 --repeates 1
- Conduct experiments for popular CNN models
resnet, vgg, densenet, shuffleneton each dataset
python3 exp_comparison_PretrainedModels.py --model resnet --dataset $dataset_name --epochs 300 --repeates 1
python3 exp_comparison_PretrainedModels.py --model vgg --dataset $dataset_name --epochs 300 --repeates 1
python3 exp_comparison_PretrainedModels.py --model densenet --dataset $dataset_name --epochs 300 --repeates 1
python3 exp_comparison_PretrainedModels.py --model shufflenet --dataset $dataset_name --epochs 300 --repeates 1
- Run ipy_exp_comparison.ipynb to demenstrate experimental results.
- Install NNI
pip install nni - Modify the running script
tune_model.pyand the configuration filetune_config.yml. - Tune hyparameters vi NNI
nnictl create --config ./tune_config.ymland visit127.0.0.1:8080to view resuls.