Faz2: code/meshai_train/dataset.py
Browse files- code/meshai_train/dataset.py +2 -10
code/meshai_train/dataset.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
import json
|
|
|
|
| 4 |
from pathlib import Path
|
| 5 |
|
| 6 |
import numpy as np
|
|
@@ -97,16 +98,12 @@ class PreprocessedMeshDataset(Dataset):
|
|
| 97 |
)
|
| 98 |
)
|
| 99 |
except Exception as exc:
|
| 100 |
-
# 404 / EntryNotFound / RemoteEntryNotFound — manifestte olup HF'de olmayan UID
|
| 101 |
msg = str(exc).lower()
|
| 102 |
if "404" in msg or "entrynotfound" in msg.replace(" ", "") or "not found" in msg:
|
| 103 |
raise FileNotFoundError(f"HF eksik: {rel}") from exc
|
| 104 |
raise
|
| 105 |
|
| 106 |
def _load_npz(self, uid: str):
|
| 107 |
-
"""Incomplete HF cache can yield BadZipFile; delete + force redownload once."""
|
| 108 |
-
import zipfile
|
| 109 |
-
|
| 110 |
path = self._resolve_file(uid, "geometry_latent.npz")
|
| 111 |
try:
|
| 112 |
return np.load(path)
|
|
@@ -116,7 +113,7 @@ class PreprocessedMeshDataset(Dataset):
|
|
| 116 |
except OSError:
|
| 117 |
pass
|
| 118 |
if not self.token:
|
| 119 |
-
raise FileNotFoundError(f"Bozuk latent
|
| 120 |
from huggingface_hub import hf_hub_download
|
| 121 |
|
| 122 |
rel = f"{_uid_hf_prefix(uid)}/geometry_latent.npz"
|
|
@@ -163,7 +160,6 @@ class PreprocessedMeshDataset(Dataset):
|
|
| 163 |
continue
|
| 164 |
if not views:
|
| 165 |
views.append(np.zeros((3, self.render_size, self.render_size), dtype=np.float32))
|
| 166 |
-
# Collate batch_size>1 icin view sayisini sabitle (eksik render pad).
|
| 167 |
while len(views) < self.max_views:
|
| 168 |
views.append(views[-1].copy())
|
| 169 |
views = views[: self.max_views]
|
|
@@ -178,9 +174,6 @@ class PreprocessedMeshDataset(Dataset):
|
|
| 178 |
}
|
| 179 |
|
| 180 |
def __getitem__(self, idx: int) -> dict:
|
| 181 |
-
# Manifest bazen HF'de olmayan / bozuk UID icerir; sonraki ornege kay.
|
| 182 |
-
import zipfile
|
| 183 |
-
|
| 184 |
if not hasattr(self, "_missing_uids"):
|
| 185 |
self._missing_uids = set()
|
| 186 |
n = len(self.objects)
|
|
@@ -202,7 +195,6 @@ class PreprocessedMeshDataset(Dataset):
|
|
| 202 |
|
| 203 |
|
| 204 |
def collate_preprocessed(batch: list[dict]) -> dict:
|
| 205 |
-
# Savunmaci pad: eski checkpoint/yamali dataset karisik shape getirebilir.
|
| 206 |
max_v = max(int(b["views"].shape[0]) for b in batch)
|
| 207 |
views_list = []
|
| 208 |
for b in batch:
|
|
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
import json
|
| 4 |
+
import zipfile
|
| 5 |
from pathlib import Path
|
| 6 |
|
| 7 |
import numpy as np
|
|
|
|
| 98 |
)
|
| 99 |
)
|
| 100 |
except Exception as exc:
|
|
|
|
| 101 |
msg = str(exc).lower()
|
| 102 |
if "404" in msg or "entrynotfound" in msg.replace(" ", "") or "not found" in msg:
|
| 103 |
raise FileNotFoundError(f"HF eksik: {rel}") from exc
|
| 104 |
raise
|
| 105 |
|
| 106 |
def _load_npz(self, uid: str):
|
|
|
|
|
|
|
|
|
|
| 107 |
path = self._resolve_file(uid, "geometry_latent.npz")
|
| 108 |
try:
|
| 109 |
return np.load(path)
|
|
|
|
| 113 |
except OSError:
|
| 114 |
pass
|
| 115 |
if not self.token:
|
| 116 |
+
raise FileNotFoundError(f"Bozuk latent: {uid}") from exc
|
| 117 |
from huggingface_hub import hf_hub_download
|
| 118 |
|
| 119 |
rel = f"{_uid_hf_prefix(uid)}/geometry_latent.npz"
|
|
|
|
| 160 |
continue
|
| 161 |
if not views:
|
| 162 |
views.append(np.zeros((3, self.render_size, self.render_size), dtype=np.float32))
|
|
|
|
| 163 |
while len(views) < self.max_views:
|
| 164 |
views.append(views[-1].copy())
|
| 165 |
views = views[: self.max_views]
|
|
|
|
| 174 |
}
|
| 175 |
|
| 176 |
def __getitem__(self, idx: int) -> dict:
|
|
|
|
|
|
|
|
|
|
| 177 |
if not hasattr(self, "_missing_uids"):
|
| 178 |
self._missing_uids = set()
|
| 179 |
n = len(self.objects)
|
|
|
|
| 195 |
|
| 196 |
|
| 197 |
def collate_preprocessed(batch: list[dict]) -> dict:
|
|
|
|
| 198 |
max_v = max(int(b["views"].shape[0]) for b in batch)
|
| 199 |
views_list = []
|
| 200 |
for b in batch:
|