zai-org/CogView

★ 1,799⑂ 175

Text-to-Image generation. The repo for NeurIPS 2021 paper "CogView: Mastering Text-to-Image Generation via Transformers".

About zai-org/CogView

zai-org/CogView is an open-source project on GitHub, mainly written in Python. Text-to-Image generation. The repo for NeurIPS 2021 paper "CogView: Mastering Text-to-Image Generation via Transformers". It currently holds 1,799 stars and 175 forks with 0 open issues, and was last pushed on an unknown date (repository created unknown).

Project Overview

AI Homed tracks it on the AI Image Projects board and on the AI AI Image Projects list.

GitHub Repository Details

Repository zai-org/CogView · default branch - · size 0 KB · watchers 0 · source: GitHub REST API and repository README

README

Generate vivid Images for Any (Chinese) text

teaser

News! The paper of ImageReward is accepted by NeurIPS 2023!

News! The codes of ImageReward (paper link) have been released at https://github.com/THUDM/ImageReward! ImageReward is the first general-purpose text-to-image human preference RM.

News! The codes of CogView2 (paper link) have been released at https://github.com/THUDM/CogView2!

News! The demo for a better and faster CogView2 (formal version, March 2022) is available! The lastest model also supports English input, but to translate them into Chinese often could be better.

News! The demo for a better and faster CogView2 (new version) is available!

News! The paper of CogView is accepted by NeurIPS 2021!

CogView is a pretrained (4B-param) transformer for text-to-image generation in general domain.

@article{ding2021cogview,
  title={CogView: Mastering Text-to-Image Generation via Transformers},
  author={Ding, Ming and Yang, Zhuoyi and Hong, Wenyi and Zheng, Wendi and Zhou, Chang and Yin, Da and Lin, Junyang and Zou, Xu and Shao, Zhou and Yang, Hongxia and Tang, Jie},
  journal={arXiv preprint arXiv:2105.13290},
  year={2021}

Getting Started

Setup

    docker pull cogview/cuda111_torch181_deepspeed040
    ./env/start_docker.sh && docker exec -it bg-cogview bash
    
    cd /root/cogview # in the container
    

Download

0. Download the image tokenizer vqvae_hard_biggerset_011.pt from BAAI website or Tsinghua Cloud. Place the file under pretrained/vqvae.
wget 'https://cloud.tsinghua.edu.cn/f/71607a5dca69417baa8c/?dl=1' -O pretrained/vqvae/vqvae_hard_biggerset_011.pt
1. Download models from Project Wudao-Wenhui. | FileName | Discription | | ---- | ---- | | cogview-base.tar | The pretrained text-to-image model. | | cogview-caption.tar | Finetuned image-to-text model, also used for reranking. | | cogview-sr.tar | Finetuned super-resolution model. (warning: it runs slow.) |

Uncompress them into pretrained/cogview/. The following command should be modified based on the model name.

    tar -xvf cogview-{base, sr, caption}.tar -C pretrained/cogview/
    
2. (Only for training tutorial, skip it for inference.) Download a small "bird-and-animal" example dataset from our link at Tsinghua Cloud.
wget https://cloud.tsinghua.edu.cn/f/1e4963ec8ac84941ba68/?dl=1 -O data/bird_animal.bin

Run CogView! (Model Inference)

We encapsulate the generation functions into scripts. See generate_samples.py and arguments.py for details.

Text-to-Image Generation

Write text queries (one per line) into input.txt and run:
./scripts/text2image.sh --debug
The results will in a new folder samples_text2image/.

Arguments useful in inference are mainly:

Super-resolution

Run the following script and input text\t{image_path}, where {image_path} means the path of a previously generated image.
./scripts/super_resolution.sh
Note: It is only effective for generated images from our Image Tokenizer (due to the token distribution).

Image-to-Text

The input is "one image path per line", and will print the results to stdout.
./scripts/image2text.sh
Note: Not optimized for this task, so it might not very competitive (but okay). We will consider to release a version funetuning for a longer period on this task in the future. (TODO)

Post-selection

This application only takes file inputs, where each line is {text}\t{image_path1}\t{image_path2}\t{image_path3}.... The output is {output_path}/scores.txt, a line of a list of scores, following a line from inputs.
./scripts/post_selection.sh

Note: In the released codes, for simplicity, we did not expose the raw API , which supports some advanced generation modes, e.g. text and part of image.

Training

Here we use a subset of our dataset from bird-and-animal for tutorial. The binary dataset is generated by our cogdata toolkit. Please wait for a formal release with tutorials of cogdata (although it is available now).

Single Node

After downloading the dataset, directly run
./scripts/pretrain_single_node.sh

Multiple Nodes

If you want to train the models on multiple servers inter-connected by infiniband without a shared file system (you may need pdsh to accelerate this process): 1. On each server, use git clone to download this repo, and make sure the data (LMDB format) are moved into the data subfolder. 2. On each server, echo "ip1 ip2 " > ./docker/ip_list.txt, and then start the docker by ./env/start_docker.sh. 3. Get into the docker on the first node container via docker exec -it bg-cogview bash. 4. Get into /root/cogview and run ./scripts/pretrain_multiple_nodes.sh. You may need to change the config (especially OPTIONS_NCCL) in the shell script.

See the arguments.py for advanced functions for training. TODO

Gallery

more_samples

GitHub Stars & Activity

1,799Stars
175Forks
0Open issues
PythonLanguage

GitHub Popularity

GitHub stars1,799
Forks175
Open issues0
Primary languagePython
License-
Stars gained today0
Created-
Last pushed-

Trending History

Trending statusnot on today's boards

Related AI Projects

1

ultralytics / ultralytics

Python★ 61,829⑂ 11,787
2

ultralytics / yolov5

Python★ 58,057⑂ 17,469
3

roboflow / supervision

Python★ 50,960⑂ 4,848
4

lucidrains / vit-pytorch

Python★ 25,514⑂ 3,495
5

junyanz / pytorch-CycleGAN-and-pix2pix

Python★ 25,244⑂ 6,567
6

graphdeco-inria / gaussian-splatting

Python★ 23,930⑂ 3,434
7

pytorch / vision

Python★ 17,921⑂ 7,265
8

cvat-ai / cvat

Python★ 16,758⑂ 3,871

More AI Rankings