Code for Active Mixup in 2020 CVPR
- You need a well-trained teacher model with sufficient accuracy, such as top-1 ~93% for CIFAR-10.
- For CIFAR-10, convert CIFAR10 Data to PNG or JPG format. (https://github.com/knjcode/cifar2png.git) For example, run git clone https://github.com/knjcode/cifar2png.git at current directory. Follow the instruction to install it and make sure all converted png images are stored in active_mixup/cifar2png/cifar10png/ , which contains train and test folders.
- Locate train data directory and specify root in 00_data_prep.sh with it. For example, with downloaded cifar10 above, we use root=./cifar2png/cifar10png/train .
************* Stage 0 ********************************
- 00_data_prep.sh (randomly select real images and mix them to a candidate pool)
- 01_data_prep.sh (query teacher model and obtain the first real image training set)
- active_train.sh (train the model with real images data)
************* Stage 1 ********************************
- 10_data_prep.sh (query student network)
- 11_data_prep.sh (query teacher model and extend training data)
- active_rain.sh (train the model with new dataset)
************* Stage 2 (repeat the above) *************
- 10_data_prep.sh
- 11_data_prep.sh
- active_train.sh
************* Stage 3 (repeat the above) *************
...
- Specify the number of real_images with 1000, 2000, ...
- The code will generate combination indieces pool. To save the space, the dumped pkl only stores paths instead of arrays.
- The real images will be dumped into ./images folder.
- Specify checkpoint in py file for teacher query model. For example, checkpoint = torch.load('./checkpoint/cifar10_vgg16_teacher.pth')
- In my_loader, specify real_img_query_loader with the pkl of real images. For example, datainfo = pickle.load(open('./images/cifar10_real_images_1000.pkl', 'rb'))
- The code will generate real image query results and dump the results into query folder ./images/query. For example, ./images/query/cifar10_query_label_###.pkl
- Specify checkpoint in py file for student query model. For example, checkpoint = torch.load('./active_student_models/cifar10_vgg_student_model_1000.pth'). Note that you need at least one student model for query.
- Specify the number of selected mixed images for each stage. For example, local_indices = np.argsort(unc_tags)[:10000], which implies that we select top uncertain 10K images.
- In my loder, specify mix_img_query_loader with the pkl of mixed image candidate pool. For example, datainfo = pickle.load(open('./images/cifar10_mix_images_499000.pkl', 'rb')).
- The code will generate two sets, including left unlabeled images and selected images. To save the space, unlabeled images are dumped in the format of paths. Selected images here haven't queried teacher model yet.
- Specify checkpoint in py file for teacher query model. For example, checkpoint = torch.load('./checkpoint/cifar10_vgg16_teacher.pth')
- Specify current labeled images. For example, datainfo = pickle.load(open('./images/query/cifar10_query_label_1000.pkl', 'rb'))
- In my loder, specify active_query_loader with the pkl of selected images from 10_data_prep.py. For example, datainfo = pickle.load(open('./images/query/cifar10_query_new_label_10000.pkl', 'rb')).
- The code will concatenate the new query labeled images to the previously obtained labeled images, dumping the new query set.
- Specify lr, model_out, and log generation path.
- In my loader, specify active_learning_loader with obtained training set. For example, datainfo = pickle.load(open('./images/query/cifar10_query_label_1000.pkl', 'rb')).
- The code will generate a well-trained model with current training set.
- The first set of real images are randomly selected and training process is stochastic, so the training accuracies can show variations (maybe +/- 2%).
- Active learning is an incremental process, so the previous student model can affect the next student training. Some variation can occur.
- You may try the example with run_00.sh and run_01.sh for Stage 0 and Stage 1 with 1000 images. Please remember to modify active_learning_loader in my loader after running run_00.sh for new training with run_01.sh.
If you have any questions, please feel free to contact me. Thanks very much for your interest and questions in advance.
@inproceedings{wang2020neural,
title={Neural networks are more productive teachers than human raters: Active mixup for data-efficient knowledge distillation from a blackbox model},
author={Wang, Dongdong and Li, Yandong and Wang, Liqiang and Gong, Boqing},
booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
pages={1498--1507},
year={2020}
}