PyTorch CZSL framework containing GQA, the open-world setting, and the CGE and CompCos methods.

Related tags

Deep Learning czsl
Overview

Compositional Zero-Shot Learning

This is the official PyTorch code of the CVPR 2021 works Learning Graph Embeddings for Compositional Zero-shot Learning and Open World Compositional Zero-Shot Learning. The code provides the implementation of the methods CGE, CompCos together with other baselines (e.g. SymNet, AoP, TMN, LabelEmbed+,RedWine). It also provides train and test for the Open World CZSL setting and the new GQA benchmark.

Setup

  1. Clone the repo

  2. We recommend using Anaconda for environment setup. To create the environment and activate it, please run:

    conda env create --file environment.yml
    conda activate czsl
  1. Go to the cloned repo and open a terminal. Download the datasets and embeddings, specifying the desired path (e.g. DATA_ROOT in the example):
    bash ./utils/download_data.sh DATA_ROOT
    mkdir logs

Training

Closed World. To train a model, the command is simply:

    python train.py --config CONFIG_FILE

where CONFIG_FILE is the path to the configuration file of the model. The folder configs contains configuration files for all methods, i.e. CGE in configs/cge, CompCos in configs/compcos, and the other methods in configs/baselines.

To run CGE on MitStates, the command is just:

    python train.py --config configs/cge/mit.yml

On UT-Zappos, the command is:

    python train.py --config configs/cge/utzappos.yml

Open World. To train CompCos (in the open world scenario) on MitStates, run:

    python train.py --config configs/compcos/mit/compcos.yml

To run experiments in the open world setting for a non-open world method, just add --open_world after the command. E.g. for running SymNet in the open world scenario on MitStates, the command is:

    python train.py --config configs/baselines/mit/symnet.yml --open_world

Note: To create a new config, all the available arguments are indicated in flags.py.

Test

Closed World. To test a model, the code is simple:

    python test.py --logpath LOG_DIR

where LOG_DIR is the directory containing the logs of a model.

Open World. To test a model in the open world setting, run:

    python test.py --logpath LOG_DIR --open_world

To test a CompCos model in the open world setting with hard masking, run:

    python test.py --logpath LOG_DIR_COMPCOS --open_world --hard_masking

References

If you use this code, please cite

@inproceedings{naeem2021learning,
  title={Learning Graph Embeddings for Compositional Zero-shot Learning},
  author={Naeem, MF and Xian, Y and Tombari, F and Akata, Zeynep},
  booktitle={34th IEEE Conference on Computer Vision and Pattern Recognition},
  year={2021},
  organization={IEEE}
}

and

@inproceedings{mancini2021open,
  title={Open World Compositional Zero-Shot Learning},
  author={Mancini, M and Naeem, MF and Xian, Y and Akata, Zeynep},
  booktitle={34th IEEE Conference on Computer Vision and Pattern Recognition},
  year={2021},
  organization={IEEE}
}

Note: Some of the scripts are adapted from AttributeasOperators repository. GCN and GCNII implementations are imported from their respective repositories. If you find those parts useful, please consider citing:

