AUTOMATIC1111 / stable-diffusion-webui

Stable Diffusion web UI
GNU Affero General Public License v3.0
140.7k stars 26.62k forks source link

I used the same paramters and same safetensor,but my result is much worse than WebUI,ppppplease give me some advises! [Bug]: #16040

Closed OMTHSJUHW closed 3 months ago

OMTHSJUHW commented 3 months ago

Checklist

What happened?

I used the same paramters and same safetensor,but my result(by my code) is much worse than WebUI,ppppplease give me some advises! the way that i load the safetensor is wrong??? help!(all the safetensor or pt are download in my laptop)(here is code):

**import torch from diffusers import StableDiffusionPipeline from transformers import CLIPTextModel,CLIPModel,CLIPProcessor,CLIPTokenizer from safetensors.torch import load_file # 用于加载 .safetensors 文件 import os

pipe = StableDiffusionPipeline.from_single_file("./AI-ModelScope/anyloraCheckpoint_bakedvaeFp16NOT.safetensors",local_files_only=True,use_safetensors=True,load_safety_checker=False) pipe = pipe.to("cuda")

lora_path = "./Pokemon_LoRA/pokemon_v3_offset.safetensors"

lora_w = 1.0 pipe._lora_scale = lora_w state_dict, network_alphas = pipe.lora_state_dict( lora_path ) for key in network_alphas: network_alphas[key] = network_alphas[key] * lora_w

network_alpha = network_alpha * lora_w

pipe.load_lora_into_unet( state_dict = state_dict , network_alphas = network_alphas , unet = pipe.unet ) pipe.load_lora_into_text_encoder( state_dict = state_dict , network_alphas = network_alphas , text_encoder = pipe.text_encoder )

pipe.load_textual_inversion("./AI-ModelScope/By bad artist -neg.pt")

设置随机种子

seed = int(3187489596) generator = torch.Generator("cuda").manual_seed(seed)

生成图像

poke_prompt="sugimori ken (style), ghost and ground pokemon (creature), full body, gengar, marowak, solo, grin, half-closed eye, happy, highres, no humans, other focus, pokemon, purple eyes, simple background, smile, solo, standing, teeth, uneven eyes, white background , ((masterpiece))"

tokenizer = CLIPTokenizer.from_pretrained("./AI-ModelScope/clip-vit-large-patch14") text_encoder = CLIPTextModel.from_pretrained("./AI-ModelScope/clip-vit-large-patch14") pipe.text_encoder = text_encoder.to('cuda') pipe.tokenizer = tokenizer

image = pipe( prompt = poke_prompt, negative_prompt="(painting by bad-artist-anime:0.9), (painting by bad-artist:0.9), watermark, text, error, blurry, jpeg artifacts, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, artist name, (worst quality, low quality:1.4), bad anatomy", guidance_scale=9, num_inference_steps=200, generator=generator, sampler="dpm++_sde_karras", clip_skip=2, ).images[0]

保存生成的图像

output_path = f"./out.png" print(os.path.abspath("./out.png")) image.save(output_path)**

Steps to reproduce the problem

None

What should have happened?

None

What browsers do you use to access the UI ?

No response

Sysinfo

None

Console logs

None

Additional information

No response

light-and-ray commented 3 months ago

Do not use diffusers if you make an extension

You need to import

from modules.processing import StableDiffusionProcessingTxt2Img, process_images

Then create p

p = StableDiffusionProcessingTxt2Img(
    ...
)

Then process:

with closing(p):
    processed = process_images(p)

Then you can find images here

processed.images