mmagic.apis.inferencers.inference_functions
¶
Module Contents¶
Functions¶
|
Set random seed. |
|
Delete key from config object. |
|
Initialize a model from config file. |
|
Pad frame sequence data. |
|
Read image from file. |
|
Read frames from file or video. |
|
Calculate the number of images per row (nrow) to make the grid closer to |
Attributes¶
- mmagic.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.
- mmagic.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.
- mmagic.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
- mmagic.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)
- mmagic.apis.inferencers.inference_functions.read_image(filepath)[源代码]¶
Read image from file.
- 参数
filepath (str) – File path.
- 返回
Image.
- 返回类型
image (np.array)
- mmagic.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)
- mmagic.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