修正 mini_npz 深度数据职责
This commit is contained in:
@@ -36,7 +36,6 @@ HF_ENDPOINT = "https://huggingface.co"
|
||||
MODELSCOPE_ENDPOINT = "https://modelscope.cn"
|
||||
MODELSCOPE_REVISION = "master"
|
||||
MODELSCOPE_TIMEOUT = 60.0
|
||||
REFERENCE_DEPTH_KEY = "snapform_reference_depth"
|
||||
|
||||
|
||||
class TaskCancelled(RuntimeError):
|
||||
@@ -48,37 +47,6 @@ def check_cancelled(cancel_check):
|
||||
raise TaskCancelled("Task cancelled")
|
||||
|
||||
|
||||
def convert_ai_depth_for_displacement(prediction):
|
||||
"""Convert DA3 distance into Blender's positive displacement direction."""
|
||||
import numpy as np
|
||||
|
||||
prediction.depth = 1.0 - np.asarray(prediction.depth)
|
||||
|
||||
|
||||
def depth_reference_value(depth):
|
||||
"""Return the unmasked depth used to size the imported camera plane."""
|
||||
import numpy as np
|
||||
|
||||
values = np.asarray(depth)
|
||||
valid = np.isfinite(values) & (values > 0.0)
|
||||
if not valid.any():
|
||||
raise ValueError("Depth array contains no positive finite values")
|
||||
return float(np.median(values[valid]))
|
||||
|
||||
|
||||
def write_npz_reference_depth(npz_path, reference_depth):
|
||||
"""Add SnapForm metadata without changing exported prediction arrays."""
|
||||
import numpy as np
|
||||
|
||||
npz_path = Path(npz_path)
|
||||
temporary_path = npz_path.with_name(f"{npz_path.stem}.tmp.npz")
|
||||
with np.load(npz_path, allow_pickle=False) as archive:
|
||||
values = {key: archive[key] for key in archive.files}
|
||||
values[REFERENCE_DEPTH_KEY] = np.asarray(reference_depth, dtype=np.float32)
|
||||
np.savez_compressed(temporary_path, **values)
|
||||
temporary_path.replace(npz_path)
|
||||
|
||||
|
||||
def write_status(
|
||||
path,
|
||||
progress,
|
||||
@@ -1640,10 +1608,6 @@ def reconstruct(args, model_cache=None, cancel_check=None):
|
||||
ref_view_strategy=args.ref_view_strategy,
|
||||
)
|
||||
check_cancelled(cancel_check)
|
||||
reference_depth = None
|
||||
if args.export_format == "mini_npz":
|
||||
reference_depth = depth_reference_value(prediction.depth[0])
|
||||
convert_ai_depth_for_displacement(prediction)
|
||||
write_status(args.status, 0.88, f"Exporting {args.export_format}")
|
||||
if args.export_format == "mesh":
|
||||
export_textured_mesh_glb(
|
||||
@@ -1701,10 +1665,6 @@ def reconstruct(args, model_cache=None, cancel_check=None):
|
||||
result_paths,
|
||||
cancel_check=cancel_check,
|
||||
)
|
||||
if args.export_format == "mini_npz":
|
||||
result_path = output_directory / "results.npz"
|
||||
if reference_depth is not None:
|
||||
write_npz_reference_depth(result_path, reference_depth)
|
||||
check_cancelled(cancel_check)
|
||||
copy_frames(images, output_directory)
|
||||
write_status(
|
||||
|
||||
Reference in New Issue
Block a user