Skip to main content

Generate deep-dreams in PyTorch

Project description


deep dreams in PyTorch

Less lines of code, more deep-dreams

from torch_dreams.simple import vgg19_dreamer
import cv2 ## for saving images

simple_dreamer = vgg19_dreamer()

dreamed_image = simple_dreamer.dream(
    image_path = "your_image.png",
    layer_index= 27,
    iterations= 2,
    size = (256,256)

cv2.imwrite("dream.jpg", dreamed_image)

deep-dreams on a video

from torch_dreams.simple import vgg19_dreamer
simple_dreamer = vgg19_dreamer()

    video_path = "sample_videos/tiger_mini.mp4",
    save_name = "dream.mp4",
    layer = simple_dreamer.layers[13],
    octave_scale= 1.3,
    num_octaves = 2,
    iterations= 2,
    lr = 0.09,
    size = None, 
    framerate= 30.0

Generating deep dreams with your own PyTorch model

  • importing torch_dreams
from torch_dreams import  utils
from torch_dreams import dreamer
import matplotlib.pyplot as plt ## for viewing the deep-dreams
  • choosing a model (could be some other PyTorch model as well)
model= models.vgg19(pretrained=True)
  • selecting one of the model's layers for the deep-dream
layers = list(model.features.children())
layer = layers[13]
  • Defining the torch transforms to be applied before the forward pass (could be any set of torch transforms). Or if you're using the VGG19 like me, you could use utils.preprocess_func_vgg and utils.deprocess_func_vgg
preprocess = utils.preprocess_func_vgg
deprocess = utils.deprocess_func_vgg
  • Calling an instance of the dreamer class and generating a deep-dream
dreamer = dreamer(model, preprocess, deprocess)

dreamed = dreamer.deep_dream(
                        image_np =image_sample, 
                        layer = layer, 
                        octave_scale = 1.5, 
                        num_octaves = 2, 
                        iterations = 2, 
                        lr = 0.09,

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for torch-dreams, version 0.0.1
Filename, size File type Python version Upload date Hashes
Filename, size torch_dreams-0.0.1-py3.7.egg (11.0 kB) File type Egg Python version 3.7 Upload date Hashes View
Filename, size torch_dreams-0.0.1-py3-none-any.whl (5.6 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size torch-dreams-0.0.1.tar.gz (4.5 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page