{"id":14256848,"url":"https://github.com/MIMICLab/L-Verse","last_synced_at":"2025-08-12T20:33:18.548Z","repository":{"id":41399500,"uuid":"430911702","full_name":"MIMICLab/L-Verse","owner":"MIMICLab","description":"L-Verse: Bidirectional Generation Between Image and Text","archived":false,"fork":false,"pushed_at":"2022-11-15T05:51:27.000Z","size":1919,"stargazers_count":108,"open_issues_count":1,"forks_count":6,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-08-09T02:49:20.868Z","etag":null,"topics":["deep-learning","image-captioning","image-to-text","l-verse","pytorch","pytorch-lightning","text-to-image","transformer","vq-vae"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MIMICLab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-11-23T00:45:14.000Z","updated_at":"2024-08-07T08:43:43.000Z","dependencies_parsed_at":"2022-09-03T11:32:22.292Z","dependency_job_id":null,"html_url":"https://github.com/MIMICLab/L-Verse","commit_stats":null,"previous_names":["lgai-research/l-verse","tgisaturday/l-verse","mimiclab/l-verse"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MIMICLab%2FL-Verse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MIMICLab%2FL-Verse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MIMICLab%2FL-Verse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MIMICLab%2FL-Verse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MIMICLab","download_url":"https://codeload.github.com/MIMICLab/L-Verse/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":216434129,"owners_count":16025236,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deep-learning","image-captioning","image-to-text","l-verse","pytorch","pytorch-lightning","text-to-image","transformer","vq-vae"],"created_at":"2024-08-22T07:01:20.134Z","updated_at":"2024-08-22T07:02:55.071Z","avatar_url":"https://github.com/MIMICLab.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# L-Verse: Bidirectional Generation Between Image and Text\n\n**Taehoon Kim, Gwangmo Song, Sihaeng Lee, Sangyun Kim, Yewon Seo, Soonyoung Lee, Seung Hwan Kim, Honglak Lee, Kyunghoon Bae [[Paper]](https://arxiv.org/abs/2111.11133.pdf)** \n\n**LG AI Research**\n\n**CVPR 2022 (Oral)** \n\n\u003cimg src=assets/lverse.png width=1280\u003e\n\n\n## Abstract\nFar 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. \n\n\n\n## Preparation\n\n### Requirements\n\n```\npip install -r requirements.txt\n```\n\n### Dataset\n\n Place any image dataset with ImageNet-style directory structure (directory with at least 1 sub-directory) to fit the dataset into pytorch ImageFolder.\n Alternatively, you can also use [ImageDataset2](https://github.com/lgai-research/L-Verse/blob/973ea99ab3053158fb4b92757d52d72a3b70fad9/latent_verse/loader.py#L201) which doesn't require any sub-directroy. In this case, replace [ImageDataset](https://github.com/lgai-research/L-Verse/blob/973ea99ab3053158fb4b92757d52d72a3b70fad9/latent_verse/loader.py#L126) with ImageDataset2. Our code also supports [WebDataset](https://github.com/webdataset/webdataset). \n\n\n### Pretrained weights \n\n- We provide the AugVAE pretrained weights on ImageNet dataset. \n\n    AugVAE-ML: [Google Drive](https://drive.google.com/file/d/1muj3Z-gEPwFtuwKLqZXAGZCVLa4eBKhk/view?usp=sharing)\n\n    AugVAE-SL: [Google Drive](https://drive.google.com/file/d/1N9NOL5nOffBYCwYT7yTNa4X0zRJreabp/view?usp=sharing)\n\n## AugVAE\n### Training\nFor faster training, our training code supports multi-gpu. \nTo enable multi-gpu training, add \" --gpus \" flag with number of gpus in your machine (default 1).\n\n\nFor training, provide config file and training dataset.\nIf you are training AugVAE-SL, you must also provide pretrained AugVAE-ML weight\nPlease refer to example config files in configs. \n\n\n```\npython train_vae.py --configs [config_file] --train_dir [path_to_train_data] --val_dir [path_to_val_data]\n```\n\nYou can also test functionality with randomly generated fake data.\n\n```\npython train_vae.py --fake_data --configs [config_file] \n```\n\n### Evaluation \nFor faster evaluation, our evaluation code supports multi-gpu. \nTo enable multi-gpu evaluation, add \" --gpus \" flag with number of gpus in your machine (default 1).\n\nFor evaluation, provide config file, pretrained AugVAE weight, and test dataset\nPlease refer to example config files in configs. \n\n\n```\npython eval_vae.py --configs [config_file] --ckpt_path [weight_file] --test_dir [path_to_test_data] \n```\n\nYou can also test functionality with randomly generated fake data.\n```\npython eval_vae.py --fake_data --configs [config_file] --ckpt_path [weight_file]\n```\n\n## BiART\nAmong many open-sourced Transformer (GPT) repositories, we used Andrej Karpathy's [minGPT](https://github.com/karpathy/minGPT) with extra embedding layer for Segment Embedding. \n\nHere's an example modification code to apply Segment Embedding to [minGPT](https://github.com/karpathy/minGPT).\n\n```python\nclass GPT(nn.Module):\n    def __init__(self, vocab_size, block_size, n_embd, ... )):    \n        ...\n        self.tok_emb = nn.Embedding(vocab_size, n_embd)\n        self.seg_emb = nn.Embedding(2, n_embd)\n        self.pos_emb = nn.Parameter(torch.zeros(1, block_size, n_embd))\n\n    def forward(self, idx, seg, ...:\n        token_embeddings = self.tok_emb(idx) # each index maps to a (learnable) vector\n        segment_embeddings = self.seg_emb(seg)\n        ...\n        t = token_embeddings.shape[1]\n        assert t \u003c= self.block_size, \"Cannot forward, model block size is exhausted.\"\n        position_embeddings = self.pos_emb[:, :t, :] # each position maps to a (learnable) vector\n        x = self.drop(token_embeddings + segment_embeddings + position_embeddings)\n        ...\n```\n\nThere's also [Pytorch Lightning version](https://github.com/williamFalcon/minGPT) which fits well with our AugVAE implementation.\n\n## License\n\nThis project is distributed under MIT license.\n\n```\nCopyright (c) 2022-present LG AI Research.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n```\n\n## How to cite\n```\n@InProceedings{Kim_2022_CVPR,\n    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},\n    title     = {L-Verse: Bidirectional Generation Between Image and Text},\n    booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},\n    month     = {June},\n    year      = {2022},\n    pages     = {16526-16536}\n}\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMIMICLab%2FL-Verse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMIMICLab%2FL-Verse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMIMICLab%2FL-Verse/lists"}