DeepSDFStruct.deep_sdf.models#
DeepSDF Model Classes#
This module provides the DeepSDFModel class, which wraps a trained decoder network and latent vectors for evaluating learned implicit representations.
The model can be used to: - Decode latent codes to SDF values at query points - Export models for deployment (TorchScript/LibTorch) - Integrate with gradient-based optimization
Classes#
- DeepSDFModel
Main interface for trained DeepSDF models, combining a decoder network with learned latent vectors.
Classes
|
Wrapper for trained DeepSDF decoder and latent vectors. |
- class DeepSDFStruct.deep_sdf.models.DeepSDFModel(decoder, trained_latent_vectors, device)#
Bases:
objectWrapper for trained DeepSDF decoder and latent vectors.
This class provides a convenient interface for using trained DeepSDF models. It combines the decoder network (which maps latent+position to SDF values) with the trained latent vectors (which encode different shapes).
The model supports both constant latent codes (one code for all query points) and spatially-varying codes (different codes per query point), enabling flexible shape representation.
- Parameters:
decoder (torch.nn.Module) – The trained decoder network. Should accept input of shape (N, latent_dim + 3) and output SDF values of shape (N, 1).
trained_latent_vectors (torch.Tensor) – Trained latent codes of shape (num_shapes, latent_dim). Each row encodes one learned shape.
device (str or torch.device) – Device for computation (‘cpu’ or ‘cuda’).
- _decoder#
The decoder network.
- Type:
torch.nn.Module
- _trained_latent_vectors#
The latent code library.
- Type:
torch.Tensor
- device#
Computation device.
- Type:
str or torch.device
- _decode_sdf(latent_vec, queries)#
Decode SDF values from a latent code and spatial queries.
- export_libtorch_executable(filename)#
Export model to TorchScript for C++ deployment.
- Parameters:
filename (str)
Examples
>>> import torch >>> from DeepSDFStruct.deep_sdf.models import DeepSDFModel >>> >>> # Assume we have a trained decoder and latent vectors >>> # decoder = ... >>> # latents = torch.randn(10, 256) # 10 shapes, 256-dim codes >>> >>> # Create model >>> model = DeepSDFModel(decoder, latents, device='cuda') >>> >>> # Query first shape >>> points = torch.rand(1000, 3, device='cuda') >>> distances = model._decode_sdf(latents[0], points) >>> >>> # Use with SDFfromDeepSDF >>> from DeepSDFStruct.SDF import SDFfromDeepSDF >>> sdf = SDFfromDeepSDF(model, latent_code=latents[0]) >>> mesh = create_3D_mesh(sdf, N_base=64, mesh_type='surface')
Notes
The decoder architecture typically consists of multiple fully-connected layers with skip connections. See networks/ for architecture definitions.
References
- export_libtorch_executable(filename)#
Export the trained decoder model to a TorchScript file for use with LibTorch (C++).
- Parameters:
filename (str) – Path where the TorchScript model will be saved (e.g. “decoder.pt”).
Example
>>> model.export_libtorch_executable("decoder.pt") Example input: tensor([[...]]) Example Output: tensor([[...]]) # The file "decoder.pt" is now ready for loading in LibTorch.