Generate deep-dreams in PyTorch
Project description
torch-dreams
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()
simple_dreamer.deep_dream_on_video(
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)
model.eval()
- 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
andutils.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,
)
plt.imshow(dreamed)
plt.show()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
torch-dreams-0.0.2.tar.gz
(4.6 kB
view hashes)
Built Distribution
Close
Hashes for torch_dreams-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d58b7eeec18cc802fb58686178b9cd077437ab6c50553aa84042441a53e8ab7 |
|
MD5 | e794cc2e40240f3bcfe9933d3f59f794 |
|
BLAKE2b-256 | 86c59f981513e1d4dbb5b7b4c5e0c7c3c45a5d312ed07e5ac7e97f535d1ce5ce |