GithubHelp home page GithubHelp logo

cdancette / rubi.bootstrap.pytorch Goto Github PK

View Code? Open in Web Editor NEW
59.0 6.0 14.0 187 KB

NeurIPS 2019 Paper: RUBi : Reducing Unimodal Biases for Visual Question Answering

License: BSD 3-Clause "New" or "Revised" License

Python 99.15% Shell 0.85%
vqa bias deep-learning pytorch bias-reduction

rubi.bootstrap.pytorch's Introduction

RUBi : Reducing Unimodal Biases for Visual Question Answering

This is the code for the NeurIPS 2019 article available here: https://arxiv.org/abs/1906.10169.

This paper was written by Rémi Cadene, Corentin Dancette, Hedi Ben Younes, Matthieu Cord and Devi Parikh.

RUBi is a learning strategy to reduce biases in VQA models. It relies on a question-only branch plugged at the end of a VQA model.

Summary

Installation

We don't provide support for python 2. We advise you to install python 3 with Anaconda. Then, you can create an environment.

1. As standalone project

conda create --name rubi python=3.7
source activate rubi
git clone --recursive https://github.com/cdancette/rubi.bootstrap.pytorch.git
cd rubi.bootstrap.pytorch
pip install -r requirements.txt

(1. As a python library)

To install the library

git clone https://github.com/cdancette/rubi.bootstrap.pytorch.git
python setup.py install

Then by importing the rubi python module, you can access datasets and models in a simple way.

from rubi.models.networks.rubi import RUBiNet

Note: This repo is built on top of block.bootstrap.pytorch. We import VQA2, TDIUC, VGenome from this library.

2. Download datasets

Download annotations, images and features for VQA experiments:

bash rubi/datasets/scripts/download_vqa2.sh
bash rubi/datasets/scripts/download_vqacp2.sh

Quick start

The RUBi model

The main model is RUBi.

from rubi.models.networks.rubi import RUBiNet

RUBi takes as input another VQA model, adds a question branch around it. The question predictions are merged with the original predictions. RUBi returns the new predictions that are used to train the VQA model.

For an example base model, you can check the baseline model. The model must return the raw predictions (before softmax) in a dictionnary, with the key logits.

Train a model

The boostrap/run.py file load the options contained in a yaml file, create the corresponding experiment directory and start the training procedure. For instance, you can train our best model on VQA2 by running:

python -m bootstrap.run -o rubi/options/vqacp2/rubi.yaml

Then, several files are going to be created in logs/vqa2/rubi:

  • options.yaml (copy of options)
  • logs.txt (history of print)
  • logs.json (batchs and epochs statistics)
  • view.html (learning curves)
  • ckpt_last_engine.pth.tar (checkpoints of last epoch)
  • ckpt_last_model.pth.tar
  • ckpt_last_optimizer.pth.tar
  • ckpt_best_eval_epoch.accuracy_top1_engine.pth.tar (checkpoints of best epoch)
  • ckpt_best_eval_epoch.accuracy_top1_model.pth.tar
  • ckpt_best_eval_epoch.accuracy_top1_optimizer.pth.tar

Many options are available in the options directory.

Evaluate a model

There is no testing set on VQA-CP v2, our main dataset. The evaluation is done on the validation set.

For a model trained on VQA v2, you can evaluate your model on the testing set. In this example, boostrap/run.py load the options from your experiment directory, resume the best checkpoint on the validation set and start an evaluation on the testing set instead of the validation set while skipping the training set (train_split is empty). Thanks to --misc.logs_name, the logs will be written in the new logs_predicate.txt and logs_predicate.json files, instead of being appended to the logs.txt and logs.json files.

python -m bootstrap.run \
-o logs/vqa2/rubi/baseline.yaml \
--exp.resume best_accuracy_top1 \
--dataset.train_split \
--dataset.eval_split test \
--misc.logs_name test

Reproduce results

VQA-CP v2 dataset

Use this simple setup to reproduce our results on the valset of VQA-CP v2.

Baseline:

python -m bootstrap.run \
-o rubi/options/vqacp2/baseline.yaml \
--exp.dir logs/vqacp2/baseline

RUBi :

python -m bootstrap.run \
-o rubi/options/vqacp2/rubi.yaml \
--exp.dir logs/vqacp2/rubi

Compare experiments on valset

You can compare experiments by displaying their best metrics on the valset.

python -m rubi.compare_vqacp2_rubi -d logs/vqacp2/rubi logs/vqacp2/baseline

VQA v2 dataset

Baseline:

python -m bootstrap.run \
-o rubi/options/vqa2/baseline.yaml \
--exp.dir logs/vqa2/baseline

RUBi :

python -m bootstrap.run \
-o rubi/options/vqa2/rubi.yaml \
--exp.dir logs/vqa2/rubi

You can compare experiments by displaying their best metrics on the valset.

python -m rubi.compare_vqa2_rubi_val -d logs/vqa2/rubi logs/vqa2/baseline

Evaluation on test set

python -m bootstrap.run \
-o logs/vqa2/rubi/options.yaml \
--exp.resume best_eval_epoch.accuracy_top1 \
--dataset.train_split '' \
--dataset.eval_split test \
--misc.logs_name test

