Created
September 11, 2023 09:57
-
-
Save noskill/649557c19122b200d1a360c70b3687a0 to your computer and use it in GitHub Desktop.
generate mech warrior image with diffusers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
import random | |
from diffusers import StableDiffusionKDiffusionPipeline | |
from diffusers import StableDiffusionPipeline, StableDiffusionLatentUpscalePipeline | |
from transformers import CLIPProcessor, CLIPTextModel | |
from diffusers.schedulers import DPMSolverMultistepScheduler | |
class MyPipe: | |
def __init__(self, model_id, dtype=torch.float16): | |
self.pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=dtype) | |
# we skip 2 layers of the encoder | |
self.pipe.text_encoder = CLIPTextModel.from_pretrained(model_id, subfolder="text_encoder", num_hidden_layers=10, torch_dtype=dtype) | |
# self.pipe.set_scheduler('sample_dpmpp_2m') # it's like DPM++2M Karras, doesnt work with long prompt weighting | |
self.pipe.scheduler = DPMSolverMultistepScheduler.from_config(self.pipe.scheduler.config) | |
self.pipe.to("cuda") | |
self.pipe.vae.enable_tiling() | |
def get_pipline_description(self): | |
pass | |
def gen(self, inputs, upscale=False): | |
if 'seed' in inputs: | |
inputs['generator'] = torch.Generator("cuda").manual_seed(inputs.pop('seed')) | |
image = self.pipe(**inputs).images[0] | |
return image | |
if __name__ == '__main__': | |
path = "/home/imgen/models/icb_diffusers_final/" | |
path = "/home/imgen/models/icb_diffusers/" | |
p = MyPipe(path, dtype=torch.float32) | |
seed = 2001481868 | |
inputs = dict() | |
inputs['seed'] = seed | |
inputs['guidance_scale'] = 4.5 | |
inputs['height'] = 1024 | |
inputs['width'] = 512 | |
inputs['num_inference_steps'] = 25 | |
inputs['prompt'] = 'close up Portrait photo of muscular bearded guy in a worn mech suit, (snow:1.4) , ((light bokeh)), intricate, (steel metal [rust]), elegant, sharp focus, photo by greg rutkowski, soft lighting, vibrant colors, masterpiece, ((streets)), detailed face' | |
inputs['negative_prompt'] = 'nude, cross eyed, tongue, open mouth, inside, 3d, cartoon, anime, sketches, (worst quality:2), (low quality:2), (normal quality:2), lowres, normal quality, ((monochrome)), ((grayscale)), skin spots, acnes, skin blemishes, bad anatomy, red eyes, muscular' | |
# inputs['use_karras_sigmas'] = True | |
image = p.gen(inputs) | |
image.save('mech_beard.jpeg', comment='snvlfjvnf' * 100, quality=100, subsampling=0) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment