Download 1.py from slongle/3DEval: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/datasets/slongle/3DEval/resolve/main/1.py
- Command line
-
hf download hf://datasets/slongle/3DEval/1.py
-
curl -L -o 1.py https://huggingface.co/datasets/slongle/3DEval/resolve/main/1.py
1.1 kB
| import os | |
| import cv2 | |
| import numpy as np | |
| import ImageReward as RM | |
| from PIL import Image, ImageDraw, ImageFont | |
| def mkdir(path): | |
| if not os.path.exists(path): | |
| os.makedirs(path) | |
| def add_text_to_image(image, text, position): | |
| # position: X, Y coordinates | |
| image = Image.fromarray(image) | |
| draw = ImageDraw.Draw(image) | |
| font = ImageFont.load_default(size=30) | |
| draw.text(position, text, (255, 255, 255), font=font) | |
| image = np.array(image) | |
| return image | |
| model = RM.load("ImageReward-v1.0") | |
| root_dir = "/ibex/user/dengj/3DEval/GPTEval3D/data/tournament-3darena" | |
| prompt = "a cardboard spaceship" | |
| prompt_id = 25 | |
| method_0 = "Unique3D" | |
| method_1 = "InstantMesh" | |
| image_0_dir = os.path.join(root_dir, "methods", method_0, str(prompt_id), "0", "rgb_0.png") | |
| image_1_dir = os.path.join(root_dir, "methods", method_1, str(prompt_id), "0", "rgb_0.png") | |
| image_0 = cv2.imread(image_0_dir) | |
| image_1 = cv2.imread(image_1_dir) | |
| image = np.concatenate([image_0, image_1], axis=1) | |
| cv2.imwrite("test.png", image) | |
| rewards = model.score(prompt, [image_0_dir, image_1_dir]) | |
| print(rewards) | |