noether.modeling.modules.layers.vectors_conditioner¶
Classes¶
Configuration for |
|
Embeds a set of named vectors into a single conditioning vector. |
Module Contents¶
- class noether.modeling.modules.layers.vectors_conditioner.VectorsConditionerConfig(/, **data)¶
Bases:
pydantic.BaseModelConfiguration for
VectorsConditioner.All conditioning inputs are expected to be normalized to
[-1, 1]; the underlying sine-cosine embedding runs in NeRF mode.Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
Dimension of the per-vector embedding and per-vector MLP.
- conditioning_spec: noether.data.schemas.FieldDimSpec¶
Mapping from input vector name to its feature dimension, e.g.
{"angle": 1, "shape_params": 3}.
- condition_dim: int | None = None¶
Dimension of the final conditioning vector. Defaults to
hidden_dimifNone.
- max_frequency: float = None¶
Highest frequency band, in units of
π, for the NeRF-mode sine-cosine embedding. Pick based on the smallest spatial scale you need to resolve in normalized coordinates (rough heuristic:1 / typical_input_spacing).
- init_weights: noether.core.types.InitWeightsMode = 'truncnormal002'¶
Weight initialization for MLPs.
- class noether.modeling.modules.layers.vectors_conditioner.VectorsConditioner(config)¶
Bases:
torch.nn.ModuleEmbeds a set of named vectors into a single conditioning vector.
Each input vector named in
config.conditioning_specis encoded with a NeRF-modeContinuousSincosEmbedfollowed by a per-vector MLP. The resulting per-vector embeddings are concatenated and projected tocondition_dimby a shared MLP.Note
All input vectors must be normalized to
[-1, 1]. The underlying sine-cosine embedding uses NeRF-style frequencies tuned for that range; values outside it will alias and produce uninformative embeddings.- Parameters:
config (VectorsConditionerConfig) – configuration for the VectorsConditioner. See
VectorsConditionerConfigfor available options.
- condition_dim¶
- conditioning_spec¶
- embedder¶
- forward(**conditioning_inputs)¶
Embed a set of named vectors into a single conditioning vector.
All vectors declared in
config.conditioning_specmust be supplied as keyword arguments matching the spec names. Inputs must be normalized to[-1, 1].- Parameters:
**conditioning_inputs (torch.Tensor) – Vectors with shape
(batch_size, num_features), keyed by the names declared inconfig.conditioning_spec. Thenum_featuresof each vector must match the dimension declared in the spec. All inputs must share the samebatch_size.- Returns:
Conditioning vector with shape
(batch_size, condition_dim).- Raises:
ValueError – If the supplied inputs don’t match the spec (wrong number of vectors, missing key, wrong rank, or wrong feature dimension).
- Return type:
Example
conditioner = VectorsConditioner( VectorsConditionerConfig( hidden_dim=64, conditioning_spec={"angle": 1, "shape_params": 3}, condition_dim=128, max_frequency=1024, ) ) # Inputs normalized to [-1, 1]. angle = torch.tensor([[0.5], [-0.2]]) # shape (batch_size, 1) shape_params = torch.tensor([[0.1, -0.3, 0.7], [-0.5, 0.2, -0.8]]) # shape (batch_size, 3) condition = conditioner(angle=angle, shape_params=shape_params) # condition.shape == (2, 128)