Shortcuts

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

pad_sequence(data, window_size)

Pad frame sequence data.

read_image(filepath)

Read image from file.

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

Read frames from file or video.

calculate_grid_size(→ int)

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

Attributes

VIDEO_EXTENSIONS

FILE_CLIENT

mmagic.apis.inferencers.inference_functions.VIDEO_EXTENSIONS = ('.mp4', '.mov', '.avi')[source]
mmagic.apis.inferencers.inference_functions.FILE_CLIENT[source]
mmagic.apis.inferencers.inference_functions.set_random_seed(seed, deterministic=False, use_rank_shift=True)[source]

Set random seed.

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

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

mmagic.apis.inferencers.inference_functions.delete_cfg(cfg, key='init_cfg')[source]

Delete key from config object.

Parameters
  • cfg (str or mmengine.Config) – Config object.

  • key (str) – Which key to delete.

mmagic.apis.inferencers.inference_functions.init_model(config, checkpoint=None, device='cuda:0')[source]

Initialize a model from config file.

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

Returns

The constructed model.

Return type

nn.Module

mmagic.apis.inferencers.inference_functions.pad_sequence(data, window_size)[source]

Pad frame sequence data.

Parameters
  • data (Tensor) – The frame sequence data.

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

Returns

The padded result.

Return type

data (Tensor)

mmagic.apis.inferencers.inference_functions.read_image(filepath)[source]

Read image from file.

Parameters

filepath (str) – File path.

Returns

Image.

Return type

image (np.array)

mmagic.apis.inferencers.inference_functions.read_frames(source, start_index, num_frames, from_video, end_index)[source]

Read frames from file or video.

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

Returns

Images.

Return type

images (np.array)

mmagic.apis.inferencers.inference_functions.calculate_grid_size(num_batches: int = 1, aspect_ratio: int = 1) int[source]

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

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

Returns

Calculated number of images per row.

Return type

int

Read the Docs v: latest
Versions
latest
stable
0.x
Downloads
pdf
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.