{"id":19535482,"url":"https://github.com/gordicaleksa/pytorch-deepdream","last_synced_at":"2025-10-10T18:07:59.299Z","repository":{"id":43904921,"uuid":"277642926","full_name":"gordicaleksa/pytorch-deepdream","owner":"gordicaleksa","description":"PyTorch implementation of DeepDream algorithm (Mordvintsev et al.). Additionally I've included playground.py to help you better understand basic concepts behind the algo.","archived":false,"fork":false,"pushed_at":"2023-09-17T16:11:59.000Z","size":45349,"stargazers_count":392,"open_issues_count":7,"forks_count":86,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-10-05T20:57:58.959Z","etag":null,"topics":["deep-dream-tutorial","deep-learning","deep-learning-tutorial","deepdream","machine-learning","python","pytorch"],"latest_commit_sha":null,"homepage":"https://youtube.com/c/TheAIEpiphany","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/gordicaleksa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"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},"funding":{"patreon":"theaiepiphany"}},"created_at":"2020-07-06T20:33:15.000Z","updated_at":"2025-09-15T16:19:28.000Z","dependencies_parsed_at":"2024-12-16T00:04:29.389Z","dependency_job_id":null,"html_url":"https://github.com/gordicaleksa/pytorch-deepdream","commit_stats":{"total_commits":78,"total_committers":2,"mean_commits":39.0,"dds":"0.012820512820512775","last_synced_commit":"f37d99a1fa0cafa94aa99d9384026292a3c9bb6c"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gordicaleksa/pytorch-deepdream","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gordicaleksa%2Fpytorch-deepdream","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gordicaleksa%2Fpytorch-deepdream/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gordicaleksa%2Fpytorch-deepdream/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gordicaleksa%2Fpytorch-deepdream/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gordicaleksa","download_url":"https://codeload.github.com/gordicaleksa/pytorch-deepdream/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gordicaleksa%2Fpytorch-deepdream/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279004908,"owners_count":26083802,"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","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-dream-tutorial","deep-learning","deep-learning-tutorial","deepdream","machine-learning","python","pytorch"],"created_at":"2024-11-11T02:18:50.712Z","updated_at":"2025-10-10T18:07:59.266Z","avatar_url":"https://github.com/gordicaleksa.png","language":"Jupyter Notebook","funding_links":["https://patreon.com/theaiepiphany"],"categories":[],"sub_categories":[],"readme":"## Deep Dream :computer: + :ocean::zzz: = :heart:\nThis repo contains a PyTorch implementation of the Deep Dream algorithm (:link: blog by [Mordvintstev et al.](https://ai.googleblog.com/2015/06/inceptionism-going-deeper-into-neural.html)).\n\nIt's got a full support for the **command line** usage and a **Jupyter Notebook**!\n\nAnd it will give you the power to create these weird, psychedelic-looking images:\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"data/examples/figures_width_600_model_VGG16_IMAGENET_relu4_3_pyrsize_12_pyrratio_1.4_iter_10_lr_0.09_shift_32_resized500.jpg\" width=\"488\"/\u003e\n\u003cimg src=\"data/examples/lion_width_600_model_VGG16_EXPERIMENTAL_IMAGENET_relu3_3_pyrsize_4_pyrratio_1.8_iter_10_lr_0.09_shift_32_resized400.jpg\" width=\"325\"/\u003e\n\u003c/p\u003e\n\nNot bad, huh?\n\nI strongly suggest you start with the [Jupyter notebook](https://github.com/gordicaleksa/pytorch-deepdream/blob/master/The%20Annotated%20DeepDream.ipynb) that I've created!\n\n*Note: it's pretty large, ~10 MBs, so it may take a couple of attempts to load it in the browser here on GitHub.*\n\n## Table of Contents\n* [What is DeepDream?](#what-is-deepdream-algorithm)\n    * [Image visualizations and experiments](#static-image-examples)\n    * [Ouroboros video examples](#ouroboros-video-examples)\n    * [DeepDream video examples](#deepdream-video-examples)\n* [Setup](#setup)\n* [Usage](#usage)\n* [Hardware requirements](#hardware-requirements)\n* [Learning material](#learning-material)\n\n### What is DeepDream algorithm?\nIn a nutshell the algorithm maximizes the activations of chosen network layers by doing a **gradient ascent**.\n\nSo from an input image like the one on the left after \"dreaming\" we get the image on the right:\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"data/input/figures.jpg\" width=\"400\"/\u003e\n\u003cimg src=\"data/examples/figures_width_600_model_VGG16_IMAGENET_relu4_3_pyrsize_4_pyrratio_1.4_iter_10_lr_0.09_shift_41.jpg\" width=\"400\"/\u003e\n\u003c/p\u003e\n\nWho would have said that neural networks had this creativity hidden inside? :art:\n\n#### Why yet another Deep Dream repo?\n\nMost of the original Deep Dream repos were written in **Caffe** and the ones written in PyTorch are usually really hard to read and understand.\nThis repo is an attempt of making the **cleanest** DeepDream repo that I'm aware of + it's written in **PyTorch!** :heart:\n\n## Static Image Examples\n\nHere are some examples that you can create using this code!\n\n### Optimizing shallower layers = Amplify low-level features\n\nBy using shallower layers of neural networks you'll get lower level patterns (edges, circles, colors, etc.) as the output:\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"data/examples/low_level_dreaming/figures_width_600_model_RESNET50_IMAGENET_layer2_pyrsize_11_pyrratio_1.3_iter_30_lr_0.09_shift_150_resized300.jpg\" width=\"270\"/\u003e\n\u003cimg src=\"data/examples/low_level_dreaming/figures_width_600_model_RESNET50_IMAGENET_layer2_pyrsize_11_pyrratio_1.3_iter_10_lr_0.09_shift_34_resized300.jpg\" width=\"270\"/\u003e\n\u003cimg src=\"data/examples/low_level_dreaming/figures_width_600_model_GOOGLENET_IMAGENET_inception3b_pyrsize_11_pyrratio_1.3_iter_10_lr_0.09_shift_35_resized300.jpg\" width=\"270\"/\u003e\n\u003c/p\u003e\n\nHere the first 2 images came from ResNet50 and the last one came from GoogLeNet (both pretrained on ImageNet).\n\n### Optimizing deeper Layers = Amplify high-level features\n\nBy using deeper network layers you'll get higher level patterns (eyes, snouts, animal heads):\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"data/examples/high_level_dreaming/figures_width_600_model_VGG16_IMAGENET_relu4_3_pyrsize_12_pyrratio_1.4_iter_10_lr_0.09_shift_101_resized300.jpg\" width=\"270\"/\u003e\n\u003cimg src=\"data/examples/high_level_dreaming/figures_width_600_model_RESNET50_PLACES_365_layer4_pyrsize_11_pyrratio_1.3_iter_10_lr_0.09_shift_34_resized300.jpg\" width=\"270\"/\u003e\n\u003cimg src=\"data/examples/high_level_dreaming/green_bridge_width_600_model_VGG16_EXPERIMENTAL_IMAGENET_relu4_3_pyrsize_4_pyrratio_1.8_iter_10_lr_0.09_shift_32_resized.jpg\" width=\"270\"/\u003e\n\u003c/p\u003e\n\nThe 1st and 3rd were created using VGG 16 (ImageNet) and the middle one using ResNet50 pretrained on Places 365.\n\n### Dataset matters (ImageNet vs Places 365)\n\nIf we keep every other parameter the same but we swap the pretrained weights we get these:\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"data/examples/dataset_matters/figures_width_600_model_RESNET50_IMAGENET_layer4_pyrsize_8_pyrratio_1.4_iter_10_lr_0.09_shift_32_resized400.jpg\" width=\"400\"/\u003e\n\u003cimg src=\"data/examples/dataset_matters/figures_width_600_model_RESNET50_PLACES_365_layer4_pyrsize_8_pyrratio_1.4_iter_10_lr_0.09_shift_32_resized400.jpg\" width=\"400\"/\u003e\n\u003c/p\u003e\n\nLeft: **ResNet50-ImageNet** (we can see more animal features) Right: **ResNet50-Places365** (human built stuff, etc.).\n\n### Impact of increasing the pyramid size\n\nDreaming is performed on multiple image resolutions stacked \"vertically\" (we call this an **image pyramid**).\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"data/examples/pyramid_size/figures_width_600_model_VGG16_EXPERIMENTAL_IMAGENET_relu4_3_pyrsize_3_pyrratio_1.3_iter_10_lr_0.09_shift_33_resized300.jpg\" width=\"270\"/\u003e\n\u003cimg src=\"data/examples/pyramid_size/figures_width_600_model_VGG16_EXPERIMENTAL_IMAGENET_relu4_3_pyrsize_7_pyrratio_1.3_iter_10_lr_0.09_shift_33_resized300.jpg\" width=\"270\"/\u003e\n\u003cimg src=\"data/examples/pyramid_size/figures_width_600_model_VGG16_EXPERIMENTAL_IMAGENET_relu4_3_pyrsize_9_pyrratio_1.3_iter_10_lr_0.09_shift_33_resized300.jpg\" width=\"270\"/\u003e\n\u003c/p\u003e\n\nGoing from left to right the only parameter that changed was the pyramid size (from left to right: 3, 7, 9 levels).\n\n### Impact of increasing the pyramid ratio\n\nPlaying with pyramid ratio has a similar/related effect - the basic idea is that the relative area of the image which the deeper neurons can modify and \"see\"\n(the so-called **receptive field** of the net) is increasing and we get increasingly bigger features like eyes popping out (from left to right: 1.1, 1.5, 1.8):\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"data/examples/pyramid_ratio/figures_width_600_model_VGG16_EXPERIMENTAL_IMAGENET_relu4_2_pyrsize_5_pyrratio_1.1_iter_10_lr_0.09_shift_38_resized300.jpg\" width=\"270\"/\u003e\n\u003cimg src=\"data/examples/pyramid_ratio/figures_width_600_model_VGG16_EXPERIMENTAL_IMAGENET_relu4_2_pyrsize_5_pyrratio_1.5_iter_10_lr_0.09_shift_38_resized300.jpg\" width=\"270\"/\u003e\n\u003cimg src=\"data/examples/pyramid_ratio/figures_width_600_model_VGG16_EXPERIMENTAL_IMAGENET_relu4_2_pyrsize_5_pyrratio_1.8_iter_10_lr_0.09_shift_38_resized300.jpg\" width=\"270\"/\u003e\n\u003c/p\u003e\n\n**Note: you can see the exact params used to create these images encoded into the filename!**\n\nMake sure to check out the [Jupyter notebook!](https://github.com/gordicaleksa/pytorch-deepdream/blob/master/The%20Annotated%20DeepDream.ipynb), I've explained this thoroughly.\n\n## Ouroboros Video Examples\n\nHere are some further examples that you can create using this code!\n\nThe idea here is that whatever the network dreams just feed that back to it's input and apply a geometric transformation.\n\n### Ouroboros: Zoom transform\n\nIf we apply only central zoom we get this:\n\n\u003cimg src=\"data/examples/ouroboros/zoom.gif\" /\u003e\n\n### Ouroboros: Zoom and Rotation transforms\n\nApplying central zoom and at the same time applying a 3 degree rotation per frame yields this:\n\n\u003cimg src=\"data/examples/ouroboros/zoom_rotate.gif\" /\u003e\n\n### Ouroboros: Translation \n\nFinally if we do a simple translation (5 px per frame top left to bottom right direction):\n\n\u003cimg src=\"data/examples/ouroboros/translation.gif\" /\u003e\n\nHopefully these did not break your brain - it feels like web 1.0 early 2000s. Bear with me.\n\n## DeepDream Video Examples\n\nInstead of feeding the output back to input we just apply the algorithm per frame and apply some linear blending:\n\n\u003cimg src=\"data/examples/deepdream_video/deepdream_video.gif\" /\u003e\n\nLinear blending just combines the current frame with the last one so as to reduce the flicker (here I used 0.85)\n\n*Note: all of the deepdream images/GIFs were produced by me, credits for original image artists [are given bellow](#acknowledgements).*\n\n## Setup\n\n1. `git clone https://github.com/gordicaleksa/pytorch-deepdream`\n1. Open Anaconda Prompt and navigate into project directory `cd path_to_repo`\n2. Run `conda env create` from project directory (this will create a brand new conda environment).\n3. Run `activate pytorch-deepdream` (for running scripts from your console or setup the interpreter in your IDE)\n\nThat's it! It should work out-of-the-box executing environment.yml file which deals with dependencies.\n\n*Note:* If you wish to use video functions I have - you'll need **ffmpeg** in your system path.\n\n-----\n\nPyTorch pip package will come bundled with some version of CUDA/cuDNN with it,\nbut it is highly recommended that you install a system-wide CUDA beforehand, mostly because of the GPU drivers. \nI also recommend using Miniconda installer as a way to get conda on your system.\nFollow through points 1 and 2 of [this setup](https://github.com/Petlja/PSIML/blob/master/docs/MachineSetup.md)\nand use the most up-to-date versions of Miniconda and CUDA/cuDNN for your system.\n\n## Usage\n\n#### Option 1: Jupyter Notebook\n\nJust run `jupyter notebook` from you Anaconda console and it will open up a session in your default browser. \u003cbr/\u003e\nOpen `The Annotated DeepDream.ipynb` and you're ready to play!\n\n**Note:** if you get `DLL load failed while importing win32api: The specified module could not be found` \u003cbr/\u003e\nJust do `pip uninstall pywin32` and then either `pip install pywin32` or `conda install pywin32` [should fix it](https://github.com/jupyter/notebook/issues/4980)!\n\n#### Option 2: Use your IDE of choice\n\nYou just need to link the Python environment you created in the [setup](#setup) section.\n\n#### Option 3: Command line\n\nNavigate to/activate your env if you're using Anaconda (and I hope you do) and you can use the commands I've linked below.\n\n---\n\n**Tip: Place your images/videos inside the `data/input/` directory and you can then just reference \nyour files (images/videos) by their name instead of using absolute/relative paths.**\n\n### DeepDream images\n\nTo create some **static Deep Dream images** run the following command:\n\n`python deepdream.py --input \u003cimg_name\u003e --img_width 600`\n\nThis will use the default settings but you'll immediately get a meaningful result saved to:\n\n`data/out-images/VGG16_EXPERIMENTAL_IMAGENET/`\n\n*Note: the output directory will change depending on the model and pretrained weights you use.*\n\n### Ouroboros videos\n\nTo get the out-of-the-box **Ouroboros** 30-frame video do the following:\n\n`python deepdream.py --input \u003cimg_name\u003e --create_ouroboros --ouroboros_length 30`\n\nIt will dump the intermediate frames to `data/out-videos/VGG16_EXPERIMENTAL_IMAGENET/` and it will save the final video to `data/out-videos`.\n\n### DeepDream videos\n\nTo create a **Deep Dream video** run this command:\n\n`python deepdream.py --input \u003cmp4 video name\u003e`\n\nIt will dump the intermediate frames to `data/out-videos/tmp_out` and it will save the final video to `data/out-videos`.\n\n---\n\nWell, enjoy playing with this project! Here are some additional, beautiful, results:\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"data/examples/footer/figures_width_600_model_RESNET50_PLACES_365_layer3_pyrsize_11_pyrratio_1.3_iter_10_lr_0.09_shift_32_resized400.jpg\" width=\"400\"/\u003e\n\u003cimg src=\"data/examples/footer/figures_width_600_model_RESNET50_PLACES_365_layer4_pyrsize_11_pyrratio_1.3_iter_10_lr_0.09_shift_32_resized400.jpg\" width=\"400\"/\u003e\n\u003c/p\u003e\n\n## Hardware requirements\n\nA GPU with 2+ GBs will be more than enough.\n\nYou'll be able to create DeepDream images, Ouroboros and DeepDream videos.\n\nIf you don't have a GPU, the code will automatically run on the CPU but somewhat slower (especially for videos).\n\n## Learning material\n\nIf you're having difficulties understanding DeepDream I did an overview of the algorithm [in this video](https://www.youtube.com/watch?v=6rVrh5gnpwk):\n\n\u003cp align=\"left\"\u003e\n\u003ca href=\"https://www.youtube.com/watch?v=6rVrh5gnpwk\" target=\"_blank\"\u003e\u003cimg src=\"https://img.youtube.com/vi/6rVrh5gnpwk/0.jpg\" \nalt=\"The GAT paper explained\" width=\"480\" height=\"360\" border=\"10\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nAnd also the [Jupyter Notebook](https://github.com/gordicaleksa/pytorch-deepdream/blob/master/The%20Annotated%20DeepDream.ipynb) I created is the best place to start!\n\n## Acknowledgements\n\nI found these repos useful (while developing this one):\n* [deepdream](https://github.com/google/deepdream) (Caffe, original repo)\n* [DeepDreamAnim](https://github.com/samim23/DeepDreamAnim) (Caffe)\n* [AI-Art](https://github.com/Adi-iitd/AI-Art/blob/master/DeepDream.py) (PyTorch)\n* [neural-dream](https://github.com/ProGamerGov/neural-dream) (PyTorch)\n* [DeepDream](https://github.com/CharlesPikachu/DeepDream) (PyTorch)\n\nI found the images I was using here:\n* [awesome figures pic](https://www.pexels.com/photo/action-android-device-electronics-595804/)\n* [awesome bridge pic](https://www.pexels.com/photo/gray-bridge-and-trees-814499/)\n\nOther images are now already classics in the NST and DeepDream worlds.\n\nPlaces 365 pretrained models came from [this awesome repo](https://github.com/CSAILVision/places365).\n\n## Citation\n\nIf you find this code useful for your research, please cite the following:\n\n```\n@misc{Gordić2020DeepDream,\n  author = {Gordić, Aleksa},\n  title = {pytorch-deepdream},\n  year = {2020},\n  publisher = {GitHub},\n  journal = {GitHub repository},\n  howpublished = {\\url{https://github.com/gordicaleksa/pytorch-deepdream}},\n}\n```\n\n## Connect with me\n\nIf you'd love to have some more AI-related content in your life :nerd_face:, consider:\n* Subscribing to my YouTube channel [The AI Epiphany](https://www.youtube.com/c/TheAiEpiphany) :bell:\n* Follow me on [LinkedIn](https://www.linkedin.com/in/aleksagordic/) and [Twitter](https://twitter.com/gordic_aleksa) :bulb:\n* Follow me on [Medium](https://gordicaleksa.medium.com/) :books: :heart:\n\n## Licence\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/gordicaleksa/pytorch-deepdream/blob/master/LICENCE)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgordicaleksa%2Fpytorch-deepdream","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgordicaleksa%2Fpytorch-deepdream","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgordicaleksa%2Fpytorch-deepdream/lists"}