Datasets:

Languages:
English
ArXiv:
License:
mattdeitke commited on
Commit
dd3a1b3
1 Parent(s): eeb4d06

refactor github loading

Browse files
github/github-urls.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:3baffd339cae4623b0ac3c77055ca3ff24fef0d75922738a12d9c9623fc33305
3
- size 794835357
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ac5dba4285a7d4e233f6cff0f538d7e9f6f7410bcbd6e47d565ce0338de5ee75
3
+ size 797464991
objaverse_xl/github.py CHANGED
@@ -1,6 +1,5 @@
1
  """Script to download objects from GitHub."""
2
 
3
- import hashlib
4
  import json
5
  import multiprocessing
6
  import os
@@ -10,6 +9,7 @@ import tarfile
10
  import tempfile
11
  from multiprocessing import Pool
12
  from typing import Callable, Dict, List, Literal, Optional
 
13
 
14
  import fsspec
15
  import pandas as pd
@@ -42,7 +42,7 @@ def load_github_metadata(download_dir: str = "~/.objaverse") -> pd.DataFrame:
42
 
43
  Returns:
44
  pd.DataFrame: GitHub 3D object metadata as a Pandas DataFrame with columns for
45
- the object "githubUrl", "license", and "sha256".
46
  """
47
  filename = os.path.join(download_dir, "github", "github-urls.parquet")
48
  fs, path = fsspec.core.url_to_fs(filename)
@@ -65,8 +65,8 @@ def load_github_metadata(download_dir: str = "~/.objaverse") -> pd.DataFrame:
65
 
66
 
67
  def _get_repo_id_with_hash(item: pd.Series) -> str:
68
- org, repo = item["githubUrl"].split("/")[3:5]
69
- commit_hash = item["githubUrl"].split("/")[6]
70
  return f"{org}/{repo}/{commit_hash}"
71
 
72
 
@@ -112,33 +112,6 @@ def _run_command_with_check(command: List[str], cwd: Optional[str] = None) -> bo
112
  return False
113
 
114
 
115
- def get_file_hash(file_path: str) -> str:
116
- """Get the sha256 hash of a file.
117
-
118
- Args:
119
- file_path (str): Path to the file.
120
-
121
- Returns:
122
- str: sha256 hash of the file.
123
- """
124
- # Check if the path is a symbolic link
125
- if os.path.islink(file_path):
126
- # Resolve the symbolic link
127
- resolved_path = os.readlink(file_path)
128
- # Check if the resolved path exists
129
- if not os.path.exists(resolved_path):
130
- raise FileNotFoundError(
131
- f"The symbolic link points to a file that doesn't exist: {resolved_path}"
132
- )
133
- sha256 = hashlib.sha256()
134
- # Read the file from the path
135
- with open(file_path, "rb") as f:
136
- # Loop till the end of the file
137
- for byte_block in iter(lambda: f.read(4096), b""):
138
- sha256.update(byte_block)
139
- return sha256.hexdigest()
140
-
141
-
142
  def _process_repo(
143
  repo_id: str,
144
  fs: fsspec.AbstractFileSystem,
@@ -158,12 +131,12 @@ def _process_repo(
158
  fs (fsspec.AbstractFileSystem): File system to use for saving the repo.
159
  base_dir (str): Base directory to save the repo to.
160
  expected_objects (Dict[str, str]): Dictionary of objects that one expects to
161
- find in the repo. Keys are the GitHub URLs and values are the sha256 of the
162
- objects.
163
  {and the rest of the args are the same as download_github_objects}
164
 
165
  Returns:
166
- List[Dict[str, str]]: List of dictionaries with the keys "githubUrl" and
167
  "sha256" for each downloaded object.
168
  """
169
  # NOTE: assuming that the user has already checked that the repo doesn't exist,
@@ -238,7 +211,7 @@ def _process_repo(
238
  target_directory,
239
  f"https://github.com/{org}/{repo}/blob/{repo_commit_hash}",
240
  )
241
- file_hashes.append(dict(sha256=file_hash, githubUrl=github_url))
242
 
243
  # handle the object under different conditions
244
  if github_url in expected_objects:
