Skip to content

MLToolkits/dreamify

Repository files navigation

Dreamify

A function that applies deep dream to an image using a pre-trained CNN trained on the ImageNet dataset.

Doggy Cat

Installation

pip install dreamify

Testing it

dreamify

Usage

To apply Dreamify to an image, use the following Python script:

from dreamify.deepdream import deepdream


image_path = "example.jpg"

deepdream(image_path)

You may customize the behavior of the dreamifyer by selecting a different pre-trained model, saving it as a video, etc.:

from dreamify.deepdream import deepdream


image_path = "example.jpg"

deepdream(
    image_path,
    output_path="deepdream.png",
    model_name="inception_v3",
    iterations=100,
    learning_rate=0.01,
    octaves=range(-2, 3),
    octave_scale=1.3,
    save_video=False,
    save_gif=False,
    duration=3,
    vid_duration=3,
    gif_duration=3,
    mirror_video=False,
    seed=None,
)

You may also use an object oriented approach for fine-grained behavior:

from dreamify.deepdream import DeepDream

# Default settings

image_path1 = "example1.jpg"

deepdream = DeepDream()  
deepdream(image_path1)
deepdream.save_video(output_path=dream1.mp4, duration=42, mirror_video=False)
deepdream.save_gif(output_path=dream1.gif, duration=69, mirror_video=True)

##############################################################################

# Configured settings

image_path2 = "example2.jpg"
deepdream = DeepDream(iterations=50, learning_rate=0.1)  
deepdream(image_path2)
deepdream.save_video(output_path=dream2.mp4, duration=42, mirror_video=False)
deepdream.save_gif(output_path=dream2.gif, duration=69, mirror_video=True)

Available Models

Dreamify supports the following models:

Model Name Enum Value
VGG19 vgg19
ConvNeXt-XL convnext_xl
DenseNet121 densenet121
EfficientNet-V2L efficientnet_v2l
Inception-ResNet-V2 inception_resnet_v2
Inception-V3 (Default) inception_v3
ResNet152V2 resnet152v2
Xception xception
MobileNet-V2 mobilenet_v2

Other Examples

DeepDream

Dream (shallow) -- See documentation of dream (shallow).

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published