Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/ffsplat/coding/scene_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,11 @@ def to_yaml_file(self, yaml_path: Path) -> None:


@lru_cache
def process_operation(op: Operation, verbose: bool, decoding_ops: str) -> tuple[dict[str, Field], list[dict[str, Any]]]:
def process_operation(op: Operation, verbose: bool) -> tuple[dict[str, Field], list[dict[str, Any]]]:
"""Process the operation and return the new fields and decoding updates."""
if verbose:
print(f"Encoding {op}...")
return op.apply(verbose=verbose, decoding_params_hashable=decoding_ops)
return op.apply(verbose=verbose)


@dataclass
Expand All @@ -205,9 +205,12 @@ def _encode_fields(self, verbose: bool) -> None:
input_fields_params = op_params["input_fields"]
for transform_param in op_params["transforms"]:
op = Operation.from_json(input_fields_params, transform_param, self.fields, self.output_path)
new_fields, decoding_updates = process_operation(
op, verbose=verbose, decoding_ops=self.decoding_params.to_yaml()
)
if op.transform_type != "write_file":
new_fields, decoding_updates = process_operation(op, verbose=verbose)
else:
new_fields, decoding_updates = op.apply(
verbose=verbose, decoding_params_hashable=self.decoding_params.to_yaml()
)
# if the coding_updates are not a copy the cache will be wrong
for decoding_update in copy.deepcopy(decoding_updates):
# if the last decoding update has the same input fields we can combine the transforms into one list
Expand Down
4 changes: 2 additions & 2 deletions src/ffsplat/conf/format/SOG-PlayCanvas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ops:

- input_fields: [quaternions]
transforms:
- reparametize:
- reparametrize:
method: unit_sphere
dim: -1

Expand Down Expand Up @@ -122,7 +122,7 @@ ops:

- input_fields: [quats]
transforms:
- reparametize:
- reparametrize:
method: pack_quaternions
to_fields_with_prefix: quats_packed_
dim: -1
Expand Down
4 changes: 3 additions & 1 deletion src/ffsplat/models/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,7 @@ def to_json(self) -> dict[str, Any]:
"params": self.params,
}

def apply(self, verbose: bool, decoding_params_hashable: str) -> tuple[dict[str, "Field"], list[dict[str, Any]]]:
def apply(
self, verbose: bool, decoding_params_hashable: str | None = None
) -> tuple[dict[str, "Field"], list[dict[str, Any]]]:
return apply_transform(self, verbose=verbose, decoding_params_hashable=decoding_params_hashable)
12 changes: 7 additions & 5 deletions src/ffsplat/models/transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ def apply(
"input_fields": [f"{to_fields_with_prefix}indices", f"{to_fields_with_prefix}values"],
"transforms": [
{
"reparametize": {
"reparametrize": {
"method": "unpack_quaternions",
"from_fields_with_prefix": to_fields_with_prefix,
"dim": -1,
Expand Down Expand Up @@ -1114,7 +1114,7 @@ def apply(
field_names = list(parentOp.input_fields.keys())
meta: dict[str, Any] = {
"packer": "ffsplat",
"version": 1,
"version": 1.0,
}
# Readfile no input_fields
for field_name in field_names:
Expand Down Expand Up @@ -1457,7 +1457,7 @@ def get_dynamic_params(params: dict[str, Any]) -> list[dict[str, Any]]:
"flatten": Flatten,
"reshape": Reshape,
"remapping": Remapping,
"reparametize": Reparametrize,
"reparametrize": Reparametrize,
"to_field": ToField,
"permute": Permute,
"to_dtype": ToDType,
Expand All @@ -1473,13 +1473,15 @@ def get_dynamic_params(params: dict[str, Any]) -> list[dict[str, Any]]:


def apply_transform(
parentOp: "Operation", verbose: bool, decoding_params_hashable: str
parentOp: "Operation", verbose: bool, decoding_params_hashable: str | None
) -> tuple[dict[str, "Field"], list[dict[str, Any]]]:
transformation = transformation_map.get(parentOp.transform_type)
if transformation is None:
raise ValueError(f"Unknown transformation: {parentOp.transform_type}")
elif transformation is WriteFile:
decoding_ops: list[dict[str, Any]] = yaml.load(decoding_params_hashable, Loader=yaml.SafeLoader)["ops"]
decoding_ops: list[dict[str, Any]] = []
if decoding_params_hashable is not None:
decoding_ops = yaml.load(decoding_params_hashable, Loader=yaml.SafeLoader)["ops"]
return transformation.apply(
parentOp.params[parentOp.transform_type], parentOp, verbose=verbose, decoding_ops=decoding_ops
)
Expand Down
Loading