@inproceedings{nagarajan2018attributes,
  title={Attributes as operators: factorizing unseen attribute-object compositions},
  author={Nagarajan, Tushar and Grauman, Kristen},
  booktitle={Proceedings of the European Conference on Computer Vision (ECCV)},
  pages={169--185},
  year={2018}
}
Comments
  • CGQA data set is not available

    CGQA data set is not available

    Hi, Thank you for your work and dataset. I am trying to run the download_data.sh file. It downloads all the data sets except the cgqa. Till yesterday I can successfully download the cgqa dataset also but now it is has some issue. Can you please check it. I am getting the following error message:

    Archive:  cgqa.zip
      End-of-central-directory signature not found.  Either this file is not
      a zipfile, or it constitutes one disk of a multi-part archive.  In the
      latter case the central directory and zipfile comment will be found on
      the last disk(s) of this archive.
    unzip:  cannot find zipfile directory in one of cgqa.zip or
            cgqa.zip.zip, and cannot find cgqa.zip.ZIP, period.
    

    I downloaded the cgqa.zip from the data that I downloaded through download_data.sh and found that it is not a valid file. And when I tried to download the dataset from following url it is saying that "The Connection has timed out". https://s3.mlcloud.uni-tuebingen.de/czsl/cgqa.zip

    opened by ans92 10
  • Closed world seen acc of MIT-States in the paper is lower than what I have reimplemented

    Closed world seen acc of MIT-States in the paper is lower than what I have reimplemented

    Dear author, It is a great pleasure of reading your work. Open world compositional zero shot learning is surely an interesting topic worth to be further studied. To make myself more into the algorithm in this paper, I ran the codes several times. However I cannot get the reported results where seen acc was always 10%-20% higher than unseen acc. I found that the codes in evaluation section ran slowly somehow so I reimplemented all the evaluation codes. I used hyper-parameters precisely similar with that in the paper and freezed feature extractor ResNet18 pre-trained in ImageNet. When I ran the algorithm CompCos in closed world setting using MIT-STATES, I got 42.78% seen acc, 28.53% unseen acc in val set and 54.63% seen acc, 25.37% unseen acc in test set. 25.37% unseen acc in test set is the closest to the 24.6% unseen acc reported in the paper. Over-fitting happens both in val and test set. I wonder why seen acc in the paper of 25.3% is very close to unseen acc of 24.6% with only 0.7% difference. What is the test setting and how can I tune the results? Thank you! Great love for you

    opened by wqshmzh 9
  • Weird results on CGE@CGQA

    Weird results on CGE@CGQA

    Hi Authors,

    Thank you for your great work! I tried to reproduce the results of CEG on the CGQA dataset by running "python train.py --config configs/cge/cgqa.yaml", however, the auc on validation after running 1k+ epochs is still very low (~3e-5, far from that reported in the paper.). I just cloned the repo and set the dataset as instructed. May I know if there is anything that I should do to successfully reproduce the results?

    logs.csv Attached is the log

    opened by daoyuan98 6
  • Random code crashes with multiple num_workers.

    Random code crashes with multiple num_workers.

    I get following error that is completely random. Doesn't make sense. num_workers=0 works just fine.

    File "/opt/conda/lib/python3.8/multiprocessing/queues.py", line 108, in get raise Empty _queue.Empty The above exception was the direct cause of the following exception: Traceback (most recent call last): File "train.py", line 327, in <module> main() File "train.py", line 129, in main train(epoch, image_extractor, model, trainloader, optimizer, writer) File "train.py", line 159, in train_normal for idx, data in tqdm(enumerate(trainloader), total=len(trainloader), desc = 'Training'): File "/opt/conda/lib/python3.8/site-packages/tqdm/std.py", line 1166, in __iter__ for obj in iterable: File "/opt/conda/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 521, in __next__ data = self._next_data() File "/opt/conda/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1186, in _next_data idx, data = self._get_data() File "/opt/conda/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1152, in _get_data success, data = self._try_get_data() File "/opt/conda/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1003, in _try_get_data raise RuntimeError('DataLoader worker (pid(s) {}) exited unexpectedly'.format(pids_str)) from e RuntimeError: DataLoader worker (pid(s) 692128) exited unexpectedly

    opened by gulzainali98 3
  • Download link Broken

    Download link Broken

    download_data.sh wget --show-progress -O $FOLDER/splits.tar.gz https://www.senthilpurushwalkam.com/publication/compositional/compositional_split_natural.tar.gz leads to a blank page. Any help would be greatly appreciated.

    opened by mxjmxj1 2
  • Code for image retrieval

    Code for image retrieval

    Hi there, I see that the test code predicts the attr and obj for the given image which is one of the task, But, there is a second task of image retrieval. Given an object and attribute category, find the corresponding retrieval image. I was wondering where can I find the code for image retrieval? Many thanks!!

    opened by Pulkit-Khandelwal 2
  • Eq. (8) in Open World Compositional Zero-Shot Learning

    Eq. (8) in Open World Compositional Zero-Shot Learning

    Hi, I noticed that there used the cosine similarity minus feasibility score in Eq. 8 of your paper, while it seems that the cosine similarity plus the feasibility score in line 236 of compcos.py. I don't know if I'm wrong. Thank you for your wonderful work.

    opened by korcys 2
  • Use of cosine similarity in CompCos

    Use of cosine similarity in CompCos

    Hi, Thank you for sharing your great work. I have some questions regarding the the paper "Open World Compositional Zero-Shot Learning", which introduces Compositional Cosine Logits (CompCos).

    It explains that the image features and compositions are projected into a shared semantic space. The objective function is a cross entropy loss, where the logits of classification layer are replaced by the cosine similarity between the image features and compositional embeddings in the shared embedding space. However, in the code, the projected image features are just multiplied with the projected compositional embeddings, and cross entropy is applied directly.

    pair_pred = torch.matmul(img_feats_normed, pair_embed) loss_cos = F.cross_entropy(self.scale * pair_pred, pairs) https://github.com/ExplainableML/czsl/blob/6582c0f5de82671a8750da95f4dc280c9bef5213/models/compcos.py#L253

    Is there something that I have misunderstood? It would be great if you could point out where the cosine similarity is applied in the loss function. Thank you.

    opened by hanoonaR 2
  • problem about reproduced results of LE+

    problem about reproduced results of LE+

    very admirable work! But there is some confusing problems. In the process of reproducing some methods such as Le+[1] based on your open source code, the results obtained are better than the results of Table 2 in article [2]. Is the published code somehow different from the setup in article [2]? Could you give some explanation?

    [1] From redwine to red tomato: Composition with context [2] Learning Graph Embeddings for Compositional Zero-shot Learning

    opened by zaiquanyang 2
  • Cuda Running out of memory during evaluate_predictions

    Cuda Running out of memory during evaluate_predictions

    I am trying to replicate the results of Compcos using Mit-States dataset & i am getting the following error:

    File "train.py", line 228, in main() File "train.py", line 108, in main test(epoch, image_extractor, model, testloader, evaluator_val, writer, args, logpath) File "train.py", line 193, in test stats = evaluator.evaluate_predictions(results, all_attr_gt, all_obj_gt, all_pair_gt, all_pred_dict, topk=args.topk) File "/nfs4/krissna/OWCZL/czsl-main/czsl-main/models/common.py", line 489, in evaluate_predictions results = self.score_fast_model(scores, obj_truth, bias = bias, topk = topk) File "/nfs4/krissna/OWCZL/czsl-main/czsl-main/models/common.py", line 363, in score_fast_model scores[~mask] += bias # Add bias to test pairs RuntimeError: CUDA out of memory. Tried to allocate 4.18 GiB (GPU 0; 10.92 GiB total capacity; 4.68 GiB already allocated; 2.44 GiB free; 7.85 GiB reserved in total by PyTorch)

    (Currently using Cuda10.2 10Gis) Please suggest some solution for the above error. Thanks

    opened by utkarsh-bhalode 2
  • Question about train_forward_bce function in ManifoldModel

    Question about train_forward_bce function in ManifoldModel

    Hi,

    Thanks for the high quality open-resourced codebase.

    I suspect that the Line 59 of czsl/models/manifold_methods.py should be

    composed_clf = self.compose(sampled_attrs, sampled_objs)
    

    instead of the current

    composed_clf = self.compose(attrs, objs)
    

    As I am a beginner in the CZSL field, I apologize for any misunderstandings that may exist. Looking forward to any response.

    opened by bighuang624 2
  • FileNotFoundError: Caught FileNotFoundError in DataLoader worker process 0.

    FileNotFoundError: Caught FileNotFoundError in DataLoader worker process 0.

    when i run the train.py with mit.yml ,here is the error: Traceback (most recent call last): File "train.py", line 233, in main() File "train.py", line 100, in main train(epoch, image_extractor, model, trainloader, optimizer, writer) File "train.py", line 122, in train_normal for idx, data in tqdm(enumerate(trainloader), total=len(trainloader), desc = 'Training'): File "/home/idea/anaconda3/envs/czsl/lib/python3.8/site-packages/tqdm/std.py", line 1166, in iter for obj in iterable: File "/home/idea/anaconda3/envs/czsl/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 435, in next data = self._next_data() File "/home/idea/anaconda3/envs/czsl/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1085, in _next_data return self._process_data(data) File "/home/idea/anaconda3/envs/czsl/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1111, in _process_data data.reraise() File "/home/idea/anaconda3/envs/czsl/lib/python3.8/site-packages/torch/_utils.py", line 428, in reraise raise self.exc_type(msg) FileNotFoundError: Caught FileNotFoundError in DataLoader worker process 0. Original Traceback (most recent call last): File "/home/idea/anaconda3/envs/czsl/lib/python3.8/site-packages/torch/utils/data/_utils/worker.py", line 198, in _worker_loop data = fetcher.fetch(index) File "/home/idea/anaconda3/envs/czsl/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File "/home/idea/anaconda3/envs/czsl/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 44, in data = [self.dataset[idx] for idx in possibly_batched_index] File "/home/idea/zzy/czsl/data/dataset.py", line 405, in getitem img = self.loader(image) File "/home/idea/zzy/czsl/data/dataset.py", line 25, in call img = Image.open(ospj(self.root_dir,img)).convert('RGB') #We don't want alpha File "/home/idea/anaconda3/envs/czsl/lib/python3.8/site-packages/PIL/Image.py", line 2904, in open fp = builtins.open(filename, "rb") FileNotFoundError: [Errno 2] No such file or directory: 'DATA_ROOT/mit-states/images/ripe_coffee/IMG_3474.jpg'

    but when I run with the utzappos dataset, there are no errors! I have not idea how to fix this error. IMG_3474.jpg is really an existing file in "DATA_ROOT/mit-states/images/ripe_coffee". How can I fix that error

    opened by Swagzzy4 3
  • Questions about the reported HM number (60.5) of CGE on UT-Zap50K?

    Questions about the reported HM number (60.5) of CGE on UT-Zap50K?

    Hi,

    Thanks for the impressive paper and high quality open-resourced codebase.

    I ran an experiment on zappos with this codebase (w/o any editing) and found that there is a big gap between the testset HM number(47.11) of CGE to the reported one(60.5) in the paper. The following is the eval log on test set

    image

    Furthermore, from this log, although the test auc number is close to the reported one(33.5), but the best unseen(66.05) also has a big gap to the reported one(71.5).

    I am a little bit confused about these number gaps and could you please be kind to give some explainations. Thanks a lot.

    opened by HeimingX 4
  • C-GQA dataset: Some pairs in train_pairs.txt don't have image examples in the training set

    C-GQA dataset: Some pairs in train_pairs.txt don't have image examples in the training set

    Thank you for the new dataset. I have one question about it. I find 133 pairs in train_pairs.txt that don't have any image examples in the training set. Some examples of them are: "angry person", "long_sleeved shirt", "open drawer", "small duck". Can you check this out?

    opened by vkhoi 11
