Code Monkey home page Code Monkey logo

primerl / vqa2.0-recent-approachs-2018.pytorch Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kaihuatang/vqa2.0-recent-approachs-2018.pytorch

0.0 0.0 0.0 19.39 MB

A pytroch reimplementation of "Bilinear Attention Network", "Intra- and Inter-modality Attention", "Learning Conditioned Graph Structures", "Learning to count object", "Bottom-up top-down" for Visual Question Answering 2.0

License: GNU General Public License v3.0

Shell 1.04% Python 98.96%

vqa2.0-recent-approachs-2018.pytorch's Introduction

Several Recent Approaches (2018) on VQA v2

The project is based on Cyanogenoid/vqa-counting. Most of the current VQA2.0 projects are based on https://github.com/hengyuan-hu/bottom-up-attention-vqa, while I personally prefer the Cyanogenoid's framework, because it's very clean and clear. So I reimplement several recent approaches including :

One of the benefit of our framework is that you can easily add counting module into your own model, which is proved to be effictive in imporving counting questions without harm the performance of your own model.

Dependencies

  • Python 3.6
    • torch > 0.4
    • torchvision 0.2
    • h5py 2.7
    • tqdm 4.19

Prepare dataset (FollowCyanogenoid/vqa-counting)

  • In the data directory, execute ./download.sh to download VQA v2.
    • For experimenting, using 36 fixed proposals is faster, at the expense of a bit of accuracy. Uncomment the relevant lines in download.sh and change the paths in config.py accordingly. Don't forget to set output_size in there to 36 to actually get the speed-up.
  • Prepare the data by running
python preprocess-images.py
python preprocess-vocab.py

This creates an h5py database (95 GiB) containing the object proposal features and a vocabulary for questions and answers at the locations specified in config.py.

How to Train

All the models are named as XXX_model.py, and most of the parameters is under config.py. To change the model, simply change model_type in config.py. Then train your model with:

python train.py [optional-name]
  • To evaluate accuracy (VQA accuracy and balanced pair accuracy) in various categories, you can run
python eval-acc.py <path to .pth log> [<more paths to .pth logs> ...]

Support training whole trainval split and generate result.json file for you to upload to the vqa2.0 online evaluation server

  • First, I merge the question and annotation json for train and validation splits. You can download trainval_annotation.json and trainval_question.json from the links, and put them into ./data/ directory
  • To train your model using the entire train & val sets, simply type the --trainval option during your training
python train.py --trainval
  • To generate result.json file for you to upload to the vqa2.0 online evaluation server, you need to resume from the previous model trained from trainval split and select test. The generated result.json will be put into config.result_json_path
python train.py --test --resume=./logs/YOUR_MODEL.pth
  • One More Thing: note that most of the methods require different learning rates when they train through the entire train&val splits. Usually, it's small than the learning rate that used to train on single train split.

Model Details

Note that I didn't implement tfidf embedding of BAN model (though the current model has competitive/almost the same performance even without tfidf), only Glove Embedding is provided. About Intra- and Inter-modality Attention, Although I implemented all the details provided by the paper, it still seems not as good as the paper reported, even after I discussed with auther and made some modifications.

To Train Counting Model

Set following parameters in config.py:

model_type = 'counting'

To Train Bottom-up Top-down

model_type = 'baseline' 

To Train Bilinear attention network

model_type = 'ban' 

Note that BAN is very Memory Comsuming, so please ensure you got enough GPUs and run main.py with CUDA_VISIBLE_DEVICES=0,1,2,3

To Train Intra- and Inter-modality Attention

model_type = 'inter_intra' 

You may need to change the learning rate decay strategy as well from gradual_warmup_steps and lr_decay_epochs in config.py

To Train Learning Conditioned Graph Structures

model_type = 'graph' 

Though this method seem less competitive.

Looking for previous methods to compare in your experiments

Please refer to my CVPR 2019 oral paper:

@inproceedings{tang2018learning,
  title={Learning to Compose Dynamic Tree Structures for Visual Contexts},
  author={Tang, Kaihua and Zhang, Hanwang and Wu, Baoyuan and Luo, Wenhan and Liu, Wei},
  booktitle= "Conference on Computer Vision and Pattern Recognition",
  year={2019}
}

vqa2.0-recent-approachs-2018.pytorch's People

Contributors

kaihuatang avatar theshadow29 avatar

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.