Skip to content

Commit

Permalink
update cam convention
Browse files Browse the repository at this point in the history
  • Loading branch information
ashawkey committed Dec 1, 2023
1 parent b895667 commit 7b1f675
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
25 changes: 25 additions & 0 deletions kiui/cam.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,31 @@
# elevation in (-90, 90), from +y (-90) --> -y (+90)
# azimuth in (-180, 180), from +z (0/-360) --> +x (90/-270) --> -z (180/-180) --> -x (270/-90) --> +z (360/0)

''' common world coordinate system conventions
OpenGL OpenCV Blender Unity
Right-handed Colmap Left-handed
+y +z +z +y +y +z
| / | / | /
| / | / | /
|______+x /______+x |/_____+x |/_____+x
/ |
/ |
/ |
+z +y
'''

''' camera pose matrix
[[Forward_x, Up_x, Right_x, Position_x],
[Forward_y, Up_y, Right_y, Position_y],
[Forward_z, Up_z, Right_z, Position_z],
[0, 0, 0, 1 ]]
The xyz follows corresponding world coordinate system.
'''


# look at rotation matrix
def look_at(campos, target, opengl=True):
# campos: [N, 3], camera/eye position
Expand Down
10 changes: 5 additions & 5 deletions kiui/cli/aes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, device, model_name='openai/clip-vit-large-patch14'):
self.processor = CLIPProcessor.from_pretrained(model_name)

def encode_image(self, image):
# image: PIL, np.ndarray uint8 [H, W, 3]
# image: PIL, np.ndarray uint8 [H, W, 3] or [B, H, W, 3]

pixel_values = self.processor(images=image, return_tensors="pt").pixel_values.to(self.device)
image_features = self.clip_model.get_image_features(pixel_values=pixel_values)
Expand Down Expand Up @@ -66,13 +66,13 @@ def __init__(self, device):


def __call__(self, x):
# x: np.ndarray, (h, w, 3), uint8, RGB
# x: np.ndarray, (h, w, 3) / (b, h, w, 3), uint8, RGB
# return: y: aesthetic score

features = self.clip.encode_image(x)
y = self.mlp(features)

return y.item()
return y


if __name__ == '__main__':
Expand All @@ -98,5 +98,5 @@ def __call__(self, x):
elif image.shape[-1] == 1:
image = np.concatenate([image] * 3, axis=-1)

aes_score = aes(image)
print(f'Aesthetic score: {aes_score:.3f} <-- {opt.image}')
aes_score = aes(image[None, :])
print(f'Aesthetic score: {aes_score} <-- {opt.image}')

0 comments on commit 7b1f675

Please sign in to comment.