{"id":23042564,"url":"https://github.com/daspartho/magicmix","last_synced_at":"2025-08-14T22:32:30.158Z","repository":{"id":65026985,"uuid":"576153823","full_name":"daspartho/MagicMix","owner":"daspartho","description":"Implementation of MagicMix: Semantic Mixing with Diffusion Models paper","archived":false,"fork":false,"pushed_at":"2023-01-15T17:22:38.000Z","size":14216,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2023-03-11T15:20:30.356Z","etag":null,"topics":["deep-learning","diffusers","diffusion-models","gradio","huggingface-spaces","machine-learning","paper-implementations"],"latest_commit_sha":null,"homepage":"https://huggingface.co/spaces/daspartho/MagicMix","language":"Jupyter Notebook","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/daspartho.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-12-09T06:04:29.000Z","updated_at":"2023-03-06T11:33:51.000Z","dependencies_parsed_at":"2023-02-09T23:00:59.872Z","dependency_job_id":null,"html_url":"https://github.com/daspartho/MagicMix","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daspartho%2FMagicMix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daspartho%2FMagicMix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daspartho%2FMagicMix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daspartho%2FMagicMix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daspartho","download_url":"https://codeload.github.com/daspartho/MagicMix/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229874317,"owners_count":18137750,"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","diffusers","diffusion-models","gradio","huggingface-spaces","machine-learning","paper-implementations"],"created_at":"2024-12-15T20:33:09.617Z","updated_at":"2024-12-15T20:33:10.289Z","avatar_url":"https://github.com/daspartho.png","language":"Jupyter Notebook","readme":"# MagicMix\n[![Generic badge](https://img.shields.io/badge/🤗-Open%20in%20Spaces-blue.svg)](https://huggingface.co/spaces/daspartho/MagicMix)\n\nImplementation of [MagicMix: Semantic Mixing with Diffusion Models](https://arxiv.org/pdf/2210.16056.pdf) paper.\n\n![magicmix](https://user-images.githubusercontent.com/59410571/206903603-6c8da6ef-69c4-4400-b4a3-aef9206ff396.png)\n\nThe aim of the method is to mix two different concepts in a semantic manner to synthesize a new concept while preserving the spatial layout and geometry.\n\nThe method takes an image that provides the layout semantics and a prompt that provides the content semantics for the mixing process.\n\nThere are 3 parameters for the method-\n- `v`: It is the interpolation constant used in the layout generation phase. The greater the value of v, the greater the influence of the prompt on the layout generation process.\n- `kmax` and `kmin`: These determine the range for the layout and content generation process. A higher value of kmax results in loss of more information about the layout of the original image and a higher value of kmin results in more steps for content generation process.\n\n### Usage\n\n```python\nfrom PIL import Image\nfrom magic_mix import magic_mix\n\nimg = Image.open('phone.jpg')\nout_img = magic_mix(img, 'bed', kmax=0.5)\nout_img.save(\"mix.jpg\")\n```\n```\npython3 magic_mix.py \\\n    \"phone.jpg\" \\\n    \"bed\" \\\n    \"mix.jpg\" \\\n    --kmin 0.3 \\\n    --kmax 0.6 \\\n    --v 0.5 \\\n    --steps 50 \\\n    --seed 42 \\\n    --guidance_scale 7.5\n```\nAlso, check out the [demo notebook](https://github.com/daspartho/MagicMix/blob/main/demo.ipynb) for example usage of the implementation to reproduce examples from the paper.\n\nYou can also use the community pipeline on the diffusers libary.\n\n```python\nfrom diffusers import DiffusionPipeline, DDIMScheduler\nfrom PIL import Image\n\npipe = DiffusionPipeline.from_pretrained(\n    \"CompVis/stable-diffusion-v1-4\",\n    custom_pipeline=\"magic_mix\",\n    scheduler = DDIMScheduler.from_pretrained(\"CompVis/stable-diffusion-v1-4\", subfolder=\"scheduler\"),\n).to('cuda')\n\nimg = Image.open('phone.jpg')\nmix_img = pipe(\n    img, \n    prompt = 'bed', \n    kmin = 0.3,\n    kmax = 0.5,\n    mix_factor = 0.5,\n    )\nmix_img.save('mix.jpg')\n```\n\n### Some examples reproduced from the paper:\n\n##### Input Image:\n\n![telephone](https://user-images.githubusercontent.com/59410571/206903102-34e79b9f-9ed2-4fac-bb38-82871343c655.jpg)\n\n##### Prompt: \"Bed\"\n\n##### Output Image:\n\n![telephone-bed](https://user-images.githubusercontent.com/59410571/206903104-913a671d-ef53-4ae4-919d-64c3059c8f67.jpg)\n\n##### Input Image:\n\n![sign](https://user-images.githubusercontent.com/59410571/206903307-b066dddd-8aaf-4104-9d5c-8427a51f37a7.jpg)\n\n##### Prompt: \"Family\"\n\n##### Output Image:\n\n![sign-family](https://user-images.githubusercontent.com/59410571/206903320-7530a8ac-6594-4449-8328-bbc31befd9e8.jpg)\n\n##### Input Image:\n\n![sushi](https://user-images.githubusercontent.com/59410571/206903325-a06268ef-903e-434b-8365-68fb8b003d1e.jpg)\n\n##### Prompt: \"ice-cream\"\n\n##### Output Image:\n\n![sushi-ice-cream](https://user-images.githubusercontent.com/59410571/206903341-e66d5c27-1543-489f-833b-dc8afc6c68e6.jpg)\n\n##### Input Image:\n\n![pineapple](https://user-images.githubusercontent.com/59410571/206903362-7c0464a7-ace4-4810-8fe3-37cab3d929a6.jpg)\n\n##### Prompt: \"Cake\"\n\n##### Output Image:\n\n![pineapple-cake](https://user-images.githubusercontent.com/59410571/206903377-3b0fb63c-061e-4070-a8d1-eaca5738ae36.jpg)\n\n### Note\n**I'm not the author of the paper, and this is not an official implementation**\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaspartho%2Fmagicmix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaspartho%2Fmagicmix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaspartho%2Fmagicmix/lists"}