Nekochu commited on
Commit
f93b19e
·
verified ·
1 Parent(s): 5d73726

Add examples

Browse files
.gitattributes CHANGED
@@ -34,3 +34,7 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
  example.png filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
  example.png filter=lfs diff=lfs merge=lfs -text
37
+ example/aerial_rocks_02_diff_4k_Displacement.jpg filter=lfs diff=lfs merge=lfs -text
38
+ example/aerial_rocks_02_diff_4k_Normal.jpg filter=lfs diff=lfs merge=lfs -text
39
+ example/aerial_rocks_02_diff_4k_Roughness.jpg filter=lfs diff=lfs merge=lfs -text
40
+ example/aerial_rocks_02_diff_4k.jpg filter=lfs diff=lfs merge=lfs -text
app.py CHANGED
@@ -277,14 +277,13 @@ def load_models():
277
  def process_image(img, model):
278
  """Process a single image through the model."""
279
  img = np.array(img).astype(np.float32) / 255.0
280
- if len(img.shape) == 2: # Grayscale
281
- img = np.stack([img, img, img], axis=-1)
282
- if img.shape[2] == 4: # RGBA
283
- img = img[:, :, :3]
284
- img = torch.from_numpy(np.transpose(img.copy(), (2, 0, 1))).float().unsqueeze(0)
285
- output = model(img).squeeze(0).clamp_(0, 1).detach().numpy()
286
- output = np.transpose(output, (1, 2, 0)) # CHW to HWC
287
- return (output * 255).astype(np.uint8)
288
 
289
  def generate_maps(input_image):
290
  """Generate Normal, Roughness, and Displacement maps from input diffuse texture."""
@@ -318,4 +317,4 @@ if __name__ == "__main__":
318
  rough_out = gr.Image(label="Roughness", height=180)
319
  disp_out = gr.Image(label="Displacement", height=180)
320
  btn.click(fn=generate_maps, inputs=input_img, outputs=[normal_out, rough_out, disp_out])
321
- demo.launch(theme=gr.themes.Soft())
 
277
  def process_image(img, model):
278
  """Process a single image through the model."""
279
  img = np.array(img).astype(np.float32) / 255.0
280
+ if len(img.shape) == 2: img = np.stack([img, img, img], axis=-1)
281
+ if img.shape[2] == 4: img = img[:, :, :3]
282
+ tensor = torch.from_numpy(np.transpose(img.copy(), (2, 0, 1))).float().unsqueeze(0)
283
+ with torch.inference_mode():
284
+ output = model(tensor).squeeze(0).clamp_(0, 1).numpy()
285
+ del tensor # Explicit cleanup
286
+ return (np.transpose(output, (1, 2, 0)) * 255).astype(np.uint8)
 
287
 
288
  def generate_maps(input_image):
289
  """Generate Normal, Roughness, and Displacement maps from input diffuse texture."""
 
317
  rough_out = gr.Image(label="Roughness", height=180)
318
  disp_out = gr.Image(label="Displacement", height=180)
319
  btn.click(fn=generate_maps, inputs=input_img, outputs=[normal_out, rough_out, disp_out])
320
+ demo.launch(theme=gr.themes.Soft(), ssr_mode=False)
example/aerial_rocks_02_diff_4k.jpg ADDED

Git LFS Details

  • SHA256: 0358f1de07d18a71741d2e65caab814d1270a82528e61c3924e4a4ba8ff1e3d8
  • Pointer size: 131 Bytes
  • Size of remote file: 335 kB
example/aerial_rocks_02_diff_4k_Displacement.jpg ADDED

Git LFS Details

  • SHA256: c6f13826804fa45c18c13de9c9cf9822f34b92b3640fe010f90c06b670ceab50
  • Pointer size: 131 Bytes
  • Size of remote file: 226 kB
example/aerial_rocks_02_diff_4k_Normal.jpg ADDED

Git LFS Details

  • SHA256: 065eb18e1c9a22c86c5c7d2f7f56de2f34589baf955519412507e5a03126b98c
  • Pointer size: 131 Bytes
  • Size of remote file: 377 kB
example/aerial_rocks_02_diff_4k_Roughness.jpg ADDED

Git LFS Details

  • SHA256: 11266f863823cbfc776ce07c30530b7f3dcd3e790cf830ca0a42c80821a43632
  • Pointer size: 131 Bytes
  • Size of remote file: 288 kB