Weights of best model

The weights for the model trained on VQA-CP v2 can be downloaded here : http://webia.lip6.fr/~cadene/rubi/ckpt_last_model.pth.tar

To use it :

  • Run this command once to create the experiment folder. Cancel it when the training starts
python -m bootstrap.run \
-o rubi/options/vqacp2/rubi.yaml \
--exp.dir logs/vqacp2/rubi
  • Move the downloaded file to the experiment folder, and use the flag --exp.resume last to use this checkpoint :
python -m bootstrap.run \
-o logs/vqacp2/rubi/options.yaml \
--exp.resume last

Useful commands

Use tensorboard instead of plotly

Instead of creating a view.html file, a tensorboard file will be created:

python -m bootstrap.run -o rubi/options/vqacp2/rubi.yaml \
--view.name tensorboard
tensorboard --logdir=logs/vqa2

You can use plotly and tensorboard at the same time by updating the yaml file like this one.

Use a specific GPU

For a specific experiment:

CUDA_VISIBLE_DEVICES=0 python -m boostrap.run -o rubi/options/vqacp2/rubi.yaml

For the current terminal session:

export CUDA_VISIBLE_DEVICES=0

Overwrite an option

The boostrap.pytorch framework makes it easy to overwrite a hyperparameter. In this example, we run an experiment with a non-default learning rate. Thus, I also overwrite the experiment directory path:

python -m bootstrap.run -o rubi/options/vqacp2/rubi.yaml \
--optimizer.lr 0.0003 \
--exp.dir logs/vqacp2/rubi_lr,0.0003

Resume training

If a problem occurs, it is easy to resume the last epoch by specifying the options file from the experiment directory while overwritting the exp.resume option (default is None):

python -m bootstrap.run -o logs/vqacp2/rubi/options.yaml \
--exp.resume last

Cite

@article{cadene2019rubi,
  title={RUBi: Reducing Unimodal Biases for Visual Question Answering},
  author={Cadene, Remi and Dancette, Corentin and Cord, Matthieu and Parikh, Devi and others},
  journal={Advances in Neural Information Processing Systems},
  volume={32},
  pages={841--852},
  year={2019}
}

Authors

This code was made available by Corentin Dancette and Rémi Cadene

Acknowledgment

Special thanks to the authors of VQA2, TDIUC, VisualGenome and VQACP2, the datasets used in this research project.

rubi.bootstrap.pytorch's People

Contributors

cdancette avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

rubi.bootstrap.pytorch's Issues

ModuleNotFoundError: block.external

Traceback (most recent call last):
File "/home/deer/anaconda3/envs/rubi/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/home/deer/anaconda3/envs/rubi/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/deer/anaconda3/envs/rubi/lib/python3.7/site-packages/block/models/metrics/compute_oe_accuracy.py", line 8, in
from block.external.VQA.PythonHelperTools.vqaTools.vqa import VQA
ModuleNotFoundError: No module named 'block.external

I have install the module block.bootstrap.pytorch in the requirements.txt, did the block have been updated?

Semantic tags corresponding to features

I want to know the semantic tags corresponding to the detection feature.But only the index of the category is in the file.Can you provide the corresponding files of semantic tags and indexes?
THANKS

logs_rubi_val_oe.json not getting generated

When I run rubi, the following files are getting generated. No logs_rubi_val_oe.json is getting generated. Is it the rubi accuracy that is present in logs_val_oe.json? The numbers seem to be tallying with that of rubi as reported in the paper. Attaching the screenshot below.

image

package requirement 'block.bootstrap.pytorch' is not satisfied

Thank you for sharing. I'm sorry that I'm new to VQA.
After the "pip install requirements.txt',Pycharm suggests"package requirement 'block.bootstrap.pytorch' is not satisfied", I check the pip list ,the block.bootstrap.pytorch has been installed and the version is 0.1.6, I dont know how to deal with this error, could you give some advice for me?
thanks a lot .I'm looking for your reply!

huge datasets download problem.

Is this necessary to download both datasets by using these scripts?

bash rubi/datasets/scripts/download_vqa2.sh
bash rubi/datasets/scripts/download_vqacp2.sh

or we can use only of them from both.

Unable to run the Compare(Evaluation) script.

Hi, I have trained the baseline and Rubi model in the VQA-CP V2 dataset. And when I wanted to run the python -m rubi.compare_vqa2_rubi_val -d logs/vqa2/rubi logs/vqa2/baseline ,I got the Error:

FileNotFoundError: [Errno 2] No such file or directory: 'logs/vqacp2/rubi/logs_val_oe.json'

And then I checked the log dir of the Rubi and the baseline net, I couldn't find the JSON log file for 'open-ended' evaluation, and the log.txt was like:

