{"id":13563640,"url":"https://github.com/THUDM/CogView2","last_synced_at":"2025-04-03T20:31:22.128Z","repository":{"id":37094176,"uuid":"485320771","full_name":"THUDM/CogView2","owner":"THUDM","description":"official code repo for paper \"CogView2: Faster and Better Text-to-Image Generation via Hierarchical Transformers\"","archived":false,"fork":false,"pushed_at":"2022-08-03T17:38:41.000Z","size":152,"stargazers_count":934,"open_issues_count":25,"forks_count":77,"subscribers_count":34,"default_branch":"main","last_synced_at":"2024-08-01T13:29:38.350Z","etag":null,"topics":["pretrained-models","pytorch","text-to-image","transformer"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/THUDM.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":"2022-04-25T10:15:47.000Z","updated_at":"2024-07-26T02:27:45.000Z","dependencies_parsed_at":"2022-07-13T13:30:35.237Z","dependency_job_id":null,"html_url":"https://github.com/THUDM/CogView2","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/THUDM%2FCogView2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/THUDM%2FCogView2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/THUDM%2FCogView2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/THUDM%2FCogView2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/THUDM","download_url":"https://codeload.github.com/THUDM/CogView2/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223030663,"owners_count":17076471,"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":["pretrained-models","pytorch","text-to-image","transformer"],"created_at":"2024-08-01T13:01:21.659Z","updated_at":"2024-11-04T16:31:04.942Z","avatar_url":"https://github.com/THUDM.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003cimg src=\"assets/logo2.png\"/\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n\u003cb\u003eGenerate vivid Images for Chinese / English text\u003c/b\u003e\n\u003c/p\u003e\n\nCogView2 is a hierarchical transformer (6B-9B-9B parameters) for text-to-image generation in general domain. This implementation is based on the [SwissArmyTransformer](https://github.com/THUDM/SwissArmyTransformer) library (v0.2).\n\n* **Read** our paper [CogView2: Faster and Better Text-to-Image Generation via Hierarchical Transformers](https://arxiv.org/abs/2204.14217) on ArXiv for a formal introduction. The *LoPAR* accelarate the generation and *CogLM* enables the model for bidirectional completion.\n* **Run** our pretrained models from text-to-image generation or text-guided completion! Please use A100 GPU.\n* **Cite** our paper if you find our work is helpful~ \n```\n@article{ding2022cogview2,\n  title={CogView2: Faster and Better Text-to-Image Generation via Hierarchical Transformers},\n  author={Ding, Ming and Zheng, Wendi and Hong, Wenyi and Tang, Jie},\n  journal={arXiv preprint arXiv:2204.14217},\n  year={2022}\n}\n```\n\n## Web Demo\n\n- Thank the Huggingface team for integrating CogView2 into [Huggingface Spaces 🤗](https://huggingface.co/spaces) using [Gradio](https://github.com/gradio-app/gradio). Try out the Web Demo: [![Hugging Face Spaces](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue)](https://huggingface.co/spaces/THUDM/CogView2)\n\n- Thank the Replicate team to deploy a web demo! Try at [![Replicate](https://replicate.com/thudm/cogview2/badge)](https://replicate.com/thudm/cogview2) .\n\n## Getting Started\n### Setup\n* Hardware: Linux servers with Nvidia A100s are recommended, but it is also okay to run the pretrained models with smaller `--max-inference-batch-size` or training smaller models on less powerful GPUs.\n* Environment: install dependencies via `pip install -r requirements.txt`. \n* LocalAttention: Make sure you have CUDA installed and compile the local attention kernel.\n```shell\ngit clone https://github.com/Sleepychord/Image-Local-Attention\ncd Image-Local-Attention \u0026\u0026 python setup.py install\n```\nIf you don't install this kernel, you can also run the first stage (20*20 tokens) via `--only-first-stage` for text-to-image generation.\n\n### Download\nOur code will automatically download or detect the models into the path defined by envrionment variable `SAT_HOME`. You can download from [here](https://model.baai.ac.cn/model-detail/100041) and place them (folders named `coglm`/`cogview2-dsr`/`cogview2-itersr`) under `SAT_HOME`. \n\n### Text-to-Image Generation\n```\n./text2image.sh --input-source input.txt\n```\nArguments useful in inference are mainly:\n* `--input-source [path or \"interactive\"]`. The path of the input file, can also be \"interactive\", which will launch a CLI.\n* `--output-path [path]`. The folder containing the results.\n* `--batch-size [int]`. The number of samples will be generated per query.\n* `--max-inference-batch-size [int]`. Maximum batch size per forward. Reduce it if OOM. \n* `--debug`. Only save concatenated images for all generated samples, and name them by input text and date. \n* `--with-id`. When it toggled, you must specify an \"id\" before each input, e.g. `001\\t一个漂亮的女孩`, \\t denoting TAB (**NOT space**). It will generate `batch-size` split images in a folder named \"id\" for each input. Confict with `--debug`.\n* `--device [int]`. Running on which GPU. \n* `--inverse-prompt`. Use the perplexity to generate the original text to sort the generated images.\n* `--only-first-stage`. \n* `--style`. The style of the generated images, choices=['none', 'mainbody', 'photo', 'flat', 'comics', 'oil', 'sketch', 'isometric', 'chinese', 'watercolor']. The default style is `mainbody`, usually an isolated object with white background.\n\nYou'd better specify a environment variable `SAT_HOME` to specify the path to store the downloaded model.\n\nChinese input is usually much better than English input.\n\n### Text-guided Completion\n```\n./text_guided_completion.sh --input-source input_comp.txt\n```\nThe format of input is `text\timage_path\th0\tw0\th1\tw1`, where all the separation are **TAB** (**NOT space**). The image at `image_path` will be center-cropped to `480*480` pixels and mask the square from `(h0,w0)`to `(h1,w1)`. These coordinations are range from 0 to 1. The model will fill the square with object described in `text`. Please use a square much **larger than the desired region**.  \n\u003cimg width=\"741\" alt=\"comp_pipeline\" src=\"https://user-images.githubusercontent.com/9153807/174002452-3670850f-b234-4515-8ac8-2971de26f78a.png\"\u003e\n\n## Gallery\n\n\n![more_samples](https://github.com/THUDM/CogView2/files/8553662/big.1.pdf)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTHUDM%2FCogView2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FTHUDM%2FCogView2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTHUDM%2FCogView2/lists"}