Instructions to use kiigii/imagedream-ipmv-diffusers with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use kiigii/imagedream-ipmv-diffusers with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("kiigii/imagedream-ipmv-diffusers", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
Delete camera_utils.py
Browse files- camera_utils.py +0 -88
camera_utils.py
DELETED
|
@@ -1,88 +0,0 @@
|
|
| 1 |
-
# Copied from ImageDream
|
| 2 |
-
# https://github.com/bytedance/ImageDream/blob/main/extern/ImageDream/imagedream/camera_utils.py
|
| 3 |
-
|
| 4 |
-
import numpy as np
|
| 5 |
-
import torch
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
def create_camera_to_world_matrix(elevation, azimuth):
|
| 9 |
-
elevation = np.radians(elevation)
|
| 10 |
-
azimuth = np.radians(azimuth)
|
| 11 |
-
# Convert elevation and azimuth angles to Cartesian coordinates on a unit sphere
|
| 12 |
-
x = np.cos(elevation) * np.sin(azimuth)
|
| 13 |
-
y = np.sin(elevation)
|
| 14 |
-
z = np.cos(elevation) * np.cos(azimuth)
|
| 15 |
-
|
| 16 |
-
# Calculate camera position, target, and up vectors
|
| 17 |
-
camera_pos = np.array([x, y, z])
|
| 18 |
-
target = np.array([0, 0, 0])
|
| 19 |
-
up = np.array([0, 1, 0])
|
| 20 |
-
|
| 21 |
-
# Construct view matrix
|
| 22 |
-
forward = target - camera_pos
|
| 23 |
-
forward /= np.linalg.norm(forward)
|
| 24 |
-
right = np.cross(forward, up)
|
| 25 |
-
right /= np.linalg.norm(right)
|
| 26 |
-
new_up = np.cross(right, forward)
|
| 27 |
-
new_up /= np.linalg.norm(new_up)
|
| 28 |
-
cam2world = np.eye(4)
|
| 29 |
-
cam2world[:3, :3] = np.array([right, new_up, -forward]).T
|
| 30 |
-
cam2world[:3, 3] = camera_pos
|
| 31 |
-
return cam2world
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
def convert_opengl_to_blender(camera_matrix):
|
| 35 |
-
if isinstance(camera_matrix, np.ndarray):
|
| 36 |
-
# Construct transformation matrix to convert from OpenGL space to Blender space
|
| 37 |
-
flip_yz = np.array([[1, 0, 0, 0], [0, 0, -1, 0], [0, 1, 0, 0], [0, 0, 0, 1]])
|
| 38 |
-
camera_matrix_blender = np.dot(flip_yz, camera_matrix)
|
| 39 |
-
else:
|
| 40 |
-
# Construct transformation matrix to convert from OpenGL space to Blender space
|
| 41 |
-
flip_yz = torch.tensor(
|
| 42 |
-
[[1, 0, 0, 0], [0, 0, -1, 0], [0, 1, 0, 0], [0, 0, 0, 1]]
|
| 43 |
-
)
|
| 44 |
-
if camera_matrix.ndim == 3:
|
| 45 |
-
flip_yz = flip_yz.unsqueeze(0)
|
| 46 |
-
camera_matrix_blender = torch.matmul(flip_yz.to(camera_matrix), camera_matrix)
|
| 47 |
-
return camera_matrix_blender
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
def normalize_camera(camera_matrix):
|
| 51 |
-
"""normalize the camera location onto a unit-sphere"""
|
| 52 |
-
if isinstance(camera_matrix, np.ndarray):
|
| 53 |
-
camera_matrix = camera_matrix.reshape(-1, 4, 4)
|
| 54 |
-
translation = camera_matrix[:, :3, 3]
|
| 55 |
-
translation = translation / (
|
| 56 |
-
np.linalg.norm(translation, axis=1, keepdims=True) + 1e-8
|
| 57 |
-
)
|
| 58 |
-
camera_matrix[:, :3, 3] = translation
|
| 59 |
-
else:
|
| 60 |
-
camera_matrix = camera_matrix.reshape(-1, 4, 4)
|
| 61 |
-
translation = camera_matrix[:, :3, 3]
|
| 62 |
-
translation = translation / (
|
| 63 |
-
torch.norm(translation, dim=1, keepdim=True) + 1e-8
|
| 64 |
-
)
|
| 65 |
-
camera_matrix[:, :3, 3] = translation
|
| 66 |
-
return camera_matrix.reshape(-1, 16)
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
def get_camera(
|
| 70 |
-
num_frames,
|
| 71 |
-
elevation=15,
|
| 72 |
-
azimuth_start=0,
|
| 73 |
-
azimuth_span=360,
|
| 74 |
-
blender_coord=True,
|
| 75 |
-
extra_view=False,
|
| 76 |
-
):
|
| 77 |
-
angle_gap = azimuth_span / num_frames
|
| 78 |
-
cameras = []
|
| 79 |
-
for azimuth in np.arange(azimuth_start, azimuth_span + azimuth_start, angle_gap):
|
| 80 |
-
camera_matrix = create_camera_to_world_matrix(elevation, azimuth)
|
| 81 |
-
if blender_coord:
|
| 82 |
-
camera_matrix = convert_opengl_to_blender(camera_matrix)
|
| 83 |
-
cameras.append(camera_matrix.flatten())
|
| 84 |
-
|
| 85 |
-
if extra_view:
|
| 86 |
-
dim = len(cameras[0])
|
| 87 |
-
cameras.append(np.zeros(dim))
|
| 88 |
-
return torch.tensor(np.stack(cameras, 0)).float()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|