[W 2020-02-05 16:08:34] ...tstrap/views/plotly.py.76: Json log file 'logs_rubi_val_oe' not found in 'logs/vqacp2/rubi/logs_rubi_val_oe.json'
[I 2020-02-05 16:08:34] ...trap/engines/engine.py.252: Evaluating model on valset for epoch 0
[W 2020-02-05 16:08:34] ...tstrap/views/plotly.py.76: Json log file 'logs_train_oe' not found in 'logs/vqacp2/rubi/logs_train_oe.json'
[W 2020-02-05 16:08:34] ...tstrap/views/plotly.py.76: Json log file 'logs_q_train_oe' not found in 'logs/vqacp2/rubi/logs_q_train_oe.json'
[W 2020-02-05 16:08:34] ...tstrap/views/plotly.py.76: Json log file 'logs_rubi_train_oe' not found in 'logs/vqacp2/rubi/logs_rubi_train_oe.json'
[W 2020-02-05 16:08:34] ...tstrap/views/plotly.py.76: Json log file 'logs_q_val_oe' not found in 'logs/vqacp2/rubi/logs_q_val_oe.json'
[W 2020-02-05 16:08:34] ...tstrap/views/plotly.py.76: Json log file 'logs_val_oe' not found in 'logs/vqacp2/rubi/logs_val_oe.json'

I would like to know how to generate these log files for evaluating the 'open-ended' accuracy.
Thank you very much.

Could you provide pre-trained weights for baseline architecture?

Would it be possible to provide the checkpoint for baseline architecture as well?

I got very low accuracy (only 21.74) with baseline.yaml:

[S 2019-08-22 13:44:22] ...trap/engines/engine.py.120: eval_epoch.epoch: 11
[S 2019-08-22 13:44:22] ...trap/engines/engine.py.120: eval_epoch.loss: 4.28
[S 2019-08-22 13:44:22] ...trap/engines/engine.py.120: eval_epoch.accuracy_top1: 21.74
[S 2019-08-22 13:44:22] ...trap/engines/engine.py.120: eval_epoch.accuracy_top5: 70.43

which is very puzzling.

Object Labels

I have downloaded the object features as specified. I need the object labels too for my work. Can you please point me to any such source

Thanks.

Downloading features takes very long time

Hi,

wget http://data.lip6.fr/cadene/block/coco/extract_rcnn/2018-04-27_bottom-up-attention_fixed_36.tar shows 2 days estimated time for download even though I have fairly high internet speed. Any chance you have the same file on a faster server?

how to extract image features

Could you please share the code to extract image features "2018-04-27_bottom-up-attention_fixed_36" or the pre-trained RCNN?

A question about your paper

Hello, I have a question about your model.

Let's see the up image of Figure 3 (b):
without the question-only model, the probability is [0.8, 0.1, 0.1]. Suppose the input softmax function is [2.2, 0.1, 0.1], since softmax([2.2, 0.1, 0.1]) is [0.8, 0.1, 0.1].
and with the help of the question-only model :
[2.2, 0.1, .0.1]*[0.8, 0.4, 0.4] = [1.76, 0.04, 0.04]
and the softmax([1.76, 0.04, 0.04])=[0.7363, 0.1318, 0.1318]
Not in line with your ideas. Can you explain why?

Unable to reproduce the accuracy

Hi, I am getting low accuracy on VQACP2 val set.

Here is the log:

eval_epoch.epoch: 21
[S 2019-08-22 01:47:37] ...trap/engines/engine.py.120: eval_epoch.loss: 9.32
[S 2019-08-22 01:47:37] ...trap/engines/engine.py.120: eval_epoch.loss_mm_q: 4.51
[S 2019-08-22 01:47:37] ...trap/engines/engine.py.120: eval_epoch.loss_q: 4.81
[S 2019-08-22 01:47:37] ...trap/engines/engine.py.120: eval_epoch.accuracy_top1: 36.54
[S 2019-08-22 01:47:37] ...trap/engines/engine.py.120: eval_epoch.accuracy_top5: 73.24
[S 2019-08-22 01:47:37] ...trap/engines/engine.py.120: eval_epoch.accuracy_rubi_top1: 22.48
[S 2019-08-22 01:47:37] ...trap/engines/engine.py.120: eval_epoch.accuracy_rubi_top5: 73.94
[S 2019-08-22 01:47:37] ...trap/engines/engine.py.120: eval_epoch.accuracy_q_top1: 6.13
[S 2019-08-22 01:47:37] ...trap/engines/engine.py.120: eval_epoch.accuracy_q_top5: 47.23

What would be a good way to debug it? Maybe I should compare per type accuracies against the pre-trained model?

The baseline model isn't training well either:

[S 2019-08-22 13:44:22] ...trap/engines/engine.py.120: eval_epoch.epoch: 11
[S 2019-08-22 13:44:22] ...trap/engines/engine.py.120: eval_epoch.loss: 4.28
[S 2019-08-22 13:44:22] ...trap/engines/engine.py.120: eval_epoch.accuracy_top1: 21.74
[S 2019-08-22 13:44:22] ...trap/engines/engine.py.120: eval_epoch.accuracy_top5: 70.43

No such file or directory

hello
When I run python -m bootstrap.run -o rubi/options/vqacp2/rubi.yaml
there is a error
image
I have downloaded extract_rcnn
want to know if the data you provide is complete.
THANKS

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.