Misc API¶
Miscellaneous API.
Sync timer¶
- class kiui.timer.sync_timer(name=None, flag_env='TIMER', logger_func=<built-in function print>)[source]¶
- Synchronized timer to count the inference time of nn.Module.forward or else. - sync_timercan be used as a context manager or a decorator.- Example as context manager: - with timer('name'): run() - Example as decorator: - @timer('name') def run(): pass - Parameters:
- name (str, optional) – name of the timer. Defaults to None. 
- flag_env (str, optional) – environment variable to check if logging is enabled. Defaults to “TIMER”. 
- logger_func (Callable, optional) – function to log the result. Defaults to - print.
 
 - Note - Set environment variable - $flag_envto- 1to enable logging! default is- TIMER=1.
Super-resolution¶
- kiui.sr.sr(image: ndarray, scale: Literal[2, 4, 8] = 2, device=None)[source]¶
- lazy load functional super-resolution API for convenience. - Parameters:
- image (ndarray) – input image, uint8/float32 [H, W, 3] 
- scale (Literal[2, 4, 8], optional) – upscale factor. Defaults to 2. 
- device (torch.device, optional) – device to put SR models, if not provided, will try to use ‘cuda’. Defaults to None. 
 
- Returns:
- super-resolutioned image, uint8/float32 [H * scale, W * scale, 3] 
- Return type:
- ndarray 
 
Grid-put¶
- kiui.grid_put.grid_put(shape: Sequence[int], coords: Tensor, values: Tensor, mode: Literal[‘nearest’, ‘linear’, ‘linear-mipmap’] = 'linear-mipmap', min_resolution: int = 32, return_count: bool = False) Tensor[source]¶
- put back values to an image according to the coords. inverse operation of - F.grid_sample.- Parameters:
- shape (Sequence[int]) – shape of the image, support 2D image and 3D volume, sequence of [D] 
- coords (Tensor) – coordinates, float [N, D] in [-1, 1]. 
- values (Tensor) – values, float [N, C]. 
- mode (str, Literal[‘nearest’, ‘linear’, ‘linear-mipmap’]) – interpolation mode, see https://github.com/ashawkey/grid_put for examples. Defaults to ‘linear-mipmap’. 
- min_resolution (int, optional) – minimal resolution for mipmap. Defaults to 32. 
- return_count (bool, optional) – whether to return the summed value and weights, instead of the divided results. Defaults to False. 
 
- Returns:
- the restored image/volume, float [H, W, C]/[H, W, D, C]. 
- Return type:
- Tensor