Code for "Meta-Meta Classification for One-Shot Learning"
Execute the following script to download the data.
python ./utils/get_dataset_script/get_<dataset>.py
<dataset>
can be ILSVRC
, aircraft
, bird
and omniglot
.
Note: Register at ImageNet and request for a username and an access key to download ILSRVC-2012 data set. Pass them as arguments to above command.
python ./utils/get_dataset_script/get_ILSVRC.py accesskey username
python resnet/resnet_train_imagenet.py data/ILSVRC
python resnet_feature_extract.py data/<dataset> --resume model_best_imagenet.pth.tar -f train
python resnet_feature_extract.py data/<dataset> --resume model_best_imagenet.pth.tar -f test
Output: .npy
files containing features of train images in data/<dataset>/features_train
and test images in data/<dataset>/features_test
.
Cluster the training data using k-means:
python ./utils/cluster_images.py data/<dataset> -ds <dataset> -n num_clusters
Predict the nearest cluster for the test data using the learnt k-means:
python ./utils/cluster_images.py data/<dataset> -ds <dataset> -n num_clusters -t
python main.py data/ILSVRC/ ckptILSVRC_4_0/ -p filelistILSVRC_4_0 -cf cluster_4_0
python main.py data/ILSVRC/ ckptILSVRC_4_1/ -p filelistILSVRC_4_1 -cf cluster_4_1
python main.py data/ILSVRC/ ckptILSVRC_4_2/ -p filelistILSVRC_4_2 -cf cluster_4_2
python main.py data/ILSVRC/ ckptILSVRC_4_3/ -p filelistILSVRC_4_3 -cf cluster_4_3
Output: This creates 4 saved models for 4 clusters.
Training
python ./data_generators/data_generator.py
Testing
python ./data_generators/data_generator.py -t
Output: filelistILSVRC
(for training) and filelistILSVRC_test
(for testing)
Training problems:
python ./main_query.py data/ILSVRC/ ckptILSVRC_4_0/ -p filelistILSVRC -cf cluster_4_0 -cl 4 -m 0
python ./main_query.py data/ILSVRC/ ckptILSVRC_4_1/ -p filelistILSVRC -cf cluster_4_1 -cl 4 -m 1
python ./main_query.py data/ILSVRC/ ckptILSVRC_4_2/ -p filelistILSVRC -cf cluster_4_2 -cl 4 -m 2
python ./main_query.py data/ILSVRC/ ckptILSVRC_4_3/ -p filelistILSVRC -cf cluster_4_3 -cl 4 -m 3
Test problems:
python ./main_query.py data/ILSVRC/ ckptILSVRC_4_0/ -p filelistILSVRC_test -cf cluster_4_0 -cl 4 -m 0 -t
python ./main_query.py data/ILSVRC/ ckptILSVRC_4_1/ -p filelistILSVRC_test -cf cluster_4_1 -cl 4 -m 1 -t
python ./main_query.py data/ILSVRC/ ckptILSVRC_4_2/ -p filelistILSVRC_test -cf cluster_4_2 -cl 4 -m 2 -t
python ./main_query.py data/ILSVRC/ ckptILSVRC_4_3/ -p filelistILSVRC_test -cf cluster_4_3 -cl 4 -m 3 -t
This generates .npy
files storing the query logits (preds) and query accuracy for all these problems.
python ./main_MC.py data/ILSVRC/ ckptILSVRC_moe/ -p filelistILSVRC -n 4
Output: meta-aggregator model ckptILSVRC_moe
python ./main_MC.py data/ILSVRC/ ckptILSVRC_moe/ -p filelistILSVRC_test -n 4 -t
Output: final accuracy, CI95
NOTE: use -ds omniglot
in step 1, 3 for omniglot
data-set.
python main.py data/ILSVRC/ ckptILSVRC5way_4_0/ -p filelistILSVRC5way_4_0 -cf cluster_4_0 \
--kquery 15 --nway 5 --multi
python main.py data/ILSVRC/ ckptILSVRC5way_4_1/ -p filelistILSVRC5way_4_1 -cf cluster_4_1 \
--kquery 15 --nway 5 --multi
python main.py data/ILSVRC/ ckptILSVRC5way_4_2/ -p filelistILSVRC5way_4_2 -cf cluster_4_2 \
--kquery 15 --nway 5 --multi
python main.py data/ILSVRC/ ckptILSVRC5way_4_3/ -p filelistILSVRC5way_4_3 -cf cluster_4_3 \
--kquery 15 --nway 5 --multi
python data_generators/data_generator.py -t --kquery 15 --nway 5 -p filelistILSVRC5way \
--multi --test_problems 600 ILSVRC
Output: filelistILSVRC5way_test
(for testing)
python main_query.py data/ILSVRC/ ckptILSVRC5way_4_0/ -p filelistILSVRC5way_test -cf cluster_4_0 \
-cl 4 -m 0 --kquery 15 --nway 5 --multi --test_problems 600 -t
python main_query.py data/ILSVRC/ ckptILSVRC5way_4_1/ -p filelistILSVRC5way_test -cf cluster_4_1 \
-cl 4 -m 0 --kquery 15 --nway 5 --multi --test_problems 600 -t
python main_query.py data/ILSVRC/ ckptILSVRC5way_4_2/ -p filelistILSVRC5way_test -cf cluster_4_2 \
-cl 4 -m 0 --kquery 15 --nway 5 --multi --test_problems 600 -t
python main_query.py data/ILSVRC/ ckptILSVRC5way_4_3/ -p filelistILSVRC5way_test -cf cluster_4_3 \
-cl 4 -m 0 --kquery 15 --nway 5 --multi --test_problems 600 -t
python main_MC.py data/ILSVRC/ ckptILSVRC_moe/ -p filelistILSVRC5way_test \
-n 4 --kquery 15 --nway 5 --multi -t
Output: Final accuracy, CI95
data/<dataset>
0.0001
for clusters, 0.001
on whole data0.001
cluster_<num_clusters>_<cluster_id>
for clusters, None
for whole datanum_clusters
4
5
40,000
100,000
10,000