Welcome to the world of knowledge distillation in computer vision! In this blog, we will explore the MDistiller library that provides classical knowledge distillation algorithms utilizing mainstream computer vision (CV) benchmarks. You’ll learn how to install and use this library for your projects effectively, along with troubleshooting tips to help you out in your AI journey.
What is MDistiller?
MDistiller is a PyTorch library designed for two significant purposes:
- To offer classical knowledge distillation algorithms applicable to various CV benchmarks.
 - To provide official implementations of notable research papers, including Decoupled Knowledge Distillation (CVPR 2022) and DOT: A Distillation-Oriented Trainer (ICCV 2023).
 
Installation Guide
Before diving into the usage of MDistiller, you need to set up your environment. Follow these simple steps:
- Ensure you have the following environments installed:
        
- Python 3.6
 - PyTorch 1.9.0
 - torchvision 0.10.0
 
 - Install the required packages using the following commands:
 
sudo pip3 install -r requirements.txt
sudo python3 setup.py develop
    
Getting Started with MDistiller
Now that you have installed MDistiller, let’s explore how to get started:
Step 1: Set Up Weights & Biases (Wandb)
If you want to use Wandb for logging, register at Wandb. If you prefer not to use it, simply set CFG.LOG.WANDB to False in mdistiller/engine/cfg.py.
Step 2: Evaluation
You can evaluate the performance of pre-trained models or models trained by yourself. Download the model checkpoints from here and save them in the .download_ckpts folder. If you’re testing models on ImageNet, download the dataset from ImageNet and save it in .data/imagenet.
Run the following commands for evaluation:
python3 tools/eval.py -m resnet32x4  # ResNet32x4 on CIFAR-100
python3 tools/eval.py -m ResNet34 -d imagenet  # ResNet34 on ImageNet
Step 3: Training Models
MDistiller supports training models on CIFAR-100, ImageNet, and MS-COCO. For example, to train a model on CIFAR-100 using DKD method:
- Download the CIFAR teachers’ weights using this link.
 - Use the following command to start training:
 
python3 tools/train.py --cfg configs/cifar100/dkd/res32x4_res8x4.yaml
    
Understanding the Code through Analogy
Think of knowledge distillation like a master chef (the teacher model) training a new apprentice (the student model). The master chef has extensive experience and techniques that they have perfected over the years. They can teach the apprentice by demonstrating cooking techniques, allowing the apprentice to mimic and learn through practice. In MDistiller:
- **Teacher Model**: This represents the well-trained model (master chef).
 - **Student Model**: This is the learner, which aims to replicate the teacher’s performance.
 - **Distillation Techniques**: These are the various ways the master chef can convey their knowledge to the apprentice, enhancing their skills.
 
Just as the apprentice becomes increasingly skilled under the guidance of the master chef, your student models benefit from the knowledge of their teachers, becoming proficient in tasks through techniques like Decoupled Knowledge Distillation.
Troubleshooting
If you run into any issues while using MDistiller, here are some helpful troubleshooting ideas:
- Check your Python and library versions to ensure compatibility.
 - If you experience installation errors, review your environment setups, such as virtual environments.
 - For issues with Wandb, confirm that your credentials are correctly set up and that you are logged in.
 - When encountering evaluation problems, verify that all required model checkpoints and datasets are correctly downloaded and stored in the expected directories.
 
For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.
Conclusion
And there you have it! You are now ready to embark on your journey with MDistiller, executing knowledge distillation like a seasoned chef introducing the art of culinary mastery. At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

