sidnarsipur commited on
Commit
a245f78
1 Parent(s): 3627fc6

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +34 -13
README.md CHANGED
@@ -20,26 +20,47 @@ datasets:
20
  inference: true
21
  ---
22
 
23
- <!-- This model card has been generated automatically according to the information the training script had access to. You
24
- should probably proofread and complete it, then remove this comment. -->
25
 
 
26
 
27
- # controlnet_normal
28
 
29
- Estimate normal maps from basecolor maps.
 
30
 
31
- ## Intended uses & limitations
 
 
 
32
 
33
- #### How to use
 
 
34
 
35
- ```python
36
- # TODO: add an example code snippet for running this diffusion pipeline
37
- ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
- #### Limitations and bias
40
 
41
- [TODO: provide examples of latent issues and potential remediations]
 
 
 
42
 
43
- ## Training details
44
 
45
- [TODO: describe the data used to train the model]
 
20
  inference: true
21
  ---
22
 
23
+ # controlnet_normal
 
24
 
25
+ Generate a normal map from a photograph or basecolor (albedo) map.
26
 
27
+ # Usage
28
 
29
+ ```
30
+ import argparse
31
 
32
+ from PIL import Image
33
+ from diffusers import StableDiffusionControlNetPipeline, ControlNetModel, UniPCMultistepScheduler
34
+ from diffusers.utils import load_image
35
+ import torch
36
 
37
+ parser = argparse.ArgumentParser(description="Args for parser")
38
+ parser.add_argument("--seed", type=int, default=1, help="Seed for inference")
39
+ args = parser.parse_args()
40
 
41
+ base_model_path = "stabilityai/stable-diffusion-2-1-base"
42
+ controlnet_path = "sidnarsipur/controlnet_normal"
43
+
44
+ controlnet = ControlNetModel.from_pretrained(controlnet_path, torch_dtype=torch.float16)
45
+ pipe = StableDiffusionControlNetPipeline.from_pretrained(
46
+ base_model_path, controlnet=controlnet, torch_dtype=torch.float16
47
+ )
48
+
49
+ pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
50
+ pipe.enable_xformers_memory_efficient_attention()
51
+ pipe.enable_model_cpu_offload()
52
+
53
+ control_image = load_image("inference/basecolor.png") #Change based on your image path
54
+ prompt = "Normal Map" #Don't change!
55
+
56
+ if control_image.size[0] > 2048 or control_image.size[1] > 2048: #Optional
57
+ control_image = control_image.resize((control_image.size[0] // 2, control_image.size[1] // 2))
58
 
59
+ generator = torch.manual_seed(args.seed)
60
 
61
+ image = pipe(
62
+ prompt, num_inference_steps=50, generator=generator, image=control_image
63
+ ).images[0]
64
+ image.save("inference/normal.png")
65
 
 
66