This code implements Concept-Guided Conditional Diffusion, Concept-Guided ProtoPNet, and Concept-Guided ProtoPools.
Used datasets were:
- Caltech CUB_200_2011, available at: https://www.vision.caltech.edu/datasets/cub_200_2011/
- Animals with Attributes 2, available at: https://cvml.ista.ac.at/AwA2/
This part is adapted from previous code available here: https://github.com/tcapelle/Diffusion-Models-pytorch
datasetscontains the files to import the CUB and AwA2 datasets and prepare the data loadersmodules.pycontains the model implementationsutils.pycontains helper functionsddpm_conditional_emb.pycontains the main training algorithmsampling.pycontains code to sample new images from an already trained model
Command example to train a new model:
python ddpm_conditional_emb.py --mask 0 75 --embedding_type 'embpos'
Command example to sample new images:
python ddpm_conditional_emb.py --num_samples 15 --mask 0 75 --embedding_type 'embpos'
This part is adapted from previous code available here: https://github.com/cfchen-duke/ProtoPNet/tree/master
datasetscontains the files to import the CUB and AwA2 datasets and prepare the data loadersutilscontains different util files:densenet_features.py,resnet_features.py, andvgg_features.pycontain code to load pre-trained models from ImageNetpreprocess.py,receptive_field.pyandhelpers.pycontain helper functions for the implementation of the model and the trainingfind_nearest.pycontains the function that finds the closest patches to the prototypes to create the concept prototype datasetpush.pycontains code to perform the pushing of prototypes, whereaspushing.pyallows to push prototypes for an already trained modelCUB_correlation.pycontains code to calculate the correlations between concepts in the CUB dataset
train_and_test.pycontains the main train and testing function used in the training loopmodel.pycontains the CG-ProtoPNet modelmain.pycontains the main training algorithmprototype_dataset.pyallows the calculation of the concept prototype dataset from a pre-trained model
Command example to train a new model:
python main.py --base_architecture 'vgg16' --coefs_clst 0.8 --coefs_sep = -0.08 --coefs_l1 1e-4
Command example to create the concept prototype dataset:
python prototype_dataset.py --modeldir 'path_to_model_directory' --model 'model_name'
This part is adapted from previous code available here: https://github.com/gmum/ProtoPool
datasetscontains the files to import the CUB and AwA2 datasets and prepare the data loadersutilscontains different util files:densenet_features.py,resnet_features.py, andvgg_features.pycontain code to load pre-trained models from ImageNetutils.pycontains helper functions for the implementation of the model and the trainingfind_nearest.pycontains the function that finds the closest patches to the prototypes to create the concept prototype datasetpushing.pycontains code to push prototypes for an already trained modelshared_prototypes.pycontains code to calculate the number of shared prototypes between concepts
model.pycontains the CG-ProtoPools modelmain.pycontains the main training algorithmprototype_dataset.pyallows the calculation of the concept prototype dataset from a pre-trained model
Command example to train a new model:
python main.py --base_architecture 'vgg16' --clst_weight 0.8 --sep_weight = -0.08 --l1_weight 1e-4 --orth_p_weight 1 --orth_c_weight 1
Command example to create the concept prototype dataset:
python prototype_dataset.py --modeldir 'path_to_model_directory' --model 'model_name'