青山上空的薄霧
草地上的碎盤子
宇宙的愛與關注
人群中的時間旅行者
瘟疫期間的生活
在陽光照射的森林中冥想和平
一個人畫了一個完全紅色的圖像
LSD 的迷幻體驗
使用 OpenAI 的 CLIP 和 Siren 生成文字到圖像的簡單命令列工具。歸功於 Ryan Murdock 發現了這項技術(並提出了這個偉大的名字)!
原廠筆記本
新的簡化筆記本
這需要您有 Nvidia GPU 或 AMD GPU
$ pip install deep-daze
假設Python已安裝:
pip install deep-daze
$ imagine " a house in the forest "
對於 Windows:
imagine " a house in the forest "
就是這樣。
如果你有足夠的內存,你可以透過添加--deeper
標誌來獲得更好的質量
$ imagine " shattered plates on the ground " --deeper
在真正的深度學習時尚中,更多的層次會產生更好的結果。預設值為16
,但可以根據您的資源增加到32
。
$ imagine " stranger in strange lands " --num-layers 32
NAME
imagine
SYNOPSIS
imagine TEXT < flags >
POSITIONAL ARGUMENTS
TEXT
(required) A phrase less than 77 tokens which you would like to visualize.
FLAGS
--img=IMAGE_PATH
Default: None
Path to png/jpg image or PIL image to optimize on
--encoding=ENCODING
Default: None
User-created custom CLIP encoding. If used, replaces any text or image that was used.
--create_story=CREATE_STORY
Default: False
Creates a story by optimizing each epoch on a new sliding-window of the input words. If this is enabled, much longer texts than 77 tokens can be used. Requires save_progress to visualize the transitions of the story.
--story_start_words=STORY_START_WORDS
Default: 5
Only used if create_story is True. How many words to optimize on for the first epoch.
--story_words_per_epoch=STORY_WORDS_PER_EPOCH
Default: 5
Only used if create_story is True. How many words to add to the optimization goal per epoch after the first one.
--story_separator:
Default: None
Only used if create_story is True. Defines a separator like ' . ' that splits the text into groups for each epoch. Separator needs to be in the text otherwise it will be ignored
--lower_bound_cutout=LOWER_BOUND_CUTOUT
Default: 0.1
Lower bound of the sampling of the size of the random cut-out of the SIREN image per batch. Should be smaller than 0.8.
--upper_bound_cutout=UPPER_BOUND_CUTOUT
Default: 1.0
Upper bound of the sampling of the size of the random cut-out of the SIREN image per batch. Should probably stay at 1.0.
--saturate_bound=SATURATE_BOUND
Default: False
If True, the LOWER_BOUND_CUTOUT is linearly increased to 0.75 during training.
--learning_rate=LEARNING_RATE
Default: 1e-05
The learning rate of the neural net.
--num_layers=NUM_LAYERS
Default: 16
The number of hidden layers to use in the Siren neural net.
--batch_size=BATCH_SIZE
Default: 4
The number of generated images to pass into Siren before calculating loss. Decreasing this can lower memory and accuracy.
--gradient_accumulate_every=GRADIENT_ACCUMULATE_EVERY
Default: 4
Calculate a weighted loss of n samples for each iteration. Increasing this can help increase accuracy with lower batch sizes.
--epochs=EPOCHS
Default: 20
The number of epochs to run.
--iterations=ITERATIONS
Default: 1050
The number of times to calculate and backpropagate loss in a given epoch.
--save_every=SAVE_EVERY
Default: 100
Generate an image every time iterations is a multiple of this number.
--image_width=IMAGE_WIDTH
Default: 512
The desired resolution of the image.
--deeper=DEEPER
Default: False
Uses a Siren neural net with 32 hidden layers.
--overwrite=OVERWRITE
Default: False
Whether or not to overwrite existing generated images of the same name.
--save_progress=SAVE_PROGRESS
Default: False
Whether or not to save images generated before training Siren is complete.
--seed=SEED
Type: Optional[]
Default: None
A seed to be used for deterministic runs.
--open_folder=OPEN_FOLDER
Default: True
Whether or not to open a folder showing your generated images.
--save_date_time=SAVE_DATE_TIME
Default: False
Save files with a timestamp prepended e.g. ` %y%m%d-%H%M%S-my_phrase_here `
--start_image_path=START_IMAGE_PATH
Default: None
The generator is trained first on a starting image before steered towards the textual input
--start_image_train_iters=START_IMAGE_TRAIN_ITERS
Default: 50
The number of steps for the initial training on the starting image
--theta_initial=THETA_INITIAL
Default: 30.0
Hyperparameter describing the frequency of the color space. Only applies to the first layer of the network.
--theta_hidden=THETA_INITIAL
Default: 30.0
Hyperparameter describing the frequency of the color space. Only applies to the hidden layers of the network.
--save_gif=SAVE_GIF
Default: False
Whether or not to save a GIF animation of the generation procedure. Only works if save_progress is set to True.
該技術最初由 Mario Klingemann 設計和分享,它允許您在引導至文字之前使用起始圖像來啟動生成器網路。
只需指定您要使用的影像的路徑,以及可選的初始訓練步驟數。
$ imagine ' a clear night sky filled with stars ' --start_image_path ./cloudy-night-sky.jpg
已塗底漆的起始影像
然後按照提示進行訓練A pizza with green pepper.
我們還可以輸入影像作為優化目標,而不僅僅是啟動生成器網路。然後 Deepdaze 會對該圖像做出自己的解釋:
$ imagine --img samples/Autumn_1875_Frederic_Edwin_Church.jpg
原圖:
網路解讀:
原圖:
網路解讀:
$ imagine " A psychedelic experience. " --img samples/hot-dog.jpg
網路解讀:
文字的常規模式僅允許 77 個標記。如果您想視覺化完整的故事/段落/歌曲/詩歌,請將create_story
設定為True
。
考慮到羅伯特·弗羅斯特的詩作《在一個下雪的夜晚停在樹林裡》——「我想我知道這些是誰的樹林。儘管他的房子在村子裡;他不會看到我在這裡停下來觀看他的樹林被雪填滿。錯誤唯一的其他聲音是微風的掠過。 」
我們得到:
deep_daze.Imagine
from deep_daze import Imagine
imagine = Imagine (
text = 'cosmic love and attention' ,
num_layers = 24 ,
)
imagine ()
以以下格式儲存圖片:insert_text_here.00001.png、insert_text_here.00002.png、...最多(total_iterations % save_every)
imagine = Imagine (
text = text ,
save_every = 4 ,
save_progress = True
)
建立帶有時間戳記和序號的檔案。
例如 210129-043928_328751_insert_text_here.00001.png、210129-043928_512351_insert_text_here.00002.png、...
imagine = Imagine (
text = text ,
save_every = 4 ,
save_progress = True ,
save_date_time = True ,
)
如果您有至少 16 GiB 的可用 vram,您應該能夠在有一定迴旋空間的情況下運行這些設定。
imagine = Imagine (
text = text ,
num_layers = 42 ,
batch_size = 64 ,
gradient_accumulate_every = 1 ,
)
imagine = Imagine (
text = text ,
num_layers = 24 ,
batch_size = 16 ,
gradient_accumulate_every = 2
)
如果您迫切希望在小於 8 GiB vram 的卡上運行此程序,則可以降低 image_width。
imagine = Imagine (
text = text ,
image_width = 256 ,
num_layers = 16 ,
batch_size = 1 ,
gradient_accumulate_every = 16 # Increase gradient_accumulate_every to correct for loss in low batch sizes
)
這些實驗是使用 2060 Super RTX 和 3700X Ryzen 5 進行的。
對於 512 的影像解析度:
對於 256 的影像解析度:
@NotNANtoN 建議批量大小為 32、44 層和訓練 1-8 輪。
這只是一個預告片。我們將能夠用自然語言隨意生成圖像、聲音、任何東西。全息甲板即將在我們的有生之年成為現實。
如果您有興趣進一步發展這項技術,請加入 Pytorch 或 Mesh Tensorflow 的 DALL-E 複製工作。
Big Sleep - CLIP 和 Big GAN 的生成器
@misc { unpublished2021clip ,
title = { CLIP: Connecting Text and Images } ,
author = { Alec Radford, Ilya Sutskever, Jong Wook Kim, Gretchen Krueger, Sandhini Agarwal } ,
year = { 2021 }
}
@misc { sitzmann2020implicit ,
title = { Implicit Neural Representations with Periodic Activation Functions } ,
author = { Vincent Sitzmann and Julien N. P. Martel and Alexander W. Bergman and David B. Lindell and Gordon Wetzstein } ,
year = { 2020 } ,
eprint = { 2006.09661 } ,
archivePrefix = { arXiv } ,
primaryClass = { cs.CV }
}