mattdeitke
commited on
Commit
·
d6b9526
1
Parent(s):
f313dd0
naming updates
Browse files- objaverse_xl/github.py +36 -40
- scripts/rendering/main.py +98 -89
objaverse_xl/github.py
CHANGED
@@ -180,10 +180,9 @@ def _process_repo(
|
|
180 |
if handle_missing_object is not None:
|
181 |
for github_url, sha256 in expected_objects.items():
|
182 |
handle_missing_object(
|
183 |
-
|
184 |
sha256=sha256,
|
185 |
-
|
186 |
-
organization=org,
|
187 |
)
|
188 |
return []
|
189 |
|
@@ -232,7 +231,7 @@ def _process_repo(
|
|
232 |
|
233 |
# get the sha256 for each file
|
234 |
file_hashes = []
|
235 |
-
for file in files_with_3d_extension:
|
236 |
file_hash = get_file_hash(file)
|
237 |
# remove the temp_dir from the file path
|
238 |
github_url = file.replace(
|
@@ -246,28 +245,26 @@ def _process_repo(
|
|
246 |
if expected_objects[github_url] == file_hash:
|
247 |
if handle_found_object is not None:
|
248 |
handle_found_object(
|
249 |
-
|
250 |
-
|
251 |
sha256=file_hash,
|
252 |
-
|
253 |
-
organization=org,
|
254 |
)
|
255 |
else:
|
256 |
if handle_modified_object is not None:
|
257 |
handle_modified_object(
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
)
|
264 |
elif handle_new_object is not None:
|
265 |
handle_new_object(
|
266 |
-
|
267 |
-
|
268 |
sha256=file_hash,
|
269 |
-
|
270 |
-
organization=org,
|
271 |
)
|
272 |
|
273 |
# save the file hashes to a json file
|
@@ -319,10 +316,9 @@ def _process_repo(
|
|
319 |
for github_url, sha256 in expected_objects.items():
|
320 |
if github_url not in obtained_urls:
|
321 |
handle_missing_object(
|
322 |
-
|
323 |
sha256=sha256,
|
324 |
-
|
325 |
-
organization=org,
|
326 |
)
|
327 |
|
328 |
return file_hashes
|
@@ -434,24 +430,22 @@ def download_github_objects(
|
|
434 |
successfully found and downloaded. Here, the object has the same sha256 as
|
435 |
the one that was downloaded with Objaverse-XL. If None, the object will be
|
436 |
downloaded, but nothing will be done with it. Args for the function include:
|
437 |
-
-
|
438 |
-
-
|
439 |
- sha256 (str): SHA256 of the contents of the 3D object.
|
440 |
-
-
|
441 |
-
|
442 |
-
comes from.
|
443 |
Return is not used. Defaults to None.
|
444 |
handle_new_object (Optional[Callable], optional): Called when a new object is
|
445 |
found. Here, the object is not used in Objaverse-XL, but is still downloaded
|
446 |
with the repository. The object may have not been used because it does not
|
447 |
successfully import into Blender. If None, the object will be downloaded,
|
448 |
but nothing will be done with it. Args for the function include:
|
449 |
-
-
|
450 |
-
-
|
451 |
- sha256 (str): SHA256 of the contents of the 3D object.
|
452 |
-
-
|
453 |
-
|
454 |
-
comes from.
|
455 |
Return is not used. Defaults to None.
|
456 |
handle_modified_object (Optional[Callable], optional): Called when a modified
|
457 |
object is found and downloaded. Here, the object is successfully downloaded,
|
@@ -459,21 +453,23 @@ def download_github_objects(
|
|
459 |
Objaverse-XL. This is not expected to happen very often, because the same
|
460 |
commit hash is used for each repo. If None, the object will be downloaded,
|
461 |
but nothing will be done with it. Args for the function include:
|
462 |
-
-
|
463 |
-
-
|
464 |
-
-
|
465 |
-
|
466 |
-
-
|
467 |
-
|
|
|
|
|
468 |
Return is not used. Defaults to None.
|
469 |
handle_missing_object (Optional[Callable], optional): Called when an object that
|
470 |
is in Objaverse-XL is not found. Here, it is likely that the repository was
|
471 |
deleted or renamed. If None, nothing will be done with the missing object.
|
472 |
Args for the function include:
|
473 |
-
-
|
474 |
- sha256 (str): SHA256 of the contents of the original 3D object.
|
475 |
-
-
|
476 |
-
|
477 |
Return is not used. Defaults to None.
|
478 |
|
479 |
Returns:
|
@@ -531,7 +527,7 @@ def download_github_objects(
|
|
531 |
]
|
532 |
|
533 |
logger.info(
|
534 |
-
f"Found {len(repo_ids_to_download)} not yet downloaded. Downloading now..."
|
535 |
)
|
536 |
|
537 |
# get the objects to download
|
|
|
180 |
if handle_missing_object is not None:
|
181 |
for github_url, sha256 in expected_objects.items():
|
182 |
handle_missing_object(
|
183 |
+
file_identifier=github_url,
|
184 |
sha256=sha256,
|
185 |
+
metadata=dict(github_organization=org, github_repo=repo),
|
|
|
186 |
)
|
187 |
return []
|
188 |
|
|
|
231 |
|
232 |
# get the sha256 for each file
|
233 |
file_hashes = []
|
234 |
+
for file in tqdm(files_with_3d_extension, desc="Handling 3D object files"):
|
235 |
file_hash = get_file_hash(file)
|
236 |
# remove the temp_dir from the file path
|
237 |
github_url = file.replace(
|
|
|
245 |
if expected_objects[github_url] == file_hash:
|
246 |
if handle_found_object is not None:
|
247 |
handle_found_object(
|
248 |
+
local_path=file,
|
249 |
+
file_identifier=github_url,
|
250 |
sha256=file_hash,
|
251 |
+
metadata=dict(github_organization=org, github_repo=repo),
|
|
|
252 |
)
|
253 |
else:
|
254 |
if handle_modified_object is not None:
|
255 |
handle_modified_object(
|
256 |
+
local_path=file,
|
257 |
+
file_identifier=github_url,
|
258 |
+
new_sha256=file_hash,
|
259 |
+
old_sha256=expected_objects[github_url],
|
260 |
+
metadata=dict(github_organization=org, github_repo=repo),
|
261 |
)
|
262 |
elif handle_new_object is not None:
|
263 |
handle_new_object(
|
264 |
+
local_path=file,
|
265 |
+
file_identifier=github_url,
|
266 |
sha256=file_hash,
|
267 |
+
metadata=dict(github_organization=org, github_repo=repo),
|
|
|
268 |
)
|
269 |
|
270 |
# save the file hashes to a json file
|
|
|
316 |
for github_url, sha256 in expected_objects.items():
|
317 |
if github_url not in obtained_urls:
|
318 |
handle_missing_object(
|
319 |
+
file_identifier=github_url,
|
320 |
sha256=sha256,
|
321 |
+
metadata=dict(github_organization=org, github_repo=repo),
|
|
|
322 |
)
|
323 |
|
324 |
return file_hashes
|
|
|
430 |
successfully found and downloaded. Here, the object has the same sha256 as
|
431 |
the one that was downloaded with Objaverse-XL. If None, the object will be
|
432 |
downloaded, but nothing will be done with it. Args for the function include:
|
433 |
+
- local_path (str): Local path to the downloaded 3D object.
|
434 |
+
- file_identifier (str): GitHub URL of the 3D object.
|
435 |
- sha256 (str): SHA256 of the contents of the 3D object.
|
436 |
+
- metadata (Dict[str, Any]): Metadata about the 3D object, including the
|
437 |
+
GitHub organization and repo names.
|
|
|
438 |
Return is not used. Defaults to None.
|
439 |
handle_new_object (Optional[Callable], optional): Called when a new object is
|
440 |
found. Here, the object is not used in Objaverse-XL, but is still downloaded
|
441 |
with the repository. The object may have not been used because it does not
|
442 |
successfully import into Blender. If None, the object will be downloaded,
|
443 |
but nothing will be done with it. Args for the function include:
|
444 |
+
- local_path (str): Local path to the downloaded 3D object.
|
445 |
+
- file_identifier (str): GitHub URL of the 3D object.
|
446 |
- sha256 (str): SHA256 of the contents of the 3D object.
|
447 |
+
- metadata (Dict[str, Any]): Metadata about the 3D object, including the
|
448 |
+
GitHub organization and repo names.
|
|
|
449 |
Return is not used. Defaults to None.
|
450 |
handle_modified_object (Optional[Callable], optional): Called when a modified
|
451 |
object is found and downloaded. Here, the object is successfully downloaded,
|
|
|
453 |
Objaverse-XL. This is not expected to happen very often, because the same
|
454 |
commit hash is used for each repo. If None, the object will be downloaded,
|
455 |
but nothing will be done with it. Args for the function include:
|
456 |
+
- local_path (str): Local path to the downloaded 3D object.
|
457 |
+
- file_identifier (str): GitHub URL of the 3D object.
|
458 |
+
- new_sha256 (str): SHA256 of the contents of the newly downloaded 3D
|
459 |
+
object.
|
460 |
+
- old_sha256 (str): Expected SHA256 of the contents of the 3D object as it
|
461 |
+
was when it was downloaded with Objaverse-XL.
|
462 |
+
- metadata (Dict[str, Any]): Metadata about the 3D object, including the
|
463 |
+
GitHub organization and repo names.
|
464 |
Return is not used. Defaults to None.
|
465 |
handle_missing_object (Optional[Callable], optional): Called when an object that
|
466 |
is in Objaverse-XL is not found. Here, it is likely that the repository was
|
467 |
deleted or renamed. If None, nothing will be done with the missing object.
|
468 |
Args for the function include:
|
469 |
+
- file_identifier (str): GitHub URL of the 3D object.
|
470 |
- sha256 (str): SHA256 of the contents of the original 3D object.
|
471 |
+
- metadata (Dict[str, Any]): Metadata about the 3D object, including the
|
472 |
+
GitHub organization and repo names.
|
473 |
Return is not used. Defaults to None.
|
474 |
|
475 |
Returns:
|
|
|
527 |
]
|
528 |
|
529 |
logger.info(
|
530 |
+
f"Found {len(repo_ids_to_download)} repoIds not yet downloaded. Downloading now..."
|
531 |
)
|
532 |
|
533 |
# get the objects to download
|
scripts/rendering/main.py
CHANGED
@@ -9,7 +9,7 @@ import tempfile
|
|
9 |
import time
|
10 |
import zipfile
|
11 |
from functools import partial
|
12 |
-
from typing import List, Literal, Optional, Union
|
13 |
|
14 |
import fire
|
15 |
import fsspec
|
@@ -21,23 +21,23 @@ from objaverse_xl.github import download_github_objects
|
|
21 |
from objaverse_xl.utils import get_uid_from_str
|
22 |
|
23 |
|
24 |
-
def log_processed_object(
|
25 |
"""Log when an object is done being used.
|
26 |
|
27 |
Args:
|
28 |
-
object_id (str): ID of the object.
|
29 |
-
sha256 (str): SHA256 of the object.
|
30 |
csv_filename (str): Name of the CSV file to save the logs to.
|
|
|
31 |
|
32 |
Returns:
|
33 |
None
|
34 |
"""
|
|
|
35 |
# log that this object was rendered successfully
|
36 |
# saving locally to avoid excessive writes to the cloud
|
37 |
dirname = os.path.expanduser(f"~/.objaverse/github/logs/")
|
38 |
os.makedirs(dirname, exist_ok=True)
|
39 |
with open(os.path.join(dirname, csv_filename), "a", encoding="utf-8") as f:
|
40 |
-
f.write(f"{time.time()},{
|
41 |
|
42 |
|
43 |
def zipdir(path: str, ziph: zipfile.ZipFile) -> None:
|
@@ -59,19 +59,18 @@ def zipdir(path: str, ziph: zipfile.ZipFile) -> None:
|
|
59 |
|
60 |
|
61 |
def handle_found_object(
|
62 |
-
|
63 |
-
|
64 |
sha256: str,
|
65 |
-
|
66 |
-
organization: str,
|
67 |
num_renders: int,
|
68 |
render_dir: str,
|
69 |
only_northern_hemisphere: bool,
|
70 |
gpu_devices: Union[int, List[int]],
|
71 |
render_timeout: int,
|
72 |
-
successful_log_file: str = "handle-found-object-successful.csv",
|
73 |
-
failed_log_file: str = "handle-found-object-failed.csv",
|
74 |
-
) ->
|
75 |
"""Called when an object is successfully found and downloaded.
|
76 |
|
77 |
Here, the object has the same sha256 as the one that was downloaded with
|
@@ -79,12 +78,11 @@ def handle_found_object(
|
|
79 |
it.
|
80 |
|
81 |
Args:
|
82 |
-
|
83 |
-
|
84 |
sha256 (str): SHA256 of the contents of the 3D object.
|
85 |
-
|
86 |
-
|
87 |
-
comes from.
|
88 |
num_renders (int): Number of renders to save of the object.
|
89 |
render_dir (str): Directory where the objects will be rendered.
|
90 |
only_northern_hemisphere (bool): Only render the northern hemisphere of the
|
@@ -98,11 +96,10 @@ def handle_found_object(
|
|
98 |
successful_log_file (str): Name of the log file to save successful renders to.
|
99 |
failed_log_file (str): Name of the log file to save failed renders to.
|
100 |
|
101 |
-
Returns:
|
102 |
-
None
|
103 |
"""
|
104 |
-
save_uid = get_uid_from_str(
|
105 |
-
args = f"--object_path '{
|
106 |
|
107 |
# get the GPU to use for rendering
|
108 |
using_gpu: bool = True
|
@@ -147,8 +144,14 @@ def handle_found_object(
|
|
147 |
if using_gpu:
|
148 |
command = f"export DISPLAY=:0.{gpu_i} && {command}"
|
149 |
|
150 |
-
# render the object
|
151 |
-
subprocess.run(
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
|
153 |
# check that the renders were saved successfully
|
154 |
png_files = glob.glob(os.path.join(target_directory, "*.png"))
|
@@ -159,25 +162,34 @@ def handle_found_object(
|
|
159 |
or (len(npy_files) != num_renders)
|
160 |
or (len(metadata_files) != 1)
|
161 |
):
|
162 |
-
logger.error(
|
163 |
-
|
164 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
165 |
|
166 |
# update the metadata
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
|
|
|
|
174 |
|
175 |
# Make a zip of the target_directory.
|
176 |
# Keeps the {save_uid} directory structure when unzipped
|
177 |
with zipfile.ZipFile(
|
178 |
f"{target_directory}.zip", "w", zipfile.ZIP_DEFLATED
|
179 |
-
) as
|
180 |
-
zipdir(target_directory,
|
181 |
|
182 |
# move the zip to the render_dir
|
183 |
fs, path = fsspec.core.url_to_fs(render_dir)
|
@@ -190,15 +202,17 @@ def handle_found_object(
|
|
190 |
)
|
191 |
|
192 |
# log that this object was rendered successfully
|
193 |
-
|
|
|
|
|
|
|
194 |
|
195 |
|
196 |
def handle_new_object(
|
197 |
-
|
198 |
-
|
199 |
sha256: str,
|
200 |
-
|
201 |
-
organization: str,
|
202 |
log_file: str = "handle-new-object.csv",
|
203 |
) -> None:
|
204 |
"""Called when a new object is found.
|
@@ -209,27 +223,26 @@ def handle_new_object(
|
|
209 |
done with it.
|
210 |
|
211 |
Args:
|
212 |
-
|
213 |
-
|
214 |
sha256 (str): SHA256 of the contents of the 3D object.
|
215 |
-
|
216 |
-
|
217 |
-
comes from.
|
218 |
log_file (str): Name of the log file to save the handle_new_object logs to.
|
219 |
|
220 |
Returns:
|
221 |
None
|
222 |
"""
|
223 |
# log the new object
|
224 |
-
log_processed_object(
|
225 |
|
226 |
|
227 |
def handle_modified_object(
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
num_renders: int,
|
234 |
render_dir: str,
|
235 |
only_northern_hemisphere: bool,
|
@@ -244,12 +257,13 @@ def handle_modified_object(
|
|
244 |
be downloaded, but nothing will be done with it.
|
245 |
|
246 |
Args:
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
|
|
253 |
num_renders (int): Number of renders to save of the object.
|
254 |
render_dir (str): Directory where the objects will be rendered.
|
255 |
only_northern_hemisphere (bool): Only render the northern hemisphere of the
|
@@ -264,27 +278,40 @@ def handle_modified_object(
|
|
264 |
Returns:
|
265 |
None
|
266 |
"""
|
267 |
-
handle_found_object(
|
268 |
-
|
269 |
-
|
270 |
-
sha256=
|
271 |
-
|
272 |
-
organization=organization,
|
273 |
num_renders=num_renders,
|
274 |
render_dir=render_dir,
|
275 |
only_northern_hemisphere=only_northern_hemisphere,
|
276 |
gpu_devices=gpu_devices,
|
277 |
render_timeout=render_timeout,
|
278 |
-
successful_log_file=
|
279 |
-
failed_log_file=
|
280 |
)
|
281 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
282 |
|
283 |
def handle_missing_object(
|
284 |
github_url: str,
|
285 |
sha256: str,
|
286 |
-
|
287 |
-
organization: str,
|
288 |
log_file: str = "handle-missing-object.csv",
|
289 |
) -> None:
|
290 |
"""Called when an object that is in Objaverse-XL is not found.
|
@@ -295,38 +322,20 @@ def handle_missing_object(
|
|
295 |
Args:
|
296 |
github_url (str): GitHub URL of the 3D object.
|
297 |
sha256 (str): SHA256 of the contents of the original 3D object.
|
298 |
-
|
299 |
-
|
300 |
log_file (str): Name of the log file to save missing renders to.
|
301 |
|
302 |
Returns:
|
303 |
None
|
304 |
"""
|
305 |
# log the missing object
|
306 |
-
log_processed_object(github_url, sha256
|
307 |
|
308 |
|
309 |
def get_example_objects() -> pd.DataFrame:
|
310 |
"""Returns a DataFrame of example objects to use for debugging."""
|
311 |
-
return pd.
|
312 |
-
[
|
313 |
-
{
|
314 |
-
"githubUrl": "https://github.com/mattdeitke/objaverse-xl-test-files/blob/6928b08a2501aa7a4a4aabac1f888b66e7782056/example.fbx",
|
315 |
-
"license": None,
|
316 |
-
"sha256": "7037575f47816118e5a34e7c0da9927e1be7be3f5b4adfac337710822eb50fa9",
|
317 |
-
},
|
318 |
-
{
|
319 |
-
"githubUrl": "https://github.com/mattdeitke/objaverse-xl-test-files/blob/6928b08a2501aa7a4a4aabac1f888b66e7782056/example.glb",
|
320 |
-
"license": None,
|
321 |
-
"sha256": "04e6377317d6818e32c5cbd1951e76deb3641bbf4f6db6933046221d5fbf1c5c",
|
322 |
-
},
|
323 |
-
{
|
324 |
-
"githubUrl": "https://github.com/mattdeitke/objaverse-xl-test-files/blob/6928b08a2501aa7a4a4aabac1f888b66e7782056/example.obj",
|
325 |
-
"license": None,
|
326 |
-
"sha256": "d2b9a5d7c47dc93526082c9b630157ab6bce4fd8669610d942176f4a36444e71",
|
327 |
-
},
|
328 |
-
]
|
329 |
-
)
|
330 |
|
331 |
|
332 |
def render_github_objects(
|
|
|
9 |
import time
|
10 |
import zipfile
|
11 |
from functools import partial
|
12 |
+
from typing import List, Literal, Optional, Union, Dict, Any, Callable
|
13 |
|
14 |
import fire
|
15 |
import fsspec
|
|
|
21 |
from objaverse_xl.utils import get_uid_from_str
|
22 |
|
23 |
|
24 |
+
def log_processed_object(csv_filename: str, *args) -> None:
|
25 |
"""Log when an object is done being used.
|
26 |
|
27 |
Args:
|
|
|
|
|
28 |
csv_filename (str): Name of the CSV file to save the logs to.
|
29 |
+
*args: Arguments to save to the CSV file.
|
30 |
|
31 |
Returns:
|
32 |
None
|
33 |
"""
|
34 |
+
args = ",".join([str(arg) for arg in args])
|
35 |
# log that this object was rendered successfully
|
36 |
# saving locally to avoid excessive writes to the cloud
|
37 |
dirname = os.path.expanduser(f"~/.objaverse/github/logs/")
|
38 |
os.makedirs(dirname, exist_ok=True)
|
39 |
with open(os.path.join(dirname, csv_filename), "a", encoding="utf-8") as f:
|
40 |
+
f.write(f"{time.time()},{args}\n")
|
41 |
|
42 |
|
43 |
def zipdir(path: str, ziph: zipfile.ZipFile) -> None:
|
|
|
59 |
|
60 |
|
61 |
def handle_found_object(
|
62 |
+
local_path: str,
|
63 |
+
file_identifier: str,
|
64 |
sha256: str,
|
65 |
+
metadata: Dict[str, Any],
|
|
|
66 |
num_renders: int,
|
67 |
render_dir: str,
|
68 |
only_northern_hemisphere: bool,
|
69 |
gpu_devices: Union[int, List[int]],
|
70 |
render_timeout: int,
|
71 |
+
successful_log_file: Optional[str] = "handle-found-object-successful.csv",
|
72 |
+
failed_log_file: Optional[str] = "handle-found-object-failed.csv",
|
73 |
+
) -> bool:
|
74 |
"""Called when an object is successfully found and downloaded.
|
75 |
|
76 |
Here, the object has the same sha256 as the one that was downloaded with
|
|
|
78 |
it.
|
79 |
|
80 |
Args:
|
81 |
+
local_path (str): Local path to the downloaded 3D object.
|
82 |
+
file_identifier (str): GitHub URL of the 3D object.
|
83 |
sha256 (str): SHA256 of the contents of the 3D object.
|
84 |
+
metadata (Dict[str, Any]): Metadata about the 3D object, including keys for
|
85 |
+
`github_organization` and `github_repo`.
|
|
|
86 |
num_renders (int): Number of renders to save of the object.
|
87 |
render_dir (str): Directory where the objects will be rendered.
|
88 |
only_northern_hemisphere (bool): Only render the northern hemisphere of the
|
|
|
96 |
successful_log_file (str): Name of the log file to save successful renders to.
|
97 |
failed_log_file (str): Name of the log file to save failed renders to.
|
98 |
|
99 |
+
Returns: True if the object was rendered successfully, False otherwise.
|
|
|
100 |
"""
|
101 |
+
save_uid = get_uid_from_str(file_identifier)
|
102 |
+
args = f"--object_path '{local_path}' --num_renders {num_renders}"
|
103 |
|
104 |
# get the GPU to use for rendering
|
105 |
using_gpu: bool = True
|
|
|
144 |
if using_gpu:
|
145 |
command = f"export DISPLAY=:0.{gpu_i} && {command}"
|
146 |
|
147 |
+
# render the object (put in dev null)
|
148 |
+
subprocess.run(
|
149 |
+
["bash", "-c", command],
|
150 |
+
timeout=render_timeout,
|
151 |
+
check=False,
|
152 |
+
stdout=subprocess.DEVNULL,
|
153 |
+
stderr=subprocess.DEVNULL,
|
154 |
+
)
|
155 |
|
156 |
# check that the renders were saved successfully
|
157 |
png_files = glob.glob(os.path.join(target_directory, "*.png"))
|
|
|
162 |
or (len(npy_files) != num_renders)
|
163 |
or (len(metadata_files) != 1)
|
164 |
):
|
165 |
+
logger.error(
|
166 |
+
f"Found object {file_identifier} was not rendered successfully!"
|
167 |
+
)
|
168 |
+
if failed_log_file is not None:
|
169 |
+
log_processed_object(
|
170 |
+
failed_log_file,
|
171 |
+
file_identifier,
|
172 |
+
sha256,
|
173 |
+
)
|
174 |
+
return False
|
175 |
|
176 |
# update the metadata
|
177 |
+
metadata_path = os.path.join(target_directory, "metadata.json")
|
178 |
+
with open(metadata_path, "r", encoding="utf-8") as f:
|
179 |
+
metadata_file = json.load(f)
|
180 |
+
metadata_file["sha256"] = sha256
|
181 |
+
metadata_file["file_identifier"] = file_identifier
|
182 |
+
metadata_file["save_uid"] = save_uid
|
183 |
+
metadata_file["metadata"] = metadata
|
184 |
+
with open(metadata_path, "w", encoding="utf-8") as f:
|
185 |
+
json.dump(metadata, f, indent=2, sort_keys=True)
|
186 |
|
187 |
# Make a zip of the target_directory.
|
188 |
# Keeps the {save_uid} directory structure when unzipped
|
189 |
with zipfile.ZipFile(
|
190 |
f"{target_directory}.zip", "w", zipfile.ZIP_DEFLATED
|
191 |
+
) as ziph:
|
192 |
+
zipdir(target_directory, ziph)
|
193 |
|
194 |
# move the zip to the render_dir
|
195 |
fs, path = fsspec.core.url_to_fs(render_dir)
|
|
|
202 |
)
|
203 |
|
204 |
# log that this object was rendered successfully
|
205 |
+
if successful_log_file is not None:
|
206 |
+
log_processed_object(successful_log_file, file_identifier, sha256)
|
207 |
+
|
208 |
+
return True
|
209 |
|
210 |
|
211 |
def handle_new_object(
|
212 |
+
local_path: str,
|
213 |
+
file_identifier: str,
|
214 |
sha256: str,
|
215 |
+
metadata: Dict[str, Any],
|
|
|
216 |
log_file: str = "handle-new-object.csv",
|
217 |
) -> None:
|
218 |
"""Called when a new object is found.
|
|
|
223 |
done with it.
|
224 |
|
225 |
Args:
|
226 |
+
local_path (str): Local path to the downloaded 3D object.
|
227 |
+
file_identifier (str): GitHub URL of the 3D object.
|
228 |
sha256 (str): SHA256 of the contents of the 3D object.
|
229 |
+
metadata (Dict[str, Any]): Metadata about the 3D object, including the GitHub
|
230 |
+
organization and repo names.
|
|
|
231 |
log_file (str): Name of the log file to save the handle_new_object logs to.
|
232 |
|
233 |
Returns:
|
234 |
None
|
235 |
"""
|
236 |
# log the new object
|
237 |
+
log_processed_object(log_file, file_identifier, sha256)
|
238 |
|
239 |
|
240 |
def handle_modified_object(
|
241 |
+
local_path: str,
|
242 |
+
file_identifier: str,
|
243 |
+
new_sha256: str,
|
244 |
+
old_sha256: str,
|
245 |
+
metadata: Dict[str, Any],
|
246 |
num_renders: int,
|
247 |
render_dir: str,
|
248 |
only_northern_hemisphere: bool,
|
|
|
257 |
be downloaded, but nothing will be done with it.
|
258 |
|
259 |
Args:
|
260 |
+
local_path (str): Local path to the downloaded 3D object.
|
261 |
+
file_identifier (str): GitHub URL of the 3D object.
|
262 |
+
new_sha256 (str): SHA256 of the contents of the newly downloaded 3D object.
|
263 |
+
old_sha256 (str): Expected SHA256 of the contents of the 3D object as it was
|
264 |
+
when it was downloaded with Objaverse-XL.
|
265 |
+
metadata (Dict[str, Any]): Metadata about the 3D object, including the GitHub
|
266 |
+
organization and repo names.
|
267 |
num_renders (int): Number of renders to save of the object.
|
268 |
render_dir (str): Directory where the objects will be rendered.
|
269 |
only_northern_hemisphere (bool): Only render the northern hemisphere of the
|
|
|
278 |
Returns:
|
279 |
None
|
280 |
"""
|
281 |
+
success = handle_found_object(
|
282 |
+
local_path=local_path,
|
283 |
+
file_identifier=file_identifier,
|
284 |
+
sha256=new_sha256,
|
285 |
+
metadata=metadata,
|
|
|
286 |
num_renders=num_renders,
|
287 |
render_dir=render_dir,
|
288 |
only_northern_hemisphere=only_northern_hemisphere,
|
289 |
gpu_devices=gpu_devices,
|
290 |
render_timeout=render_timeout,
|
291 |
+
successful_log_file=None,
|
292 |
+
failed_log_file=None,
|
293 |
)
|
294 |
|
295 |
+
if success:
|
296 |
+
log_processed_object(
|
297 |
+
"handle-modified-object-successful.csv",
|
298 |
+
file_identifier,
|
299 |
+
old_sha256,
|
300 |
+
new_sha256,
|
301 |
+
)
|
302 |
+
else:
|
303 |
+
log_processed_object(
|
304 |
+
"handle-modified-object-failed.csv",
|
305 |
+
file_identifier,
|
306 |
+
old_sha256,
|
307 |
+
new_sha256,
|
308 |
+
)
|
309 |
+
|
310 |
|
311 |
def handle_missing_object(
|
312 |
github_url: str,
|
313 |
sha256: str,
|
314 |
+
metadata: Dict[str, Any],
|
|
|
315 |
log_file: str = "handle-missing-object.csv",
|
316 |
) -> None:
|
317 |
"""Called when an object that is in Objaverse-XL is not found.
|
|
|
322 |
Args:
|
323 |
github_url (str): GitHub URL of the 3D object.
|
324 |
sha256 (str): SHA256 of the contents of the original 3D object.
|
325 |
+
metadata (Dict[str, Any]): Metadata about the 3D object, including the GitHub
|
326 |
+
organization and repo names.
|
327 |
log_file (str): Name of the log file to save missing renders to.
|
328 |
|
329 |
Returns:
|
330 |
None
|
331 |
"""
|
332 |
# log the missing object
|
333 |
+
log_processed_object(log_file, github_url, sha256)
|
334 |
|
335 |
|
336 |
def get_example_objects() -> pd.DataFrame:
|
337 |
"""Returns a DataFrame of example objects to use for debugging."""
|
338 |
+
return pd.read_json("example-objects.json", orient="records")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
339 |
|
340 |
|
341 |
def render_github_objects(
|