Owner
EML Tübingen
Explainable Machine Learning group at University of Tübingen
EML Tübingen
A Planar RGB-D SLAM which utilizes Manhattan World structure to provide optimal camera pose trajectory while also providing a sparse reconstruction containing points, lines and planes, and a dense surfel-based reconstruction.

ManhattanSLAM Authors: Raza Yunus, Yanyan Li and Federico Tombari ManhattanSLAM is a real-time SLAM library for RGB-D cameras that computes the camera

null 117 Dec 28, 2022
aka "Bayesian Methods for Hackers": An introduction to Bayesian methods + probabilistic programming with a computation/understanding-first, mathematics-second point of view. All in pure Python ;)

Bayesian Methods for Hackers Using Python and PyMC The Bayesian method is the natural approach to inference, yet it is hidden from readers behind chap

Cameron Davidson-Pilon 25.1k Jan 2, 2023
Implementation of temporal pooling methods studied in [ICIP'20] A Comparative Evaluation Of Temporal Pooling Methods For Blind Video Quality Assessment

Implementation of temporal pooling methods studied in [ICIP'20] A Comparative Evaluation Of Temporal Pooling Methods For Blind Video Quality Assessment

Zhengzhong Tu 5 Sep 16, 2022
Scripts and a shader to get you started on setting up an exported Koikatsu character in Blender.

KK Blender Shader Pack A plugin and a shader to get you started with setting up an exported Koikatsu character in Blender. The plugin is a Blender add

null 166 Jan 1, 2023
Complete the code of prefix-tuning in low data setting

Prefix Tuning Note: 作者在论文中提到使用真实的word去初始化prefix的操作(Initializing the prefix with activations of real words,significantly improves generation)。我在使用作者提供的

Andrew Zeng 4 Jul 11, 2022
Rethinking of Pedestrian Attribute Recognition: A Reliable Evaluation under Zero-Shot Pedestrian Identity Setting

Pytorch Pedestrian Attribute Recognition: A strong PyTorch baseline of pedestrian attribute recognition and multi-label classification.

Jian 79 Dec 18, 2022
Pytorch implementation for "Large-Scale Long-Tailed Recognition in an Open World" (CVPR 2019 ORAL)

Large-Scale Long-Tailed Recognition in an Open World [Project] [Paper] [Blog] Overview Open Long-Tailed Recognition (OLTR) is the author's re-implemen

Zhongqi Miao 761 Dec 26, 2022
[CVPR 2022] Official Pytorch code for OW-DETR: Open-world Detection Transformer

OW-DETR: Open-world Detection Transformer (CVPR 2022) [Paper] Akshita Gupta*, Sanath Narayan*, K J Joseph, Salman Khan, Fahad Shahbaz Khan, Mubarak Sh

Akshita Gupta 127 Dec 27, 2022
TorchX is a library containing standard DSLs for authoring and running PyTorch related components for an E2E production ML pipeline.

TorchX is a library containing standard DSLs for authoring and running PyTorch related components for an E2E production ML pipeline

null 193 Dec 22, 2022
Scientific Computation Methods in C and Python (Open for Hacktoberfest 2021)

Sci - cpy README is a stub. Do expand it. Objective This repository is meant to be a ready reference for scientific computation methods. Do ⭐ it if yo

Sandip Dutta 7 Oct 12, 2022
Open-World Entity Segmentation

Open-World Entity Segmentation Project Website Lu Qi*, Jason Kuen*, Yi Wang, Jiuxiang Gu, Hengshuang Zhao, Zhe Lin, Philip Torr, Jiaya Jia This projec

DV Lab 410 Jan 3, 2023
Learning Open-World Object Proposals without Learning to Classify

Learning Open-World Object Proposals without Learning to Classify Pytorch implementation for "Learning Open-World Object Proposals without Learning to

Dahun Kim 149 Dec 22, 2022
the code for paper "Energy-Based Open-World Uncertainty Modeling for Confidence Calibration"

EOW-Softmax This code is for the paper "Energy-Based Open-World Uncertainty Modeling for Confidence Calibration". Accepted by ICCV21. Usage Commnd exa

Yezhen Wang 36 Dec 2, 2022
[NeurIPS 2021] “Improving Contrastive Learning on Imbalanced Data via Open-World Sampling”,

Improving Contrastive Learning on Imbalanced Data via Open-World Sampling Introduction Contrastive learning approaches have achieved great success in

VITA 24 Dec 17, 2022
Video-based open-world segmentation

UVO_Challenge Team Alpes_runner Solutions This is an official repo for our UVO Challenge solutions for Image/Video-based open-world segmentation. Our

Yuming Du 84 Dec 22, 2022
Towards Open-World Feature Extrapolation: An Inductive Graph Learning Approach

This repository holds the implementation for paper Towards Open-World Feature Extrapolation: An Inductive Graph Learning Approach Download our preproc

Qitian Wu 42 Dec 27, 2022
RE-OWOD - Revisiting open world object detection

Revisting Open World Object Detection Installation See INSTALL.md. Dataset Our n

null 7 Jan 5, 2022