Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Update GSO subset builder
Browse files- README.md +2 -2
- app.py +3 -3
- exporter.py +14 -2
- static/app.js +4 -1
- static/index.html +1 -1
README.md
CHANGED
|
@@ -32,7 +32,7 @@ pick any mix of them, and take the result with you:
|
|
| 32 |
- **Push it to the Hub** as a dataset in your account or org, with a catalog, a dataset card
|
| 33 |
and attribution.
|
| 34 |
- **Fine-tune TRELLIS.2** on it: after a Hub export, one link opens the
|
| 35 |
-
[
|
| 36 |
dataset prefilled. Training runs there, so signing in here only asks for repo access, never for
|
| 37 |
permission to run jobs. Every export also carries `subset.txt` and a group-aware `holdout.txt`, and
|
| 38 |
the card has the exact `trellis2-train --subset` (or `trellis2-prep`) commands. See the
|
|
@@ -51,7 +51,7 @@ Subsets are shareable links.
|
|
| 51 |
| `LATENTS_REPOS` | none | extra `trellis2-prep` repos, added to each collection's own `latents_repos` |
|
| 52 |
| `ZIP_MAX_GB` | `2` | largest zip the Space builds; bigger subsets use the script or a Hub export |
|
| 53 |
| `EXPORT_MAX_GB` | `30` | largest Hub export |
|
| 54 |
-
| `TRAINER_SPACE` | `hugging-3d/
|
| 55 |
| `SUBSET_ENABLED` | `0` | `1` when the trainer Space has `SUBSET_ENABLED=1` too: the link then trains straight from existing latents with the export's `holdout.txt`, instead of preprocessing the exported OBJs |
|
| 56 |
|
| 57 |
Run it locally against a local build: `LOCAL_OBJECTS_DIR=/path/to/out uvicorn app:app --port 7860`.
|
|
|
|
| 32 |
- **Push it to the Hub** as a dataset in your account or org, with a catalog, a dataset card
|
| 33 |
and attribution.
|
| 34 |
- **Fine-tune TRELLIS.2** on it: after a Hub export, one link opens the
|
| 35 |
+
[3D Model LoRA Trainer](https://huggingface.co/spaces/hugging-3d/3d-model-lora-trainer) with the
|
| 36 |
dataset prefilled. Training runs there, so signing in here only asks for repo access, never for
|
| 37 |
permission to run jobs. Every export also carries `subset.txt` and a group-aware `holdout.txt`, and
|
| 38 |
the card has the exact `trellis2-train --subset` (or `trellis2-prep`) commands. See the
|
|
|
|
| 51 |
| `LATENTS_REPOS` | none | extra `trellis2-prep` repos, added to each collection's own `latents_repos` |
|
| 52 |
| `ZIP_MAX_GB` | `2` | largest zip the Space builds; bigger subsets use the script or a Hub export |
|
| 53 |
| `EXPORT_MAX_GB` | `30` | largest Hub export |
|
| 54 |
+
| `TRAINER_SPACE` | `hugging-3d/3d-model-lora-trainer` | where the "Fine-tune" link after an export points |
|
| 55 |
| `SUBSET_ENABLED` | `0` | `1` when the trainer Space has `SUBSET_ENABLED=1` too: the link then trains straight from existing latents with the export's `holdout.txt`, instead of preprocessing the exported OBJs |
|
| 56 |
|
| 57 |
Run it locally against a local build: `LOCAL_OBJECTS_DIR=/path/to/out uvicorn app:app --port 7860`.
|
app.py
CHANGED
|
@@ -36,14 +36,14 @@ except ImportError: # running from a checkout
|
|
| 36 |
import jobs as T
|
| 37 |
|
| 38 |
DEFAULT_COLLECTIONS = ("hugging-3d/gso-objects,hugging-3d/smithsonian-3d-objects,hugging-3d/abo-3d-objects,"
|
| 39 |
-
"hugging-3d/nasa-3d-objects,hugging-3d/thingi10k-3d-objects")
|
| 40 |
COLLECTION_REPOS = [r for r in os.environ.get("COLLECTIONS", DEFAULT_COLLECTIONS).split(",") if r]
|
| 41 |
EXTRA_LATENTS = [r for r in os.environ.get("LATENTS_REPOS", "").split(",") if r] # appended to every manifest's list
|
| 42 |
LOCAL_DIR = os.environ.get("LOCAL_OBJECTS_DIR")
|
| 43 |
SPACE_ID = os.environ.get("SPACE_ID", "hugging-3d/data-finetuning-subset-builder")
|
| 44 |
SPACE_URL = f"https://huggingface.co/spaces/{SPACE_ID}"
|
| 45 |
APP_URL = f"https://{os.environ['SPACE_HOST']}/" if os.environ.get("SPACE_HOST") else None # None: use the page URL
|
| 46 |
-
TRAINER_SPACE = os.environ.get("TRAINER_SPACE", "hugging-3d/
|
| 47 |
TRAINER_URL = f"https://huggingface.co/spaces/{TRAINER_SPACE}"
|
| 48 |
ZIP_MAX_BYTES = int(float(os.environ.get("ZIP_MAX_GB", "2")) * 2**30)
|
| 49 |
EXPORT_MAX_BYTES = int(float(os.environ.get("EXPORT_MAX_GB", "30")) * 2**30)
|
|
@@ -51,7 +51,7 @@ STATIC = os.path.join(os.path.dirname(os.path.abspath(__file__)), "static")
|
|
| 51 |
REPO_NAME = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._-]{0,95}$")
|
| 52 |
CLIENT_COLUMNS = ["object_id", "name", "description", "category", "brand", "group", "faces", "license",
|
| 53 |
"is_watertight", "size_x_cm", "size_y_cm", "size_z_cm", "max_dim_cm", "flatness",
|
| 54 |
-
"all_bytes", "glb_bytes", "preview_glb_bytes", "prep_sha256", "latents_repo", "source_url", "author", "credit"]
|
| 55 |
|
| 56 |
app = FastAPI(title="3D subset builder")
|
| 57 |
attach_huggingface_oauth(app)
|
|
|
|
| 36 |
import jobs as T
|
| 37 |
|
| 38 |
DEFAULT_COLLECTIONS = ("hugging-3d/gso-objects,hugging-3d/smithsonian-3d-objects,hugging-3d/abo-3d-objects,"
|
| 39 |
+
"hugging-3d/nasa-3d-objects,hugging-3d/thingi10k-3d-objects,hugging-3d/omniobject3d-3d-objects")
|
| 40 |
COLLECTION_REPOS = [r for r in os.environ.get("COLLECTIONS", DEFAULT_COLLECTIONS).split(",") if r]
|
| 41 |
EXTRA_LATENTS = [r for r in os.environ.get("LATENTS_REPOS", "").split(",") if r] # appended to every manifest's list
|
| 42 |
LOCAL_DIR = os.environ.get("LOCAL_OBJECTS_DIR")
|
| 43 |
SPACE_ID = os.environ.get("SPACE_ID", "hugging-3d/data-finetuning-subset-builder")
|
| 44 |
SPACE_URL = f"https://huggingface.co/spaces/{SPACE_ID}"
|
| 45 |
APP_URL = f"https://{os.environ['SPACE_HOST']}/" if os.environ.get("SPACE_HOST") else None # None: use the page URL
|
| 46 |
+
TRAINER_SPACE = os.environ.get("TRAINER_SPACE", "hugging-3d/3d-model-lora-trainer")
|
| 47 |
TRAINER_URL = f"https://huggingface.co/spaces/{TRAINER_SPACE}"
|
| 48 |
ZIP_MAX_BYTES = int(float(os.environ.get("ZIP_MAX_GB", "2")) * 2**30)
|
| 49 |
EXPORT_MAX_BYTES = int(float(os.environ.get("EXPORT_MAX_GB", "30")) * 2**30)
|
|
|
|
| 51 |
REPO_NAME = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._-]{0,95}$")
|
| 52 |
CLIENT_COLUMNS = ["object_id", "name", "description", "category", "brand", "group", "faces", "license",
|
| 53 |
"is_watertight", "size_x_cm", "size_y_cm", "size_z_cm", "max_dim_cm", "flatness",
|
| 54 |
+
"all_bytes", "glb_bytes", "preview_glb_bytes", "prep_sha256", "latents_repo", "source_url", "author", "credit", "extras_bytes"]
|
| 55 |
|
| 56 |
app = FastAPI(title="3D subset builder")
|
| 57 |
attach_huggingface_oauth(app)
|
exporter.py
CHANGED
|
@@ -10,6 +10,7 @@ import io
|
|
| 10 |
import json
|
| 11 |
import os
|
| 12 |
import random
|
|
|
|
| 13 |
import shutil
|
| 14 |
import tempfile
|
| 15 |
import zipfile
|
|
@@ -42,7 +43,8 @@ def estimate_bytes(rows: pd.DataFrame, formats: Iterable[str], man: dict) -> int
|
|
| 42 |
n = pd.Series(1, index=rows.index)
|
| 43 |
per = {"glb": rows.glb_bytes, "preview": rows.preview_glb_bytes,
|
| 44 |
"original": (rows.all_bytes - rows.glb_bytes) if "original" in files else 0 * n,
|
| 45 |
-
"thumbnails": n * 70_000 * len(files.get("thumbnails", [])), "metadata": n * 3_000
|
|
|
|
| 46 |
return int(sum(per[f].sum() for f in formats))
|
| 47 |
|
| 48 |
|
|
@@ -104,12 +106,22 @@ print("downloaded to", out)
|
|
| 104 |
'''
|
| 105 |
|
| 106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
def card(repo_id: str, rows: pd.DataFrame, formats: list[str], man: dict, space_url: str,
|
| 108 |
share_url: str, latents_repo: str | None, n_latents: int, n_holdout: int) -> str:
|
| 109 |
cats = Counter(c or "uncategorized" for c in rows.category).most_common()
|
| 110 |
cat_table = "\n".join(f"| {c} | {n} |" for c, n in cats)
|
| 111 |
files = man["paths"]["files"]
|
| 112 |
-
layout = [f"| {', '.join(f'`{p}`'.replace('{id}', '<id>') for p in files[f])} | {man['formats'][f][1]} |" for f in formats]
|
| 113 |
layout.append("| `catalog.parquet` | one row per object: metadata, geometry stats, license, variant group |")
|
| 114 |
layout.append("| `ATTRIBUTION.md` | the credit line and license of every object |")
|
| 115 |
layout.append("| `subset.txt` | `<sha256> <object_id>` per line; `trellis2-train --subset` reads it |")
|
|
|
|
| 10 |
import json
|
| 11 |
import os
|
| 12 |
import random
|
| 13 |
+
import re
|
| 14 |
import shutil
|
| 15 |
import tempfile
|
| 16 |
import zipfile
|
|
|
|
| 43 |
n = pd.Series(1, index=rows.index)
|
| 44 |
per = {"glb": rows.glb_bytes, "preview": rows.preview_glb_bytes,
|
| 45 |
"original": (rows.all_bytes - rows.glb_bytes) if "original" in files else 0 * n,
|
| 46 |
+
"thumbnails": n * 70_000 * len(files.get("thumbnails", [])), "metadata": n * 3_000,
|
| 47 |
+
"renders": rows.extras_bytes.fillna(0) if "extras_bytes" in rows else 0 * n}
|
| 48 |
return int(sum(per[f].sum() for f in formats))
|
| 49 |
|
| 50 |
|
|
|
|
| 106 |
'''
|
| 107 |
|
| 108 |
|
| 109 |
+
def _brief(paths: list[str]) -> list[str]:
|
| 110 |
+
"""Paths for a card's file table, with a run of numbered files (renders/000.png, 001.png, ...) as one entry."""
|
| 111 |
+
numbered = [p for p in paths if re.search(r"/\d+\.\w+$", p)]
|
| 112 |
+
if len(numbered) < 3:
|
| 113 |
+
return paths
|
| 114 |
+
first, last = numbered[0], numbered[-1]
|
| 115 |
+
run = f"{first.rsplit('/', 1)[0]}/{first.rsplit('/', 1)[1].split('.')[0]}…{last.rsplit('/', 1)[1]}"
|
| 116 |
+
return [run] + [p for p in paths if p not in numbered]
|
| 117 |
+
|
| 118 |
+
|
| 119 |
def card(repo_id: str, rows: pd.DataFrame, formats: list[str], man: dict, space_url: str,
|
| 120 |
share_url: str, latents_repo: str | None, n_latents: int, n_holdout: int) -> str:
|
| 121 |
cats = Counter(c or "uncategorized" for c in rows.category).most_common()
|
| 122 |
cat_table = "\n".join(f"| {c} | {n} |" for c, n in cats)
|
| 123 |
files = man["paths"]["files"]
|
| 124 |
+
layout = [f"| {', '.join(f'`{p}`'.replace('{id}', '<id>') for p in _brief(files[f]))} | {man['formats'][f][1]} |" for f in formats]
|
| 125 |
layout.append("| `catalog.parquet` | one row per object: metadata, geometry stats, license, variant group |")
|
| 126 |
layout.append("| `ATTRIBUTION.md` | the credit line and license of every object |")
|
| 127 |
layout.append("| `subset.txt` | `<sha256> <object_id>` per line; `trellis2-train --subset` reads it |")
|
static/app.js
CHANGED
|
@@ -364,7 +364,9 @@ function openDetail(id) {
|
|
| 364 |
d.dataset.id = id;
|
| 365 |
const glb = asset(S.cfg.paths.preview_glb, id);
|
| 366 |
if ($("#mv").getAttribute("src") !== glb) {
|
| 367 |
-
|
|
|
|
|
|
|
| 368 |
$("#mv").setAttribute("src", glb);
|
| 369 |
$("#mv").setAttribute("poster", thumbs[0] || tileUrl(id));
|
| 370 |
$("#thumbs").innerHTML = thumbs.length > 1 ? thumbs.map((u, k) => `<img loading="lazy" src="${u}" alt="render ${k + 1}">`).join("") : "";
|
|
@@ -411,6 +413,7 @@ function sizes(rows) {
|
|
| 411 |
original: sum((r) => r.all_bytes - r.glb_bytes), glb: sum((r) => r.glb_bytes),
|
| 412 |
preview: sum((r) => r.preview_glb_bytes), metadata: rows.length * 3000,
|
| 413 |
thumbnails: rows.length * 70000 * (S.cfg.paths.files.thumbnails || []).length,
|
|
|
|
| 414 |
};
|
| 415 |
}
|
| 416 |
|
|
|
|
| 364 |
d.dataset.id = id;
|
| 365 |
const glb = asset(S.cfg.paths.preview_glb, id);
|
| 366 |
if ($("#mv").getAttribute("src") !== glb) {
|
| 367 |
+
// a library's own renders (OmniObject3D) are its pictures: its meshes have no texture
|
| 368 |
+
const thumbs = (S.cfg.paths.files.thumbnails || []).concat((S.cfg.paths.files.renders || []).filter((p) => p.endsWith(".png")))
|
| 369 |
+
.map((t) => asset(t, id));
|
| 370 |
$("#mv").setAttribute("src", glb);
|
| 371 |
$("#mv").setAttribute("poster", thumbs[0] || tileUrl(id));
|
| 372 |
$("#thumbs").innerHTML = thumbs.length > 1 ? thumbs.map((u, k) => `<img loading="lazy" src="${u}" alt="render ${k + 1}">`).join("") : "";
|
|
|
|
| 413 |
original: sum((r) => r.all_bytes - r.glb_bytes), glb: sum((r) => r.glb_bytes),
|
| 414 |
preview: sum((r) => r.preview_glb_bytes), metadata: rows.length * 3000,
|
| 415 |
thumbnails: rows.length * 70000 * (S.cfg.paths.files.thumbnails || []).length,
|
| 416 |
+
renders: sum((r) => r.extras_bytes),
|
| 417 |
};
|
| 418 |
}
|
| 419 |
|
static/index.html
CHANGED
|
@@ -4,7 +4,7 @@
|
|
| 4 |
<meta charset="utf-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 6 |
<title>3D Subset Builder</title>
|
| 7 |
-
<meta name="description" content="Browse free 3D libraries (Google Scanned Objects, Smithsonian, Amazon Berkeley Objects, NASA, Thingi10K), build your own subset, download it or push it to the Hugging Face Hub, and fine-tune TRELLIS.2 on it.">
|
| 8 |
<link rel="icon" href="data:,">
|
| 9 |
<link rel="stylesheet" href="/static/style.css">
|
| 10 |
<script type="module" src="https://unpkg.com/@google/model-viewer@3.5.0/dist/model-viewer.min.js"></script>
|
|
|
|
| 4 |
<meta charset="utf-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 6 |
<title>3D Subset Builder</title>
|
| 7 |
+
<meta name="description" content="Browse free 3D libraries (Google Scanned Objects, Smithsonian, Amazon Berkeley Objects, NASA, Thingi10K, OmniObject3D), build your own subset, download it or push it to the Hugging Face Hub, and fine-tune TRELLIS.2 on it.">
|
| 8 |
<link rel="icon" href="data:,">
|
| 9 |
<link rel="stylesheet" href="/static/style.css">
|
| 10 |
<script type="module" src="https://unpkg.com/@google/model-viewer@3.5.0/dist/model-viewer.min.js"></script>
|