渲染API
本章将介绍渲染相关的 API。
landmark.init_inference
- landmark.init_inference(based_model_cls: Model, infer_model_cls: InferenceModule, model_config: str | Path | Config | Dict, inference_config: str | Path | Config | Dict)[源代码]
Initialize the inference engine.
- 参数:
based_model_cls (Model) – a model which is composed of the nerf components.
infer_model_cls (InferenceModule) – an inference module, which is composed of a model, defines the preprocess, forward and postprocess functions.
model_config (Union[str, Path, Config, Dict]) – used to define the model parameters.
inference_config (Union[str, Path, Config, Dict]) – used to define the inference engine.
- 返回:
InferenceEngine
landmark.InferenceModule
- class landmark.InferenceModule(model: Module | None = None)[源代码]
Abstract inference module for inference engine adaptation
- 参数:
model (Optional[nn.Module]) – internal model which is composed of the nerf components
- forward(*args, **kwargs)[源代码]
Define the engine’s forward logic. By default, it uses the forward logic of internal model.
- 参数:
args (list) – a list containing the input parameters of forward.
kwargs (dict) – a dict containing input parameters of forward.
- 返回:
containing the output of the model forward.
- 返回类型:
Tuple[list, dict]
- get_state_dict_from_ckpt(file_path: str | PathLike, map_location: str | Dict[str, str]) Mapping[str, Any][源代码]
Get state_dict from the given file path.
- 参数:
file_path (Union[str, os.PathLike]) – a string or os.PathLike object containing a file name.
map_location (Union[str, Dict[str, str]]) – a string or a dict specifying how to remap storage locations.
- 返回:
the model’s state dict
- 返回类型:
Mapping[str, Any]
- property inter_model
Returns the internal model.
- load_from_state_dict(state_dict: Mapping[str, Any], strict: bool = False)[源代码]
Copies parameters and buffers from
state_dictinto this module and its descendants. IfstrictisTrue, then the keys ofstate_dictmust exactly match the keys returned by this module’sstate_dict()function.- 参数:
state_dict (dict) – a dict containing parameters and persistent buffers.
strict (bool, optional) – whether to strictly enforce that the keys in state_dict match the keys returned by this module’s key
- property merge_config
Returns the offload merge config.
- postprocess(*args, **kwargs)[源代码]
Define the engine’s postprocess logic. By default, it returns the inputs.
- 参数:
args (list) – a list containing the input parameters of postprocess.
kwargs (dict) – a dict containing input parameters of postprocess.
- 返回:
containing the output of the model postprocess.
- 返回类型:
Tuple[list, dict]
- preprocess(*args, **kwargs)[源代码]
Define the engine’s preprocessing logic. By default, it returns the inputs.
- 参数:
args (list) – a list containing the input parameters of preprocess.
kwargs (dict) – a dict containing input parameters of preprocess.
- 返回:
containing the output of the model preprocess.
- 返回类型:
Tuple[list, dict]
- property scene_manager
Returns the scene manager.
landmark.nerf_components.configs.config_parser.BaseConfig
- class landmark.nerf_components.configs.config_parser.BaseConfig(config: dict | None = None)[源代码]
This is a wrapper class for dict objects so that values of which can be accessed as attributes.
- 参数:
config (dict) – The dict object to be wrapped.
- static from_file(filename: str, console_args=None, merge_configs=True)[源代码]
Reads a python file and constructs a corresponding
Configobject.- 参数:
filename (str) – Name of the file to construct the return object.
- 返回:
A
Configobject constructed with information in the file.- 返回类型:
Config- 抛出:
AssertionError – Raises an AssertionError if the file does not exist, or the file is not .py file
示例:
import os
from landmark.nerf_components.configs.config_parser import BaseConfig
octree_gs_render_config_path = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"benchmarks/nerf/octree_gs/confs/matrixcity_2block_render_ddp.py",
)
model_config = BaseConfig.from_file(octree_gs_render_config_path)
inference_config_dict = dict(
parallel_config=dict(
tp_size=1,
),
runtime="Kernel",
kernel_fusion=True,
offload_config=dict(
plane_split=[2, 1],
local_plane_split=[1, 1],
use_nccl=False,
),
)
inference_config = BaseConfig(inference_config_dict)