{"id":17871316,"url":"https://github.com/da03/markup2im","last_synced_at":"2025-03-21T17:31:26.233Z","repository":{"id":69334714,"uuid":"538640651","full_name":"da03/markup2im","owner":"da03","description":"Diffusion-based markup-to-image generation","archived":false,"fork":false,"pushed_at":"2023-03-19T00:10:58.000Z","size":35629,"stargazers_count":78,"open_issues_count":2,"forks_count":10,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-17T19:11:39.782Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://huggingface.co/spaces/yuntian-deng/latex2im","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/da03.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-19T18:22:59.000Z","updated_at":"2024-08-30T18:19:06.000Z","dependencies_parsed_at":"2024-10-28T11:39:12.133Z","dependency_job_id":null,"html_url":"https://github.com/da03/markup2im","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/da03%2Fmarkup2im","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/da03%2Fmarkup2im/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/da03%2Fmarkup2im/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/da03%2Fmarkup2im/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/da03","download_url":"https://codeload.github.com/da03/markup2im/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244838200,"owners_count":20518803,"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":[],"created_at":"2024-10-28T10:30:17.647Z","updated_at":"2025-03-21T17:31:26.228Z","avatar_url":"https://github.com/da03.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Markup-to-Image Diffusion Models with Scheduled Sampling\n\nWe provide code to reproduce [our paper on markup-to-image generation](https://openreview.net/pdf?id=81VJDmOE2ol). Our code is built on top of HuggingFace [diffusers](https://github.com/huggingface/diffusers) and [transformers](https://github.com/huggingface/transformers).\n\n## Online Demo: [https://huggingface.co/spaces/yuntian-deng/latex2im](https://huggingface.co/spaces/yuntian-deng/latex2im).\n\n## Example Generations\n\nScheduled Sampling            |   Baseline                              |        Ground Truth      |\n:----------------------------:|:---------------------------------------:|:------------------------:|\n![](imgs/math_rendering.gif)  |  ![](imgs/math_rendering_baseline.gif)  | ![](imgs/433d71b530.png) |\n![](imgs/tables_rendering.gif)|  ![](imgs/tables_rendering_baseline.gif)| ![](imgs/42725-full.png) |\n![](imgs/music_rendering.gif) |  ![](imgs/music_rendering_baseline.gif) | ![](imgs/comp.17342.png) |\n![](imgs/molecules_rendering.gif)|  ![](imgs/molecules_rendering_baseline.gif)| ![](imgs/B-1173.png) |\n\n## Prerequisites\n\n* [Pytorch](https://pytorch.org/get-started/locally/)\n\n```\npip install transformers\npip install datasets\npip install accelerate\npip install -qU git+https://github.com/da03/diffusers\n```\n\n## Datasets \u0026 Pretrained Models\n\nAll datasets have been uploaded to [Huggingface datasets](https://huggingface.co/yuntian-deng).\n\n* Math: [data](https://huggingface.co/datasets/yuntian-deng/im2latex-100k) [model](models/math/scheduled_sampling/model_e100_lr0.0001.pt.100)\n* Simple Tables: [data](https://huggingface.co/datasets/yuntian-deng/im2html-100k) [model](models/tables/scheduled_sampling/model_e100_lr0.0001.pt.100)\n* Sheet Music: [data](https://huggingface.co/datasets/yuntian-deng/im2ly-35k-syn) [model](music/math/scheduled_sampling/model_e100_lr0.0001.pt.100)\n* Molecules: [data](https://huggingface.co/datasets/yuntian-deng/im2smiles-20k) [model](models/molecules/scheduled_sampling/model_e100_lr0.0001.pt.100)\n\n## Usage\n\n### Training\n\n#### Math\n\nTo train the diffusion model,\n\n```\npython src/train.py --save_dir models/math\n```\n#### Tables\n\nTo train the diffusion model,\n\n```\npython src/train.py --dataset_name yuntian-deng/im2html-100k --save_dir models/tables \n```\n\n#### Music\n\nIn our paper, we trained on the music dataset with 4 A100 GPUs. You might need to tune `--batch_size` and  `--gradient_accumulation_steps` if you want to use a single GPU to train or if your GPUs have less memory.\n\nWe first run\n\n```\naccelerate config\n```\nto use 4 GPUs on a single machine. Note that we did not use fp16 or DeepSpeed.\n\nNext, we launch multi-GPU training using accelerate:\n\n```\naccelerate launch src/train.py --dataset_name yuntian-deng/im2ly-35k-syn --save_dir models/music\n```\n\n#### Molecules\n\nTo train the diffusion model,\n\n```\npython src/train.py --dataset_name yuntian-deng/im2smiles-20k --save_dir models/molecules\n```\n\n### Generation\n\n#### Math\n\nTo generate,\n\n```\npython scripts/generate.py --model_path models/math/scheduled_sampling/model_e100_lr0.0001.pt.100 --output_dir outputs/math --save_intermediate_every -1\n```\n\n#### Tables\n\nTo generate,\n\n```\npython scripts/generate.py --dataset_name yuntian-deng/im2html-100k --model_path models/tables/scheduled_sampling/model_e100_lr0.0001.pt.100 --output_dir outputs/tables --save_intermediate_every -1\n```\n\n#### Music\n\nTo generate,\n\n```\npython scripts/generate.py --dataset_name yuntian-deng/im2ly-35k-syn --model_path models/music/scheduled_sampling/model_e100_lr0.0001.pt.100 --output_dir outputs/music --save_intermediate_every -1\n```\n\n#### Molecules\n\nTo generate,\n\n```\npython scripts/generate.py --dataset_name yuntian-deng/im2smiles-20k --model_path models/molecules/scheduled_sampling/model_e100_lr0.0001.pt.100 --output_dir outputs/molecules --save_intermediate_every -1\n```\n\n### Visualization\n\n#### Math\n\nTo visualize the generation process, we need to first use the following command to save the intermediate images during generation:\n\n```\npython scripts/generate.py --model_path models/math/scheduled_sampling/model_e100_lr0.0001.pt.100 --output_dir outputs/math/scheduled_sampling_visualization --save_intermediate_every 1 --num_batches 1\n```\n\nNext, we put together a gif image from the generated images:\n\n```\npython scripts/make_gif.py --input_dir outputs/math/scheduled_sampling_visualization/ --output_filename imgs/math_rendering.gif --select_filename 433d71b530.png --show_every 10\n```\n\nWe can similarly visualize results from the baseline.\n\n```\npython scripts/generate.py --model_path models/math/baseline/model_e100_lr0.0001.pt.100 --output_dir outputs/math/baseline_visualization --save_intermediate_every 1 --num_batches 1\n```\n\n```\npython scripts/make_gif.py --input_dir outputs/math/baseline_visualization/ --output_filename imgs/math_rendering_baseline.gif --select_filename 433d71b530.png --show_every 10\n```\n\n#### Tables\n\nTo visualize the generation process, we need to first use the following command to save the intermediate images during generation:\n\n```\npython scripts/generate.py --dataset_name yuntian-deng/im2html-100k --model_path models/tables/scheduled_sampling/model_e100_lr0.0001.pt.100 --output_dir outputs/tables/scheduled_sampling_visualization --save_intermediate_every 1 --num_batches 1\n```\n\nNext, we put together a gif image from the generated images:\n\n```\npython scripts/make_gif.py --input_dir outputs/tables/scheduled_sampling_visualization/ --output_filename imgs/tables_rendering.gif --select_filename 42725-full.png --show_every 10\n```\n\nWe can similarly visualize results from the baseline.\n\n```\npython scripts/generate.py --dataset_name yuntian-deng/im2html-100k --model_path models/tables/baseline/model_e100_lr0.0001.pt.100 --output_dir outputs/tables/baseline_visualization --save_intermediate_every 1 --num_batches 1\n```\n\n```\npython scripts/make_gif.py --input_dir outputs/tables/baseline_visualization/ --output_filename imgs/tables_rendering_baseline.gif --select_filename 42725-full.png --show_every 10\n```\n\n#### Music\n\nTo visualize the generation process, we need to first use the following command to save the intermediate images during generation:\n\n```\npython scripts/generate.py --dataset_name yuntian-deng/im2ly-35k-syn --model_path models/music/scheduled_sampling/model_e100_lr0.0001.pt.100 --output_dir outputs/music/scheduled_sampling_visualization --save_intermediate_every 1 --num_batches 1\n```\n\nNext, we put together a gif image from the generated images:\n\n```\npython scripts/make_gif.py --input_dir outputs/music/scheduled_sampling_visualization/ --output_filename imgs/music_rendering.gif --select_filename comp.17342.png --show_every 10\n```\n\nWe can similarly visualize results from the baseline.\n\n```\npython scripts/generate.py --dataset_name yuntian-deng/im2ly-35k-syn --model_path models/music/baseline/model_e100_lr0.0001.pt.100 --output_dir outputs/music/baseline_visualization --save_intermediate_every 1 --num_batches 1\n```\n\n```\npython scripts/make_gif.py --input_dir outputs/music/baseline_visualization/ --output_filename imgs/music_rendering_baseline.gif --select_filename comp.17342.png --show_every 10\n```\n\n#### Molecules\n\nTo visualize the generation process, we need to first use the following command to save the intermediate images during generation:\n\n```\npython scripts/generate.py --dataset_name yuntian-deng/im2smiles-20k --model_path models/molecules/scheduled_sampling/model_e100_lr0.0001.pt.100 --output_dir outputs/molecules/scheduled_sampling_visualization --save_intermediate_every 1 --num_batches 1\n```\n\nNext, we put together a gif image from the generated images:\n\n```\npython scripts/make_gif.py --input_dir outputs/molecules/scheduled_sampling_visualization/ --output_filename imgs/molecules_rendering.gif --select_filename B-1173.png --show_every 10\n```\n\nWe can similarly visualize results from the baseline.\n\n```\npython scripts/generate.py --dataset_name yuntian-deng/im2smiles-20k --model_path models/molecules/baseline/model_e100_lr0.0001.pt.100 --output_dir outputs/molecules/baseline_visualization --save_intermediate_every 1 --num_batches 1\n```\n\n```\npython scripts/make_gif.py --input_dir outputs/molecules/baseline_visualization/ --output_filename imgs/molecules_rendering_baseline.gif --select_filename B-1173.png --show_every 10\n```\n\n## Citation\n\n```\n@inproceedings{\ndeng2023markuptoimage,\ntitle={Markup-to-Image Diffusion Models with Scheduled Sampling},\nauthor={Yuntian Deng and Noriyuki Kojima and Alexander M Rush},\nbooktitle={The Eleventh International Conference on Learning Representations },\nyear={2023},\nurl={https://openreview.net/forum?id=81VJDmOE2ol}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fda03%2Fmarkup2im","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fda03%2Fmarkup2im","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fda03%2Fmarkup2im/lists"}