mmagic.apis.inferencers.eg3d_inferencer
¶
Module Contents¶
Classes¶
Base inferencer. |
Attributes¶
- class mmagic.apis.inferencers.eg3d_inferencer.EG3DInferencer(config: Union[mmagic.utils.ConfigType, str], ckpt: Optional[str], device: Optional[str] = None, extra_parameters: Optional[Dict] = None, seed: int = 2022, **kwargs)[source]¶
Bases:
mmagic.apis.inferencers.base_mmagic_inferencer.BaseMMagicInferencer
Base inferencer.
- Parameters
config (str or ConfigType) – Model config or the path to it.
ckpt (str, optional) – Path to the checkpoint.
device (str, optional) – Device to run inference. If None, the best device will be automatically used.
extra_parameters (Dict, optional) – Extra parameters for different models in inference stage.
seed (str, optional) – Seed for inference.
- preprocess(inputs: mmagic.apis.inferencers.base_mmagic_inferencer.InputsType = None) mmagic.utils.ForwardInputs [source]¶
Process the inputs into a model-feedable format.
- Parameters
inputs (List[Union[str, np.ndarray]]) – The conditional inputs for the inferencer. Defaults to None.
- Returns
The preprocessed inputs and data samples.
- Return type
ForwardInputs
- forward(inputs: mmagic.utils.ForwardInputs, interpolation: Optional[str] = 'both', num_images: int = 100) Union[dict, List[dict]] [source]¶
Forward the inputs to the model.
- Parameters
inputs (ForwardInputs) – Model inputs. If data sample (the second element of inputs) is not passed, will generate a sequence of images corresponding to passed interpolation mode.
interpolation (str) – The interpolation mode. Supported choices are ‘both’, ‘conditioning’, and ‘camera’. Defaults to ‘both’.
num_images (int) – The number of frames of interpolation. Defaults to 500.
- Returns
- Output dict corresponds to the input
condition or the list of output dict of each frame during the interpolation process.
- Return type
Union[dict, List[dict]]
- visualize(preds: Union[mmagic.apis.inferencers.base_mmagic_inferencer.PredType, List[mmagic.apis.inferencers.base_mmagic_inferencer.PredType]], vis_mode: str = 'both', save_img: bool = True, save_video: bool = True, img_suffix: str = '.png', video_suffix: str = '.mp4', result_out_dir: str = 'eg3d_output') None [source]¶
Visualize predictions.
- Parameters
preds (Union[PredType, List[PredType]]) – Prediction os model.
vis_mode (str, optional) – Which output to visualize. Supported choices are ‘both’, ‘depth’, and ‘img’. Defaults to ‘all’.
save_img (bool, optional) – Whether save images. Defaults to True.
save_video (bool, optional) – Whether save videos. Defaults to True.
img_suffix (str, optional) – The suffix of saved images. Defaults to ‘.png’.
video_suffix (str, optional) – The suffix of saved videos. Defaults to ‘.mp4’.
result_out_dir (str, optional) – The save director of image and videos. Defaults to ‘eg3d_output’.
- preprocess_img(preds: List[dict]) torch.Tensor [source]¶
Preprocess images in the predictions.
- Parameters
preds (List[dict]) – List of prediction dict of each frame.
- Returns
- Preprocessed image tensor shape like
[num_frame * bz, 3, H, W].
- Return type
torch.Tensor
- preprocess_depth(preds: List[dict]) torch.Tensor [source]¶
Preprocess depth in the predictions.
- Parameters
preds (List[dict]) – List of prediction dict of each frame.
- Returns
- Preprocessed depth tensor shape like
[num_frame * bz, 3, H, W].
- Return type
torch.Tensor
- postprocess(preds: mmagic.apis.inferencers.base_mmagic_inferencer.PredType, imgs: Optional[List[numpy.ndarray]] = None, is_batch: bool = False, get_datasample: bool = False) Dict[str, torch.tensor] [source]¶
Postprocess predictions.
- Parameters
preds (List[Dict]) – Predictions of the model.
imgs (Optional[np.ndarray]) – Visualized predictions.
is_batch (bool) – Whether the inputs are in a batch. Defaults to False.
get_datasample (bool) – Whether to use Datasample to store inference results. If False, dict will be used.
- Returns
Inference results as a dict.
- Return type
Dict[str, torch.Tensor]