lucidrains / deep-daze

Simple command line tool for text to image generation using OpenAI's CLIP and Siren (Implicit neural representation network). Technique was originally created by https://twitter.com/advadnoun
MIT License
4.37k stars 327 forks source link

How do I prime in Google Colab #122

Closed Flesco closed 3 years ago

Flesco commented 3 years ago

I tried to add a start_image_path variable in the simplified notebook, but getting this error: AttributeError 'Imagine' object has no attribute 'start_image_path'

NotNANtoN commented 3 years ago

Instead of setting the start_image_pathof an instance of the Imagine class, feed it as an additional parameter to when you create an instance e.g. model = Imagine("This is a test", start_image_path="hot-dog.jpg")

Flesco commented 3 years ago

Ok, the error is fixed, but it's ignoring the starting picture I provided. Sorry if there's an obvious mistake I'm making, I'm a noob. This is what the code looks like right now:

from tqdm.notebook import trange
from IPython.display import Image, display

from deep_daze import Imagine

TEXT = "test"
NUM_LAYERS = 32 #@param {type:"number"}
SAVE_EVERY =  5#@param {type:"number"}
IMAGE_WIDTH = 512 #@param {type:"number"}
SAVE_PROGRESS = True #@param {type:"boolean"}
LEARNING_RATE = 1e-5 #@param {type:"number"}
ITERATIONS = 1050 #@param {type:"number"}
START_IMAGE_PATH = '/content/test.jpg'

model = Imagine(text=TEXT, save_every=SAVE_EVERY, start_image_path=START_IMAGE_PATH)

for epoch in trange(20, desc = 'epochs'):
    for i in trange(ITERATIONS, desc = 'iteration'):
        model.train_step(epoch, i)

        if i % model.save_every != 0:
            continue

        filename = TEXT.replace(' ', '_')
        image = Image(f'./{filename}.jpg')
        display(image)
NotNANtoN commented 3 years ago

There is only pre-training based on the starting image if the forward method of the Imagine class is used.

Instead of your for-loop, simply call model()

Flesco commented 3 years ago

That worked, thank you!

NotNANtoN commented 3 years ago

Great, feel free to close this issue if you have no more questions! :)

nathanscomputerservice commented 3 years ago

Could you give a more beginner-friendly concrete example, or, Flesco, can you copy and paste the code you used? Thank you.

Flesco commented 3 years ago

@nathanscomputerservice here's the notebook with my code: https://drive.google.com/file/d/1K18m1EbWGGWVBAwIAWBjLx0ifGYCi7N2/view?usp=sharing