Shortcuts

mmedit.apis.inferencers

Package Contents

Classes

MMEditInferencer

Class to assign task to different inferencers.

Functions

calculate_grid_size(→ int)

Calculate the number of images per row (nrow) to make the grid closer to

colorization_inference(model, img)

Inference image with the model.

delete_cfg(cfg[, key])

Delete key from config object.

init_model(config[, checkpoint, device])

Initialize a model from config file.

inpainting_inference(model, masked_img, mask)

Inference image with the model.

matting_inference(model, img, trimap)

Inference image(s) with the model.

restoration_face_inference(model, img[, ...])

Inference image with the model.

restoration_inference(model, img[, ref])

Inference image with the model.

restoration_video_inference(model, img_dir, ...[, ...])

Inference image with the model.

sample_conditional_model(model[, num_samples, ...])

Sampling from conditional models.

sample_img2img_model(model, image_path[, target_domain])

Sampling from translation models.

sample_unconditional_model(model[, num_samples, ...])

Sampling from unconditional models.

set_random_seed(seed[, deterministic, use_rank_shift])

Set random seed.

video_interpolation_inference(model, input_dir, output_dir)

Inference image with the model.

mmedit.apis.inferencers.calculate_grid_size(num_batches: int = 1, aspect_ratio: int = 1) int[源代码]

Calculate the number of images per row (nrow) to make the grid closer to square when formatting a batch of images to grid.

参数
  • num_batches (int, optional) – Number of images per batch. Defaults to 1.

  • aspect_ratio (int, optional) – The aspect ratio (width / height) of each image sample. Defaults to 1.

返回

Calculated number of images per row.

返回类型

int

mmedit.apis.inferencers.colorization_inference(model, img)[源代码]

Inference image with the model.

参数
  • model (nn.Module) – The loaded model.

  • img (str) – Image file path.

返回

The predicted colorization result.

返回类型

Tensor

mmedit.apis.inferencers.delete_cfg(cfg, key='init_cfg')[源代码]

Delete key from config object.

参数
  • cfg (str or mmengine.Config) – Config object.

  • key (str) – Which key to delete.

mmedit.apis.inferencers.init_model(config, checkpoint=None, device='cuda:0')[源代码]

Initialize a model from config file.

参数
  • config (str or mmengine.Config) – Config file path or the config object.

  • checkpoint (str, optional) – Checkpoint path. If left as None, the model will not load any weights.

  • device (str) – Which device the model will deploy. Default: ‘cuda:0’.

返回

The constructed model.

返回类型

nn.Module

mmedit.apis.inferencers.inpainting_inference(model, masked_img, mask)[源代码]

Inference image with the model.

参数
  • model (nn.Module) – The loaded model.

  • masked_img (str) – File path of image with mask.

  • mask (str) – Mask file path.

返回

The predicted inpainting result.

返回类型

Tensor

mmedit.apis.inferencers.matting_inference(model, img, trimap)[源代码]

Inference image(s) with the model.

参数
  • model (nn.Module) – The loaded model.

  • img (str) – Image file path.

  • trimap (str) – Trimap file path.

返回

The predicted alpha matte.

返回类型

np.ndarray

mmedit.apis.inferencers.restoration_face_inference(model, img, upscale_factor=1, face_size=1024)[源代码]

Inference image with the model.

参数
  • model (nn.Module) – The loaded model.

  • img (str) – File path of input image.

  • upscale_factor (int, optional) – The number of times the input image is upsampled. Default: 1.

  • face_size (int, optional) – The size of the cropped and aligned faces. Default: 1024.

返回

The predicted restoration result.

返回类型

Tensor

mmedit.apis.inferencers.restoration_inference(model, img, ref=None)[源代码]

Inference image with the model.

参数
  • model (nn.Module) – The loaded model.

  • img (str) – File path of input image.

  • ref (str | None) – File path of reference image. Default: None.

返回

The predicted restoration result.

返回类型

Tensor

mmedit.apis.inferencers.restoration_video_inference(model, img_dir, window_size, start_idx, filename_tmpl, max_seq_len=None)[源代码]

Inference image with the model.

