cloneofsimo / paint-with-words-sd

Implementation of Paint-with-words with Stable Diffusion : method from eDiff-I that let you generate image from text-labeled segmentation map.
MIT License
636 stars 50 forks source link

token [3293] not found in text #13

Closed Masayoshi555 closed 2 years ago

Masayoshi555 commented 2 years ago

OS: Win11, CUDA, jupyternotebook

This issue happened to run test.py(original but almost same as "Basic Usage").

  1. Token (type: read) is set to .env
  2. .env is set to same folder as test.py
  3. CUDA &cuDNN is installed correctly
  4. diffusers simple script can run

I don't know why this script can't get token from ".env" file. Or, are there the other issue?

#test.py

import math
import os
import dotenv
from PIL import Image
from paint_with_words import paint_with_words

settings = {
    "color_context": {
        (7, 9, 175): "sky,1.0",
        (145, 177, 102): "moon,1.0",
        (98, 190, 214): "mountain,0.2",
        (90, 161, 58): "ground,0.2",
        (90, 102, 246): "lake,0.2"
    },
    "color_map_img_path": "input.png",
    "input_prompt": "realistic photo of a dog, cat, tree, with beautiful sky, on sandy ground",
    "output_img_path": "/output.png",
}

if __name__ == "__main__":

    try:

        dotenv.load_dotenv()

        color_map_image = Image.open(settings["color_map_img_path"]).convert("RGB")
        color_context = settings["color_context"]
        input_prompt = settings["input_prompt"]

        img = paint_with_words(
            color_context=color_context,
            color_map_image=color_map_image,
            input_prompt=input_prompt,
            num_inference_steps=30,
            guidance_scale=7.5,
            device="cuda:0",
            weight_function=lambda w, sigma, qk: 0.4 * w * math.log(1 + sigma) * qk.max(),
        )

        img.save(settings["output_img_path"])

    except Exception as e:
        print(e)

#output
CompVis/stable-diffusion-v1-4
CompVis/stable-diffusion-v1-4
Some weights of the model c....
......
.....
...
..
.
token [3293] not found in text
token [3293] not found in text
#diffusers simple script

from diffusers import StableDiffusionPipeline
import os

TOKEN = os.getenv("HF_TOKEN")

pipe = StableDiffusionPipeline.from_pretrained(
    "CompVis/stable-diffusion-v1-4", 
    use_auth_token=TOKEN
).to("cuda:0")

from torch import autocast

prompt = "cute cat with colorful eye, jumping on the grass."
with autocast("cuda"):
    images = pipe(prompt, guidance_scale=7.5).images
images[0].save("output.png")
hiss-remi commented 2 years ago

That error is because input_prompt doesn't contain "moon", "mountain", or "lake".

Masayoshi555 commented 2 years ago

Thank you for quickly and accuratery advising. The script worked fine when I included all the "color-context" words in the input-prompt. I had mistaken “token" for haggingface’s.

Thank you so much😊