|
|
import torch
|
|
|
from diffusers import StableDiffusionPipeline, UNet2DConditionModel, AutoencoderKL, DDPMScheduler
|
|
|
from transformers import CLIPTextModel, CLIPImageProcessor, AutoTokenizer
|
|
|
|
|
|
|
|
|
vae = AutoencoderKL.from_pretrained("./Model/finetuned_vae_v1_150_epoch_9")
|
|
|
unet = UNet2DConditionModel.from_pretrained("./Model/finetuned_crosswalk_model_v1_150_epoch_9")
|
|
|
|
|
|
scheduler = DDPMScheduler.from_pretrained("CompVis/stable-diffusion-v1-4", subfolder="scheduler")
|
|
|
|
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained("openai/clip-vit-large-patch14")
|
|
|
text_encoder = CLIPTextModel.from_pretrained("openai/clip-vit-large-patch14")
|
|
|
feature_extractor = CLIPImageProcessor.from_pretrained("openai/clip-vit-large-patch14")
|
|
|
|
|
|
|
|
|
pipeline = StableDiffusionPipeline(
|
|
|
vae=vae,
|
|
|
text_encoder=text_encoder,
|
|
|
tokenizer=tokenizer,
|
|
|
unet=unet,
|
|
|
scheduler=scheduler,
|
|
|
feature_extractor=feature_extractor,
|
|
|
safety_checker=None,
|
|
|
)
|
|
|
|
|
|
|
|
|
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
print ("Working with: ",device)
|
|
|
pipeline.to(device)
|
|
|
|
|
|
|
|
|
prompt = "a crosswalk image"
|
|
|
with torch.amp.autocast('cuda'):
|
|
|
image = pipeline(prompt, num_inference_steps=50, guidance_scale=9).images[0]
|
|
|
|
|
|
|
|
|
image.resize((640,360)).save("output.png")
|
|
|
image.resize((640,360)).show()
|
|
|
|
|
|
|
|
|
|