All Projects → gordicaleksa → pytorch-deepdream

gordicaleksa / pytorch-deepdream

Licence: MIT license
PyTorch implementation of DeepDream algorithm (Mordvintsev et al.). Additionally I've included playground.py to help you better understand basic concepts behind the algo.

Programming Languages

Jupyter Notebook
11667 projects
python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to pytorch-deepdream

Vgg19 with tensorflow
An easy implement of VGG19 with tensorflow, which has a detailed explanation.
Stars: ✭ 173 (-40.96%)
Mutual labels:  deep-learning-tutorial
Nn
🧑‍🏫 50! Implementations/tutorials of deep learning papers with side-by-side notes 📝; including transformers (original, xl, switch, feedback, vit, ...), optimizers (adam, adabelief, ...), gans(cyclegan, stylegan2, ...), 🎮 reinforcement learning (ppo, dqn), capsnet, distillation, ... 🧠
Stars: ✭ 5,720 (+1852.22%)
Mutual labels:  deep-learning-tutorial
python autocomplete
Use Transformers and LSTMs to learn Python source code
Stars: ✭ 172 (-41.3%)
Mutual labels:  deep-learning-tutorial
Awesome Deep Learning And Machine Learning Questions
【不定期更新】收集整理的一些网站中(如知乎、Quora、Reddit、Stack Exchange等)与深度学习、机器学习、强化学习、数据科学相关的有价值的问题
Stars: ✭ 203 (-30.72%)
Mutual labels:  deep-learning-tutorial
Color Accessibility Neural Network Deeplearnjs
🍃 Using a Neural Network to improve web accessibility in JavaScript.
Stars: ✭ 230 (-21.5%)
Mutual labels:  deep-learning-tutorial
Protobuf-Dreamer
A tiled DeepDream project for creating any size of image, on both CPU and GPU
Stars: ✭ 39 (-86.69%)
Mutual labels:  deepdream
Numpydl
Deep Learning Library. For education. Based on pure Numpy. Support CNN, RNN, LSTM, GRU etc.
Stars: ✭ 169 (-42.32%)
Mutual labels:  deep-learning-tutorial
deep-dream-pytorch
Pytorch implementation of DeepDream on VGG16 Network
Stars: ✭ 46 (-84.3%)
Mutual labels:  deepdream
Wordgcn
ACL 2019: Incorporating Syntactic and Semantic Information in Word Embeddings using Graph Convolutional Networks
Stars: ✭ 230 (-21.5%)
Mutual labels:  deep-learning-tutorial
lectures-all
Central repository for all lectures on deep learning at UPC ETSETB TelecomBCN.
Stars: ✭ 46 (-84.3%)
Mutual labels:  deep-learning-tutorial
Gluon Api
A clear, concise, simple yet powerful and efficient API for deep learning.
Stars: ✭ 2,322 (+692.49%)
Mutual labels:  deep-learning-tutorial
Machine Learning Notebooks
Machine Learning notebooks for refreshing concepts.
Stars: ✭ 222 (-24.23%)
Mutual labels:  deep-learning-tutorial
neural-dream
PyTorch implementation of DeepDream algorithm
Stars: ✭ 110 (-62.46%)
Mutual labels:  deepdream
Ml Glossary
Machine learning glossary
Stars: ✭ 2,338 (+697.95%)
Mutual labels:  deep-learning-tutorial
deep-blueberry
If you've always wanted to learn about deep-learning but don't know where to start, then you might have stumbled upon the right place!
Stars: ✭ 17 (-94.2%)
Mutual labels:  deep-learning-tutorial
Dive Into Dl Pytorch
本项目将《动手学深度学习》(Dive into Deep Learning)原书中的MXNet实现改为PyTorch实现。
Stars: ✭ 14,234 (+4758.02%)
Mutual labels:  deep-learning-tutorial
Deep-Learning-CNN-for-Image-Recognition
Google TensorFlow project for classification using images or video input.
Stars: ✭ 33 (-88.74%)
Mutual labels:  deepdream
Tensorflow-ML
Different machine learning algorithms implementation in Tensorflow
Stars: ✭ 26 (-91.13%)
Mutual labels:  deep-learning-tutorial
cnn-visualization-keras-tf2
Filter visualization, Feature map visualization, Guided Backprop, GradCAM, Guided-GradCAM, Deep Dream
Stars: ✭ 21 (-92.83%)
Mutual labels:  deepdream
DeepDream
Generative deep learning: DeepDream
Stars: ✭ 17 (-94.2%)
Mutual labels:  deepdream

Deep Dream 💻 + 🌊💤 = ❤️

This repo contains a PyTorch implementation of the Deep Dream algorithm (🔗 blog by Mordvintstev et al.).

It's got a full support for the command line usage and a Jupyter Notebook!

And it will give you the power to create these weird, psychedelic-looking images:

Not bad, huh?

I strongly suggest you start with the Jupyter notebook that I've created!

Note: it's pretty large, ~10 MBs, so it may take a couple of attempts to load it in the browser here on GitHub.

Table of Contents

What is DeepDream algorithm?

In a nutshell the algorithm maximizes the activations of chosen network layers by doing a gradient ascent.

So from an input image like the one on the left after "dreaming" we get the image on the right:

Who would have said that neural networks had this creativity hidden inside? 🎨

Why yet another Deep Dream repo?

Most of the original Deep Dream repos were written in Caffe and the ones written in PyTorch are usually really hard to read and understand. This repo is an attempt of making the cleanest DeepDream repo that I'm aware of + it's written in PyTorch! ❤️

