{"id":23399656,"url":"https://github.com/filipbasara0/simple-diffusion","last_synced_at":"2025-10-15T20:23:11.805Z","repository":{"id":154191250,"uuid":"554816384","full_name":"filipbasara0/simple-diffusion","owner":"filipbasara0","description":"A minimal implementation of a denoising diffusion model in PyTorch.","archived":false,"fork":false,"pushed_at":"2024-11-14T08:22:04.000Z","size":34,"stargazers_count":117,"open_issues_count":1,"forks_count":11,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-30T03:03:52.871Z","etag":null,"topics":["attention-mechanism","computer-vision","deep-learning","diffusion","image-generation","pytorch","stable-diffusion","unet"],"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/filipbasara0.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-10-20T12:53:53.000Z","updated_at":"2025-03-09T09:31:17.000Z","dependencies_parsed_at":"2023-12-24T20:05:09.840Z","dependency_job_id":"412aaad0-cf72-4497-bca2-9314bd04b1f2","html_url":"https://github.com/filipbasara0/simple-diffusion","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/filipbasara0%2Fsimple-diffusion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filipbasara0%2Fsimple-diffusion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filipbasara0%2Fsimple-diffusion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filipbasara0%2Fsimple-diffusion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/filipbasara0","download_url":"https://codeload.github.com/filipbasara0/simple-diffusion/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247430869,"owners_count":20937874,"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":["attention-mechanism","computer-vision","deep-learning","diffusion","image-generation","pytorch","stable-diffusion","unet"],"created_at":"2024-12-22T10:15:33.217Z","updated_at":"2025-10-15T20:23:06.771Z","avatar_url":"https://github.com/filipbasara0.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple Denoising Diffusion\n\nA minimal implementation of a denoising diffusion uncoditional image generation model in PyTorch.\nThe idea was to test the performance of a very small model on the Oxford Flowers dataset.\n\nIncludes the DDIM scheduler and the UNet architecture with residual connections and Attention layers.\n\n## Oxford Flowers\n\n![flowers](https://user-images.githubusercontent.com/29043871/197328106-97e825b5-814d-495c-9042-17e9962f9584.jpeg)\n\nSo far, the model was tested on the Oxford Flowers dataset - the results can be seen on the image above.\nImages were generated with 50 DDIM steps.\n\nThe results were surprisingly decent and training unexpectedly smooth, considering the model size.\n\nTraining was done for `40k steps`, with a batch size of `64`. Learning rate was `1e-3` and weight decay was `5e-2`. Training took ~6 hours on GTX 1070Ti.\n\nHidden dims of `[16, 32, 64, 128]` were used, which resulted in a total of `2,346,835` million params.\n\nTo train the model, run the following command:\n\n```\n python train.py   --dataset_name=\"huggan/flowers-102-categories\"   --resolution=64   --output_dir=\"trained_models/ddpm-ema-64.pth\"   --train_batch_size=16   --num_epochs=121 --gradient_accumulation_steps=1   --learning_rate=1e-4   --lr_warmup_steps=300\n```\n\n### Conclusions\n\n- Skip and residual connections are a must - training doesn't converge without them\n- Attention speeds up convergence and improves the quality of generated samples\n- Normalizing images to `N(0,1)` didn't yield improvents compared to the standard `-1 to 1` normalization\n- Learning rate of `1e-3` resulted in a faster convergence for the smaller models, compared to `1e-4` which is usually used in literature\n\n### Improvements\n\n- Training longer - these models require a lot of iterations. For example, in [Diffusion Models Beat GANs on Image Synthesis](https://arxiv.org/pdf/2105.05233.pdf), iterations ranged between `300K` and `4360k`!\n- Using bigger models\n- Would like to explore the impact of more diverse augmentations\n\n### Future steps\n\n- Training on `huggan/pokemons` dataset with a bigger model. This dataset proved to be too difficult for the `2M` model\n- Training a model on a custom task\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffilipbasara0%2Fsimple-diffusion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffilipbasara0%2Fsimple-diffusion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffilipbasara0%2Fsimple-diffusion/lists"}