Views
No views yet
| Model Name | Control Image Overview | Control Image Example | Generated Image Example |
|---|---|---|---|
| TencentARC/t2iadapter_color_sd14v1 Trained with spatial color palette | A image with 8x8 color palette. | ![]() | ![]() |
| TencentARC/t2iadapter_canny_sd14v1 Trained with canny edge detection | A monochrome image with white edges on a black background. | ![]() | ![]() |
| TencentARC/t2iadapter_sketch_sd14v1 Trained with PidiNet edge detection | A hand-drawn monochrome image with white outlines on a black background. | ![]() | ![]() |
| TencentARC/t2iadapter_depth_sd14v1 Trained with Midas depth estimation | A grayscale image with black representing deep areas and white representing shallow areas. | ![]() | ![]() |
| TencentARC/t2iadapter_openpose_sd14v1 Trained with OpenPose bone image | A OpenPose bone image. | ![]() | ![]() |
| TencentARC/t2iadapter_keypose_sd14v1 Trained with mmpose skeleton image | A mmpose skeleton image. | ![]() | ![]() |
| TencentARC/t2iadapter_seg_sd14v1 Trained with semantic segmentation | An custom segmentation protocol image. | ![]() | ![]() |
| TencentARC/t2iadapter_canny_sd15v2 | |||
| TencentARC/t2iadapter_depth_sd15v2 | |||
| TencentARC/t2iadapter_sketch_sd15v2 | |||
| TencentARC/t2iadapter_zoedepth_sd15v1 |
pip install diffusers transformers matplotlib1from PIL import Image
2import torch
3import numpy as np
4import matplotlib
5from diffusers import T2IAdapter, StableDiffusionAdapterPipeline
6
7def colorize(value, vmin=None, vmax=None, cmap='gray_r', invalid_val=-99, invalid_mask=None, background_color=(128, 128, 128, 255), gamma_corrected=False, value_transform=None):
8 """Converts a depth map to a color image.
9
10 Args:
11 value (torch.Tensor, numpy.ndarry): Input depth map. Shape: (H, W) or (1, H, W) or (1, 1, H, W). All singular dimensions are squeezed
12 vmin (float, optional): vmin-valued entries are mapped to start color of cmap. If None, value.min() is used. Defaults to None.
13 vmax (float, optional): vmax-valued entries are mapped to end color of cmap. If None, value.max() is used. Defaults to None.
14 cmap (str, optional): matplotlib colormap to use. Defaults to 'magma_r'.
15 invalid_val (int, optional): Specifies value of invalid pixels that should be colored as 'background_color'. Defaults to -99.
16 invalid_mask (numpy.ndarray, optional): Boolean mask for invalid regions. Defaults to None.
17 background_color (tuple[int], optional): 4-tuple RGB color to give to invalid pixels. Defaults to (128, 128, 128, 255).
18 gamma_corrected (bool, optional): Apply gamma correction to colored image. Defaults to False.
19 value_transform (Callable, optional): Apply transform function to valid pixels before coloring. Defaults to None.
20
21 Returns:
22 numpy.ndarray, dtype - uint8: Colored depth map. Shape: (H, W, 4)
23 """
24 if isinstance(value, torch.Tensor):
25 value = value.detach().cpu().numpy()
26
27 value = value.squeeze()
28 if invalid_mask is None:
29 invalid_mask = value == invalid_val
30 mask = np.logical_not(invalid_mask)
31
32 # normalize
33 vmin = np.percentile(value[mask],2) if vmin is None else vmin
34 vmax = np.percentile(value[mask],85) if vmax is None else vmax
35 if vmin != vmax:
36 value = (value - vmin) / (vmax - vmin) # vmin..vmax
37 else:
38 # Avoid 0-division
39 value = value * 0.
40
41 # squeeze last dim if it exists
42 # grey out the invalid values
43
44 value[invalid_mask] = np.nan
45 cmapper = matplotlib.cm.get_cmap(cmap)
46 if value_transform:
47 value = value_transform(value)
48 # value = value / value.max()
49 value = cmapper(value, bytes=True) # (nxmx4)
50
51 img = value[...]
52 img[invalid_mask] = background_color
53
54 if gamma_corrected:
55 img = img / 255
56 img = np.power(img, 2.2)
57 img = img * 255
58 img = img.astype(np.uint8)
59 return img
60
61model = torch.hub.load("isl-org/ZoeDepth", "ZoeD_N", pretrained=True)
62
63img = Image.open('./images/zoedepth_in.png')
64
65out = model.infer_pil(img)
66
67zoedepth_image = Image.fromarray(colorize(out)).convert('RGB')
68
69zoedepth_image.save('images/zoedepth.png')
70
71adapter = T2IAdapter.from_pretrained("TencentARC/t2iadapter_zoedepth_sd15v1", torch_dtype=torch.float16)
72pipe = StableDiffusionAdapterPipeline.from_pretrained(
73 "runwayml/stable-diffusion-v1-5", adapter=adapter, safety_checker=None, torch_dtype=torch.float16, variant="fp16"
74)
75
76pipe.to('cuda')
77zoedepth_image_out = pipe(prompt="motorcycle", image=zoedepth_image).images[0]
78
79zoedepth_image_out.save('images/zoedepth_out.png')

