Skip to content

danni9594/CTML

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CTML

This is the experimental code for our paper "Clustered Task-Aware Meta-Learning by Learning from Learning Paths".

Requirements

python 2.*
pillow
numpy
pandas
scipy
tensorflow 1.10+

Few-Shot Image Classification

Navigate to few_shot_image directory for few-shot image classification experiments:

cd few_shot_image

Data Preprocessing

Meta-Dataset

  1. Download the pre-processed datasets of CUB-200-2011, FGVC-Aircraft, FGVCx-Fungi, and Describable Textures here released by the authors of HSML. Extract under data directory, which will create a meta-dataset folder containing the four sub-datasets.
  2. Download images and labels from VGG Flower official website. Move under data directory.
  3. Download GTSRB_Final_Training_Images.zip from GTSRB official website. Extract under data directory.
  4. Preprocess VGG Flower and GTSRB datasets (resize image + split data) by running:

cd data_preproc
python preproc_flower.py
python preproc_tsign.py

  1. Convert image file to numpy array and store in dict (for faster I/O at training time) by running:

python convert_dict_meta_dataset.py

Mini-Imagenet

  1. Download Mini-Imagenet here. Extract under data/miniimagenet directory.
  2. Preprocess Mini-Imagenet dataset (resize image + split data) by running:

cd data_preproc
python preproc_miniimagenet.py

  1. Convert image file to numpy array and store in dict (for faster I/O at training time) by running:

python convert_dict_miniimagenet.py

Data Directory Structure

After pre-processing, few_shot_image/data directory should have the following structure.

few_shot_image/data
├── meta-dataset
│   ├── CUB_Bird
│   │   ├── train_dict.pkl
│   │   ├── val_dict.pkl
│   │   └── test_dict.pkl
│   ├── DTD_Texture
│   │   ├── train_dict.pkl
│   │   ├── val_dict.pkl
│   │   └── test_dict.pkl
│   ├── FGVC_Aircraft
│   │   ├── train_dict.pkl
│   │   ├── val_dict.pkl
│   │   └── test_dict.pkl
│   ├── FGVCx_Fungi
│   │   ├── train_dict.pkl
│   │   ├── val_dict.pkl
│   │   └── test_dict.pkl
│   ├── GTSRB_Tsign
│   │   ├── train_dict.pkl
│   │   ├── val_dict.pkl
│   │   └── test_dict.pkl
│   └── VGG_Flower
│   │   ├── train_dict.pkl
│   │   ├── val_dict.pkl
│   │   └── test_dict.pkl
└── miniimagenet
    ├── train_dict.pkl
    ├── val_dict.pkl
    └── test_dict.pkl

Meta-Training

To train the proposed model and variants on Meta-Dataset under different settings, run the following:

Setting Method Command
5-way 1-shot CTML python main.py --data meta_dataset --support_size 1 --path_or_feat both
5-way 1-shot CTML-path python main.py --data meta_dataset --support_size 1 --path_or_feat only_path
5-way 1-shot CTML-feat (ARML) python main.py --data meta_dataset --support_size 1 --path_or_feat only_feat
5-way 5-shot CTML python main.py --data meta_dataset --support_size 5 --path_or_feat both
5-way 5-shot CTML-path python main.py --data meta_dataset --support_size 5 --path_or_feat only_path
5-way 5-shot CTML-feat (ARML) python main.py --data meta_dataset --support_size 1 --path_or_feat only_feat

Meta-Testing

To evaluate the proposed model and variants on Meta-Dataset under different settings, run the following:

Setting Method Command
5-way 1-shot CTML python main.py --data meta_dataset --support_size 1 --path_or_feat both --eval --test_iters 59000 58000 57000
5-way 1-shot CTML-path python main.py --data meta_dataset --support_size 1 --path_or_feat only_path --eval --test_iters 59000 58000 57000
5-way 1-shot CTML-feat python main.py --data meta_dataset --support_size 1 --path_or_feat only_feat --eval --test_iters 59000 58000 57000
5-way 5-shot CTML python main.py --data meta_dataset --support_size 5 --path_or_feat both --eval --test_iters 59000 58000 57000
5-way 5-shot CTML-path python main.py --data meta_dataset --support_size 5 --path_or_feat only_path --eval --test_iters 59000 58000 57000
5-way 5-shot CTML-feat python main.py --data meta_dataset --support_size 1 --path_or_feat only_feat --eval --test_iters 59000 58000 57000

Cold-Start Recommendation

Navigate to cold_start_recsys directory for cold-start recommendation experiments:

cd cold_start_recsys

Data Preprocessing

MovieLens-1M

  1. Download ml-1m.zip from MovieLens datasets official website. Extract under data/movielens_1m directory.
  2. Preprocess MovieLens-1M dataset (construct samples with side information + split data) by running:

cd data_preproc
python preproc_ml.py

Yelp

  1. Download Yelp dataset from the official website. Extract under data directory, which will create a yelp_dataset folder.
  2. Extract only useful information from the raw JSON files (for faster preprocessing later) by running:

cd data_preproc
python convert_json_yelp.py

  1. Preprocess Yelp dataset (construct samples with side information + split data) by running:

python preproc_yelp.py

Amazon-CDs

  1. Download ratings and metadata of Amazon CDs and Vinyl category from the official website. Move under data/amazon_cds directory.
  2. Extract only useful information from the item metadata JSON file (for faster preprocessing later) by running:

cd data_preproc
python convert_json_amzcd.py

  1. Preprocess Amazon-CDs dataset (construct samples with side information + split data) by running:

python preproc_amzcd.py

Data Directory Structure

After pre-processing, cold_start_recsys/data directory should have the following structure.

cold_start_recsys/data
├── movielens_1m
│   ├── train_df.csv
│   ├── val_df.csv
│   ├── test_df.csv
│   ├── user_dict.pkl  // user info in one-hot/multi-hot
│   ├── item_dict.pkl  // item info in one-hot/multi-hot
│   └── user_set_dict.pkl  // record warm and cold user set
├── yelp_dataset
│   ├── train_df.csv
│   ├── val_df.csv
│   ├── test_df.csv
│   ├── user_dict.pkl
│   ├── item_dict.pkl
│   └── user_set_dict.pkl
└── amazon_cds
    ├── train_df.csv
    ├── val_df.csv
    ├── test_df.csv
    ├── user_dict.pkl
    ├── item_dict.pkl
    └── user_set_dict.pkl

Meta-Training & Meta-Testing

To train the proposed model and variants on MovieLens-1M under different settings, run the following:

Method Command
CTML python main.py --data movielens_1m --path_or_feat both
CTML-path python main.py --data movielens_1m --path_or_feat only_path
CTML-feat python main.py --data movielens_1m --path_or_feat only_feat

Meta-testing will be automatically performed after every epoch of meta-training.

Acknowledgement

This code is modified based on ARML and MeLU. We thank the authors for their contributions.

Citation

If you find this repo useful in your research, please cite the following:

@article{peng2023clustered,
  title={Clustered Task-Aware Meta-Learning by Learning From Learning Paths},
  author={Peng, Danni and Pan, Sinno Jialin},
  journal={IEEE Transactions on Pattern Analysis and Machine Intelligence},
  year={2023},
  publisher={IEEE}
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages