Shortcuts

mmedit.apis.inferencers.inference_functions

Module Contents

Functions

set_random_seed(seed[, deterministic, use_rank_shift])

Set random seed.

delete_cfg(cfg[, key])

Delete key from config object.

init_model(config[, checkpoint, device])

Initialize a model from config file.

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

Sampling from unconditional models.

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

Sampling from conditional models.

inpainting_inference(model, masked_img, mask)

Inference image with the model.

matting_inference(model, img, trimap)

Inference image(s) with the model.

sample_img2img_model(model, image_path[, target_domain])

Sampling from translation models.

restoration_inference(model, img[, ref])

Inference image with the model.

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

Inference image with the model.

pad_sequence(data, window_size)

Pad frame sequence data.

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

Inference image with the model.

read_image(filepath)

Read image from file.

read_frames(source, start_index, num_frames, ...)

Read frames from file or video.

video_interpolation_inference(model, input_dir, output_dir)

Inference image with the model.

colorization_inference(model, img)

Inference image with the model.

calculate_grid_size(→ int)

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

Attributes

VIDEO_EXTENSIONS

FILE_CLIENT

has_facexlib

mmedit.apis.inferencers.inference_functions.VIDEO_EXTENSIONS = ('.mp4', '.mov', '.avi')[源代码]
mmedit.apis.inferencers.inference_functions.FILE_CLIENT[源代码]
mmedit.apis.inferencers.inference_functions.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.inference_functions.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.inference_functions.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.inference_functions.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.inference_functions.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.inference_functions.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.inference_functions.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.inference_functions.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.inference_functions.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.inference_functions.has_facexlib = True[源代码]
mmedit.apis.inferencers.inference_functions.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.inference_functions.pad_sequence(data, window_size)[源代码]

Pad frame sequence data.

参数
  • data (Tensor) – The frame sequence data.

  • window_size (int) – The window size used in sliding-window framework.

返回

The padded result.

返回类型

data (Tensor)

mmedit.apis.inferencers.inference_functions.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.inference_functions.read_image(filepath)[源代码]

Read image from file.

参数

filepath (str) – File path.

返回

Image.

返回类型

image (np.array)

mmedit.apis.inferencers.inference_functions.read_frames(source, start_index, num_frames, from_video, end_index)[源代码]

Read frames from file or video.

参数
  • source (list | mmcv.VideoReader) – Source of frames.

  • start_index (int) – Start index of frames.

  • num_frames (int) – frames number to be read.

  • from_video (bool) – Weather read frames from video.

  • end_index (int) – The end index of frames.

返回

Images.

返回类型

images (np.array)

mmedit.apis.inferencers.inference_functions.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’

mmedit.apis.inferencers.inference_functions.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.inference_functions.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

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.