Static Image Examples

Here are some examples that you can create using this code!

Optimizing shallower layers = Amplify low-level features

By using shallower layers of neural networks you'll get lower level patterns (edges, circles, colors, etc.) as the output:

Here the first 2 images came from ResNet50 and the last one came from GoogLeNet (both pretrained on ImageNet).

Optimizing deeper Layers = Amplify high-level features

By using deeper network layers you'll get higher level patterns (eyes, snouts, animal heads):

The 1st and 3rd were created using VGG 16 (ImageNet) and the middle one using ResNet50 pretrained on Places 365.

Dataset matters (ImageNet vs Places 365)

If we keep every other parameter the same but we swap the pretrained weights we get these:

Left: ResNet50-ImageNet (we can see more animal features) Right: ResNet50-Places365 (human built stuff, etc.).

Impact of increasing the pyramid size

Dreaming is performed on multiple image resolutions stacked "vertically" (we call this an image pyramid).

Going from left to right the only parameter that changed was the pyramid size (from left to right: 3, 7, 9 levels).

Impact of increasing the pyramid ratio

Playing 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" (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):

Note: you can see the exact params used to create these images encoded into the filename!

Make sure to check out the Jupyter notebook!, I've explained this thoroughly.

Ouroboros Video Examples

Here are some further examples that you can create using this code!

The idea here is that whatever the network dreams just feed that back to it's input and apply a geometric transformation.

Ouroboros: Zoom transform

If we apply only central zoom we get this:

Ouroboros: Zoom and Rotation transforms

Applying central zoom and at the same time applying a 3 degree rotation per frame yields this:

Ouroboros: Translation

Finally if we do a simple translation (5 px per frame top left to bottom right direction):

Hopefully these did not break your brain - it feels like web 1.0 early 2000s. Bear with me.

DeepDream Video Examples

Instead of feeding the output back to input we just apply the algorithm per frame and apply some linear blending:

Linear blending just combines the current frame with the last one so as to reduce the flicker (here I used 0.85)

Note: all of the deepdream images/GIFs were produced by me, credits for original image artists are given bellow.

Setup

  1. git clone https://github.com/gordicaleksa/pytorch-deepdream
  2. Open Anaconda Prompt and navigate into project directory cd path_to_repo
  3. Run conda env create from project directory (this will create a brand new conda environment).
  4. Run activate pytorch-deepdream (for running scripts from your console or setup the interpreter in your IDE)

That's it! It should work out-of-the-box executing environment.yml file which deals with dependencies.

Note: If you wish to use video functions I have - you'll need ffmpeg in your system path.


PyTorch pip package will come bundled with some version of CUDA/cuDNN with it, but it is highly recommended that you install a system-wide CUDA beforehand, mostly because of the GPU drivers. I also recommend using Miniconda installer as a way to get conda on your system. Follow through points 1 and 2 of this setup and use the most up-to-date versions of Miniconda and CUDA/cuDNN for your system.

Usage

Option 1: Jupyter Notebook

Just run jupyter notebook from you Anaconda console and it will open up a session in your default browser.
Open The Annotated DeepDream.ipynb and you're ready to play!

Note: if you get DLL load failed while importing win32api: The specified module could not be found
Just do pip uninstall pywin32 and then either pip install pywin32 or conda install pywin32 should fix it!

Option 2: Use your IDE of choice

You just need to link the Python environment you created in the setup section.

Option 3: Command line

Navigate to/activate your env if you're using Anaconda (and I hope you do) and you can use the commands I've linked below.


Tip: Place your images/videos inside the data/input/ directory and you can then just reference your files (images/videos) by their name instead of using absolute/relative paths.

DeepDream images

To create some static Deep Dream images run the following command:

python deepdream.py --input <img_name> --img_width 600

This will use the default settings but you'll immediately get a meaningful result saved to:

data/out-images/VGG16_EXPERIMENTAL_IMAGENET/

Note: the output directory will change depending on the model and pretrained weights you use.

Ouroboros videos

To get the out-of-the-box Ouroboros 30-frame video do the following:

python deepdream.py --input <img_name> --create_ouroboros --ouroboros_length 30

It will dump the intermediate frames to data/out-videos/VGG16_EXPERIMENTAL_IMAGENET/ and it will save the final video to data/out-videos.

DeepDream videos

To create a Deep Dream video run this command:

python deepdream.py --input <mp4 video name>

It will dump the intermediate frames to data/out-videos/tmp_out and it will save the final video to data/out-videos.


Well, enjoy playing with this project! Here are some additional, beautiful, results:

Hardware requirements

A GPU with 2+ GBs will be more than enough.

You'll be able to create DeepDream images, Ouroboros and DeepDream videos.

If you don't have a GPU, the code will automatically run on the CPU but somewhat slower (especially for videos).

Learning material

If you're having difficulties understanding DeepDream I did an overview of the algorithm in this video:

The GAT paper explained

And also the Jupyter Notebook I created is the best place to start!

Acknowledgements

I found these repos useful (while developing this one):

I found the images I was using here:

Other images are now already classics in the NST and DeepDream worlds.

Places 365 pretrained models came from this awesome repo.

Citation

If you find this code useful for your research, please cite the following:

@misc{Gordić2020DeepDream,
  author = {Gordić, Aleksa},
  title = {pytorch-deepdream},
  year = {2020},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/gordicaleksa/pytorch-deepdream}},
}

Connect with me

If you'd love to have some more AI-related content in your life 🤓, consider:

Licence

License: MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].