• Stars
    star
    105
  • Rank 328,196 (Top 7 %)
  • Language
    Python
  • License
    MIT License
  • Created about 3 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

L-Verse: Bidirectional Generation Between Image and Text

L-Verse: Bidirectional Generation Between Image and Text

Taehoon Kim, Gwangmo Song, Sihaeng Lee, Sangyun Kim, Yewon Seo, Soonyoung Lee, Seung Hwan Kim, Honglak Lee, Kyunghoon Bae [Paper]

LG AI Research

CVPR 2022 (Oral)

Abstract

Far beyond learning long-range interactions of natural language, transformers are becoming the de-facto standard for many vision tasks with their power and scalability. Especially with cross-modal tasks between image and text, vector quantized variational autoencoders (VQ-VAEs) are widely used to make a raw RGB image into a sequence of feature vectors. To better leverage the correlation between image and text, we propose L-Verse, a novel architecture consisting of feature-augmented variational autoencoder (AugVAE) and bidirectional auto-regressive transformer (BiART) for text-to-image and image-to-text generation. Our AugVAE shows the state-of-the-art reconstruction performance on ImageNet1K validation set, along with the robustness to unseen images in the wild. Unlike other models, BiART can distinguish between image (or text) as a conditional reference and a generation target. L-Verse can be directly used for image-to-text or text-to-image generation tasks without any finetuning or extra object detection framework. In quantitative and qualitative experiments, L-Verse shows impressive results against previous methods in both image-to-text and text-to-image generation on MS-COCO Captions. We furthermore assess the scalability of L-Verse architecture on Conceptual Captions and present the initial results of bidirectional vision-language representation learning on general domain.

Preparation

Requirements

pip install -r requirements.txt

Dataset

Place any image dataset with ImageNet-style directory structure (directory with at least 1 sub-directory) to fit the dataset into pytorch ImageFolder. Alternatively, you can also use ImageDataset2 which doesn't require any sub-directroy. In this case, replace ImageDataset with ImageDataset2. Our code also supports WebDataset.

Pretrained weights

AugVAE

Training

For faster training, our training code supports multi-gpu. To enable multi-gpu training, add " --gpus " flag with number of gpus in your machine (default 1).

For training, provide config file and training dataset. If you are training AugVAE-SL, you must also provide pretrained AugVAE-ML weight Please refer to example config files in configs.

python train_vae.py --configs [config_file] --train_dir [path_to_train_data] --val_dir [path_to_val_data]

You can also test functionality with randomly generated fake data.

python train_vae.py --fake_data --configs [config_file] 

Evaluation

For faster evaluation, our evaluation code supports multi-gpu. To enable multi-gpu evaluation, add " --gpus " flag with number of gpus in your machine (default 1).

For evaluation, provide config file, pretrained AugVAE weight, and test dataset Please refer to example config files in configs.

python eval_vae.py --configs [config_file] --ckpt_path [weight_file] --test_dir [path_to_test_data] 

You can also test functionality with randomly generated fake data.

python eval_vae.py --fake_data --configs [config_file] --ckpt_path [weight_file]

BiART

Among many open-sourced Transformer (GPT) repositories, we used Andrej Karpathy's minGPT with extra embedding layer for Segment Embedding.

Here's an example modification code to apply Segment Embedding to minGPT.

class GPT(nn.Module):
    def __init__(self, vocab_size, block_size, n_embd, ... )):    
        ...
        self.tok_emb = nn.Embedding(vocab_size, n_embd)
        self.seg_emb = nn.Embedding(2, n_embd)
        self.pos_emb = nn.Parameter(torch.zeros(1, block_size, n_embd))

    def forward(self, idx, seg, ...:
        token_embeddings = self.tok_emb(idx) # each index maps to a (learnable) vector
        segment_embeddings = self.seg_emb(seg)
        ...
        t = token_embeddings.shape[1]
        assert t <= self.block_size, "Cannot forward, model block size is exhausted."
        position_embeddings = self.pos_emb[:, :t, :] # each position maps to a (learnable) vector
        x = self.drop(token_embeddings + segment_embeddings + position_embeddings)
        ...

There's also Pytorch Lightning version which fits well with our AugVAE implementation.

License

This project is distributed under MIT license.

Copyright (c) 2022-present LG AI Research.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

How to cite

@InProceedings{Kim_2022_CVPR,
    author    = {Kim, Taehoon and Song, Gwangmo and Lee, Sihaeng and Kim, Sangyun and Seo, Yewon and Lee, Soonyoung and Kim, Seung Hwan and Lee, Honglak and Bae, Kyunghoon},
    title     = {L-Verse: Bidirectional Generation Between Image and Text},
    booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
    month     = {June},
    year      = {2022},
    pages     = {16526-16536}
}

More Repositories

1

dalle-lightning

Refactoring dalle-pytorch and taming-transformers for TPU VM
Python
60
star
2

S3FD_ATSS_SAPD

Applying Adaptive Training Sample Selection and Soft Anchor Point Detection to S3FD
Python
39
star
3

BITTERS

Large-Scale Bidirectional Training for Zero-Shot Image Captioning
Python
18
star
4

Seq2CNN

Word Embedding Annealing Using Sequence-to-sequence Model
Python
16
star
5

image-text-recognition

Region-based Convolutional Neural Networks for Text Label Detection in Patent Images
Python
9
star
6

CNN-text-classification

multi-class text classification using text-CNN and Konlpy
Python
6
star
7

PPAP

Latent-space-level Image Anonymization with Adversarial Protector Networks
Python
4
star
8

turtle_graphics

Some Practice codes for turtle graphics
Python
3
star
9

Natural_Language_Processing

2019 Sogang University Natural Language Processing Projects
Python
3
star
10

car_accident_casualties

2012-2016 casualties of car accidents happened in South Korea
R
2
star
11

pintos-project

Pintos project during 2016 fall semester
C
2
star
12

python-copy-checker

simple copy checker for python
Python
2
star
13

PPSGAN

Privacy Preserving Semi Generative Adversarial Networks
Python
2
star
14

aws_autoaugment

Improving Auto-Augment via Augmentation-Wise Weight Sharing
Python
1
star
15

DP_AAE

Adversarial Autoencoder for privacy-preserved data generation
Python
1
star
16

sogang_university_beamer

LaTeX beamer presentation template
TeX
1
star
17

BasicCNN_design_classification

Python
1
star
18

finance_analysis

Financial analysis python codes
Python
1
star
19

EEE6478_Computer_Vision

EEE6478 Computer Vision Assignments
Python
1
star
20

ML_Dockerfiles

Repo for different ML dockerfiles
Roff
1
star