@@ -312,7 +285,7 @@ def _process_repo(
312
 
313
  # get each object that was missing from the expected objects
314
  if handle_missing_object is not None:
315
- obtained_urls = {x["githubUrl"] for x in file_hashes}
316
  for github_url, sha256 in expected_objects.items():
317
  if github_url not in obtained_urls:
318
  handle_missing_object(
@@ -365,7 +338,7 @@ def _parallel_process_repo(args) -> List[Dict[str, str]]:
365
  args (Tuple): Tuple of arguments to pass to _process_repo.
366
 
367
  Returns:
368
- List[Dict[str, str]]: List of dictionaries with the keys "githubUrl" and
369
  "sha256" for each downloaded object.
370
  """
371
 
@@ -398,7 +371,7 @@ def _parallel_process_repo(args) -> List[Dict[str, str]]:
398
 
399
  def _process_group(group):
400
  key, group_df = group
401
- return key, group_df.set_index("githubUrl")["sha256"].to_dict()
402
 
403
 
404
  def download_github_objects(
@@ -415,8 +388,8 @@ def download_github_objects(
415
 
416
  Args:
417
  objects (pd.DataFrmae): GitHub objects to download. Must have columns for the
418
- object "githubUrl" and "sha256". Use the load_github_metadata function to
419
- get the metadata.
420
  processes (Optional[int], optional): Number of processes to use for downloading.
421
  If None, will use the number of CPUs on the machine. Defaults to None.
422
  download_dir (str, optional): Directory to download the GitHub objects to.
@@ -473,7 +446,7 @@ def download_github_objects(
473
  Return is not used. Defaults to None.
474
 
475
  Returns:
476
- List[Dict[str, str]]: List of dictionaries with the keys "githubUrl" and
477
  "sha256" for each downloaded object.
478
  """
479
  if processes is None:
 
1
  """Script to download objects from GitHub."""
2
 
 
3
  import json
4
  import multiprocessing
5
  import os
 
9
  import tempfile
10
  from multiprocessing import Pool
11
  from typing import Callable, Dict, List, Literal, Optional
12
+ from objaverse_xl.utils import get_file_hash
13
 
14
  import fsspec
15
  import pandas as pd
 
42
 
43
  Returns:
44
  pd.DataFrame: GitHub 3D object metadata as a Pandas DataFrame with columns for
45
+ the object "fileIdentifier", "license", "source", "fileType", and "sha256".
46
  """
47
  filename = os.path.join(download_dir, "github", "github-urls.parquet")
48
  fs, path = fsspec.core.url_to_fs(filename)
 
65
 
66
 
67
  def _get_repo_id_with_hash(item: pd.Series) -> str:
68
+ org, repo = item["fileIdentifier"].split("/")[3:5]
69
+ commit_hash = item["fileIdentifier"].split("/")[6]
70
  return f"{org}/{repo}/{commit_hash}"
71
 
72
 
 
112
  return False
113
 
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  def _process_repo(
116
  repo_id: str,
117
  fs: fsspec.AbstractFileSystem,
 
131
  fs (fsspec.AbstractFileSystem): File system to use for saving the repo.
132
  base_dir (str): Base directory to save the repo to.
133
  expected_objects (Dict[str, str]): Dictionary of objects that one expects to
134
+ find in the repo. Keys are the "fileIdentifier" (i.e., the GitHub URL in
135
+ this case) and values are the "sha256" of the objects.
136
  {and the rest of the args are the same as download_github_objects}
137
 
138
  Returns:
139
+ List[Dict[str, str]]: List of dictionaries with the keys "fileIdentifier" and
140
  "sha256" for each downloaded object.
141
  """
142
  # NOTE: assuming that the user has already checked that the repo doesn't exist,
 
211
  target_directory,
212
  f"https://github.com/{org}/{repo}/blob/{repo_commit_hash}",
213
  )
214
+ file_hashes.append(dict(sha256=file_hash, fileIdentifier=github_url))
215
 
216
  # handle the object under different conditions
217
  if github_url in expected_objects:
 
285
 
286
  # get each object that was missing from the expected objects
287
  if handle_missing_object is not None:
288
+ obtained_urls = {x["fileIdentifier"] for x in file_hashes}
289
  for github_url, sha256 in expected_objects.items():
290
  if github_url not in obtained_urls:
291
  handle_missing_object(
 
338
  args (Tuple): Tuple of arguments to pass to _process_repo.
339
 
340
  Returns:
341
+ List[Dict[str, str]]: List of dictionaries with the keys "fileIdentifier" and
342
  "sha256" for each downloaded object.
343
  """
344
 
 
371
 
372
  def _process_group(group):
373
  key, group_df = group
374
+ return key, group_df.set_index("fileIdentifier")["sha256"].to_dict()
375
 
376
 
377
  def download_github_objects(
 
388
 
389
  Args:
390
  objects (pd.DataFrmae): GitHub objects to download. Must have columns for the
391
+ object "fileIdentifier" and "sha256". Use the load_github_metadata function
392
+ to get the metadata.
393
  processes (Optional[int], optional): Number of processes to use for downloading.
394
  If None, will use the number of CPUs on the machine. Defaults to None.
395
  download_dir (str, optional): Directory to download the GitHub objects to.
 
446
  Return is not used. Defaults to None.
447
 
448
  Returns:
449
+ List[Dict[str, str]]: List of dictionaries with the keys "fileIdentifier" and
450
  "sha256" for each downloaded object.
451
  """
452
  if processes is None:
objaverse_xl/utils.py CHANGED
@@ -1,6 +1,8 @@
1
  """Utility functions for the objaverse_xl package."""
2
 
3
  import uuid
 
 
4
 
5
 
6
  def get_uid_from_str(string: str) -> str:
@@ -14,3 +16,30 @@ def get_uid_from_str(string: str) -> str:
14
  """
15
  namespace = uuid.NAMESPACE_DNS
16
  return str(uuid.uuid5(namespace, string))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  """Utility functions for the objaverse_xl package."""
2
 
3
  import uuid
4
+ import os
5
+ import hashlib
6
 
7
 
8
  def get_uid_from_str(string: str) -> str:
 
16
  """
17
  namespace = uuid.NAMESPACE_DNS
18
  return str(uuid.uuid5(namespace, string))
19
+
20
+
21
+ def get_file_hash(file_path: str) -> str:
22
+ """Get the sha256 hash of a file.
23
+
24
+ Args:
25
+ file_path (str): Path to the file.
26
+
27
+ Returns:
28
+ str: sha256 hash of the file.
29
+ """
30
+ # Check if the path is a symbolic link
31
+ if os.path.islink(file_path):
32
+ # Resolve the symbolic link
33
+ resolved_path = os.readlink(file_path)
34
+ # Check if the resolved path exists
35
+ if not os.path.exists(resolved_path):
36
+ raise FileNotFoundError(
37
+ f"The symbolic link points to a file that doesn't exist: {resolved_path}"
38
+ )
39
+ sha256 = hashlib.sha256()
40
+ # Read the file from the path
41
+ with open(file_path, "rb") as f:
42
+ # Loop till the end of the file
43
+ for byte_block in iter(lambda: f.read(4096), b""):
44
+ sha256.update(byte_block)
45
+ return sha256.hexdigest()
scripts/rendering/example-objects.json CHANGED
@@ -1,42 +1,42 @@
1
  [
2
  {
3
  "sha256": "d2b9a5d7c47dc93526082c9b630157ab6bce4fd8669610d942176f4a36444e71",
4
- "githubUrl": "https://github.com/mattdeitke/objaverse-xl-test-files/blob/ead0bed6a76012452273bbe18d12e4d68a881956/example.obj"
5
  },
6
  {
7
  "sha256": "f15f7541614940dedd1ce373dee9cde1cc63471db84081259a44488aca267408",
8
- "githubUrl": "https://github.com/mattdeitke/objaverse-xl-test-files/blob/ead0bed6a76012452273bbe18d12e4d68a881956/example-linked.gltf"
9
  },
10
  {
11
  "sha256": "cd567dfd1605a5fd60af1b8ac67e44b6af25b9e3f160da66047bb1187d02a071",
12
- "githubUrl": "https://github.com/mattdeitke/objaverse-xl-test-files/blob/ead0bed6a76012452273bbe18d12e4d68a881956/example.dae"
13
  },
14
  {
15
  "sha256": "879bc9d2d85e4f3866f0cfef41f5236f9fff5f973380461af9f69cdbed53a0da",
16
- "githubUrl": "https://github.com/mattdeitke/objaverse-xl-test-files/blob/ead0bed6a76012452273bbe18d12e4d68a881956/example.abc"
17
  },
18
  {
19
  "sha256": "ac69da6df0c83b593902c71238a7721f575233723730150230da95d583466562",
20
- "githubUrl": "https://github.com/mattdeitke/objaverse-xl-test-files/blob/ead0bed6a76012452273bbe18d12e4d68a881956/example.blend"
21
  },
22
  {
23
  "sha256": "bc4cc8a78bc57d3c41ddaca9135d2b4e66b59e97846e2b796e5cc6b09c62b273",
24
- "githubUrl": "https://github.com/mattdeitke/objaverse-xl-test-files/blob/ead0bed6a76012452273bbe18d12e4d68a881956/example-embedded.gltf"
25
  },
26
  {
27
  "sha256": "04e6377317d6818e32c5cbd1951e76deb3641bbf4f6db6933046221d5fbf1c5c",
28
- "githubUrl": "https://github.com/mattdeitke/objaverse-xl-test-files/blob/ead0bed6a76012452273bbe18d12e4d68a881956/example.glb"
29
  },
30
  {
31
  "sha256": "7037575f47816118e5a34e7c0da9927e1be7be3f5b4adfac337710822eb50fa9",
32
- "githubUrl": "https://github.com/mattdeitke/objaverse-xl-test-files/blob/ead0bed6a76012452273bbe18d12e4d68a881956/example.fbx"
33
  },
34
  {
35
  "sha256": "10fd5944c3fe32cb25fdcf46319cbda250b98bd22fd87fc41de5769b118d5262",
36
- "githubUrl": "https://github.com/mattdeitke/objaverse-xl-test-files/blob/ead0bed6a76012452273bbe18d12e4d68a881956/example.stl"
37
  },
38
  {
39
  "sha256": "aa5c41753ad8a91562122d8cafbe1a940146fc3d227b7086eb8c830da36cb42b",
40
- "githubUrl": "https://github.com/mattdeitke/objaverse-xl-test-files/blob/ead0bed6a76012452273bbe18d12e4d68a881956/example.ply"
41
  }
42
  ]
 
1
  [
2
  {
3
  "sha256": "d2b9a5d7c47dc93526082c9b630157ab6bce4fd8669610d942176f4a36444e71",
4
+ "fileIdentifier": "https://github.com/mattdeitke/objaverse-xl-test-files/blob/ead0bed6a76012452273bbe18d12e4d68a881956/example.obj"
5
  },
6
  {
7
  "sha256": "f15f7541614940dedd1ce373dee9cde1cc63471db84081259a44488aca267408",
8
+ "fileIdentifier": "https://github.com/mattdeitke/objaverse-xl-test-files/blob/ead0bed6a76012452273bbe18d12e4d68a881956/example-linked.gltf"
9
  },
10
  {
11
  "sha256": "cd567dfd1605a5fd60af1b8ac67e44b6af25b9e3f160da66047bb1187d02a071",
12
+ "fileIdentifier": "https://github.com/mattdeitke/objaverse-xl-test-files/blob/ead0bed6a76012452273bbe18d12e4d68a881956/example.dae"
13
  },
14
  {
15
  "sha256": "879bc9d2d85e4f3866f0cfef41f5236f9fff5f973380461af9f69cdbed53a0da",
16
+ "fileIdentifier": "https://github.com/mattdeitke/objaverse-xl-test-files/blob/ead0bed6a76012452273bbe18d12e4d68a881956/example.abc"
17
  },
18
  {
19
  "sha256": "ac69da6df0c83b593902c71238a7721f575233723730150230da95d583466562",
20
+ "fileIdentifier": "https://github.com/mattdeitke/objaverse-xl-test-files/blob/ead0bed6a76012452273bbe18d12e4d68a881956/example.blend"
21
  },
22
  {
23
  "sha256": "bc4cc8a78bc57d3c41ddaca9135d2b4e66b59e97846e2b796e5cc6b09c62b273",
24
+ "fileIdentifier": "https://github.com/mattdeitke/objaverse-xl-test-files/blob/ead0bed6a76012452273bbe18d12e4d68a881956/example-embedded.gltf"
25
  },
26
  {
27
  "sha256": "04e6377317d6818e32c5cbd1951e76deb3641bbf4f6db6933046221d5fbf1c5c",
28
+ "fileIdentifier": "https://github.com/mattdeitke/objaverse-xl-test-files/blob/ead0bed6a76012452273bbe18d12e4d68a881956/example.glb"
29
  },
30
  {
31
  "sha256": "7037575f47816118e5a34e7c0da9927e1be7be3f5b4adfac337710822eb50fa9",
32
+ "fileIdentifier": "https://github.com/mattdeitke/objaverse-xl-test-files/blob/ead0bed6a76012452273bbe18d12e4d68a881956/example.fbx"
33
  },
34
  {
35
  "sha256": "10fd5944c3fe32cb25fdcf46319cbda250b98bd22fd87fc41de5769b118d5262",
36
+ "fileIdentifier": "https://github.com/mattdeitke/objaverse-xl-test-files/blob/ead0bed6a76012452273bbe18d12e4d68a881956/example.stl"
37
  },
38
  {
39
  "sha256": "aa5c41753ad8a91562122d8cafbe1a940146fc3d227b7086eb8c830da36cb42b",
40
+ "fileIdentifier": "https://github.com/mattdeitke/objaverse-xl-test-files/blob/ead0bed6a76012452273bbe18d12e4d68a881956/example.ply"
41
  }
42
  ]