参数
  • model (nn.Module) – The loaded model.

  • img_dir (str) – Directory of the input video.

  • window_size (int) – The window size used in sliding-window framework. This value should be set according to the settings of the network. A value smaller than 0 means using recurrent framework.

  • start_idx (int) – The index corresponds to the first frame in the sequence.

  • filename_tmpl (str) – Template for file name.

  • max_seq_len (int | None) – The maximum sequence length that the model processes. If the sequence length is larger than this number, the sequence is split into multiple segments. If it is None, the entire sequence is processed at once.

返回

The predicted restoration result.

返回类型

Tensor

mmedit.apis.inferencers.sample_conditional_model(model, num_samples=16, num_batches=4, sample_model='ema', label=None, **kwargs)[源代码]

Sampling from conditional models.

参数
  • model (nn.Module) – Conditional models in MMGeneration.

  • num_samples (int, optional) – The total number of samples. Defaults to 16.

  • num_batches (int, optional) – The number of batch size for inference. Defaults to 4.

  • sample_model (str, optional) – Which model you want to use. [‘ema’, ‘orig’]. Defaults to ‘ema’.

  • label (int | torch.Tensor | list[int], optional) – Labels used to generate images. Default to None.,

返回

Generated image tensor.

返回类型

Tensor

mmedit.apis.inferencers.sample_img2img_model(model, image_path, target_domain=None, **kwargs)[源代码]

Sampling from translation models.

参数
  • model (nn.Module) – The loaded model.

  • image_path (str) – File path of input image.

  • style (str) – Target style of output image.

返回

Translated image tensor.

返回类型

Tensor

mmedit.apis.inferencers.sample_unconditional_model(model, num_samples=16, num_batches=4, sample_model='ema', **kwargs)[源代码]

Sampling from unconditional models.

参数
  • model (nn.Module) – Unconditional models in MMGeneration.

  • num_samples (int, optional) – The total number of samples. Defaults to 16.

  • num_batches (int, optional) – The number of batch size for inference. Defaults to 4.

  • sample_model (str, optional) – Which model you want to use. [‘ema’, ‘orig’]. Defaults to ‘ema’.

返回

Generated image tensor.

返回类型

Tensor

mmedit.apis.inferencers.set_random_seed(seed, deterministic=False, use_rank_shift=True)[源代码]

Set random seed.

In this function, we just modify the default behavior of the similar function defined in MMCV.

参数
  • seed (int) – Seed to be used.

  • deterministic (bool) – Whether to set the deterministic option for CUDNN backend, i.e., set torch.backends.cudnn.deterministic to True and torch.backends.cudnn.benchmark to False. Default: False.

  • rank_shift (bool) – Whether to add rank number to the random seed to have different random seed in different threads. Default: True.

mmedit.apis.inferencers.video_interpolation_inference(model, input_dir, output_dir, start_idx=0, end_idx=None, batch_size=4, fps_multiplier=0, fps=0, filename_tmpl='{:08d}.png')[源代码]

Inference image with the model.

参数
  • model (nn.Module) – The loaded model.

  • input_dir (str) – Directory of the input video.

  • output_dir (str) – Directory of the output video.

  • start_idx (int) – The index corresponding to the first frame in the sequence. Default: 0

  • end_idx (int | None) – The index corresponding to the last interpolated frame in the sequence. If it is None, interpolate to the last frame of video or sequence. Default: None

  • batch_size (int) – Batch size. Default: 4

  • fps_multiplier (float) – multiply the fps based on the input video. Default: 0.

  • fps (float) – frame rate of the output video. Default: 0.

  • filename_tmpl (str) – template of the file names. Default: ‘{:08d}.png’

class mmedit.apis.inferencers.MMEditInferencer(task: Optional[str] = None, config: Optional[Union[mmedit.utils.ConfigType, str]] = None, ckpt: Optional[str] = None, device: torch.device = None, extra_parameters: Optional[Dict] = None, seed: int = 2022)[源代码]

Class to assign task to different inferencers.

参数
  • task (str) – Inferencer task.

  • 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.

  • seed (int) – The random seed used in inference. Defaults to 2022.

__call__(**kwargs) Union[Dict, List[Dict]]

Call the inferencer.

参数

kwargs – Keyword arguments for the inferencer.

返回

Results of inference pipeline.

返回类型

Union[Dict, List[Dict]]

get_extra_parameters() List[str]

Each inferencer may has its own parameters. Call this function to get these parameters.

返回

List of unique parameters.

返回类型

List[str]

Read the Docs v: latest
Versions
master
latest
stable
zyh-doc-notfound-extend
Downloads
pdf
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.