Frame Encoder¶
- class FrameEncoder[source]¶
A
FrameEncoder
is the object containing everything required to encode a video frame or an image. It is composed of aCoolChicEncoder
and anĂŚnterCodingModule
.- __init__(
- coolchic_encoder_param: CoolChicEncoderParameter,
- frame_type: Literal['I', 'P', 'B'] = 'I',
- frame_data_type: Literal['rgb', 'yuv420', 'yuv444'] = 'rgb',
- bitdepth: Literal[8, 9, 10, 11, 12, 13, 14, 15, 16] = 8,
- Parameters:
coolchic_encoder_param (CoolChicEncoderParameter) – Parameters for the underlying CoolChicEncoder
frame_type (Literal['I', 'P', 'B']) – More info in coding_structure.py. Defaults to “I”.
frame_data_type (Literal['rgb', 'yuv420', 'yuv444']) – More info in coding_structure.py. Defaults to “rgb”
bitdepth (Literal[8, 9, 10, 11, 12, 13, 14, 15, 16]) – More info in coding_structure.py. Defaults to 8.
- forward(
- reference_frames: List[Tensor] | None = None,
- quantizer_noise_type: Literal['kumaraswamy', 'gaussian', 'none'] = 'kumaraswamy',
- quantizer_type: Literal['softround_alone', 'softround', 'hardround', 'ste', 'none'] = 'softround',
- soft_round_temperature: float | None = 0.3,
- noise_parameter: float | None = 1.0,
- AC_MAX_VAL: int = -1,
- flag_additional_outputs: bool = False,
Perform the entire forward pass of a video frame / image.
Simulate Cool-chic decoding to obtain both the decoded image \(\hat{\mathbf{x}}\) as a \((B, 3, H, W)\) tensor and its associated rate \(\mathrm{R}(\hat{\mathbf{x}})\) as as \((N)\) tensor`, where \(N\) is the number of latent pixels. The rate is given in bits.
- Simulate the saving of the image to a file (Optional).
Only if the model has been set in test mode e.g.
self.set_to_eval()
. Take into account that \(\hat{\mathbf{x}}\) is a float Tensor, which is gonna be saved as integer values in a file.\[\hat{\mathbf{x}}_{saved} = \mathtt{round}(\Delta_q \ \hat{\mathbf{x}}) / \Delta_q, \text{ with } \Delta_q = 2^{bitdepth} - 1\]
Downscale to YUV 420 (Optional). Only if the required output format is YUV420. The current output is a dense Tensor. Downscale the last two channels to obtain a YUV420-like representation. This is done with a nearest neighbor downsampling.
Clamp the output to be in \([0, 1]\).
- Parameters:
reference_frames (List[Tensor] | None) – List of tensors representing the reference frames. Can be set to None if no reference frame is available. Default to None.
quantizer_noise_type (Literal['kumaraswamy', 'gaussian', 'none']) – Defaults to
"kumaraswamy"
.quantizer_type (Literal['softround_alone', 'softround', 'hardround', 'ste', 'none']) – Defaults to
"softround"
.soft_round_temperature (float | None) – Soft round temperature. This is used for softround modes as well as the ste mode to simulate the derivative in the backward. Defaults to 0.3.
noise_parameter (float | None) – noise distribution parameter. Defaults to 1.0.
AC_MAX_VAL (int) – If different from -1, clamp the value to be in \([-AC\_MAX\_VAL; AC\_MAX\_VAL + 1]\) to write the actual bitstream. Defaults to -1.
flag_additional_outputs (bool) – True to fill
CoolChicEncoderOutput['additional_data']
with many different quantities which can be used to analyze Cool-chic behavior. Defaults to False.
- Returns:
Output of the FrameEncoder for the forward pass.
- Return type:
- get_param() OrderedDict[str, Tensor] [source]¶
Return a copy of the weights and biases inside the module.
- Returns:
A copy of all weights & biases in the module.
- Return type:
OrderedDict[str, Tensor]
- set_param(param: OrderedDict[str, Tensor])[source]¶
Replace the current parameters of the module with param.
- Parameters:
param (
OrderedDict[str, Tensor]
) – Parameters to be set.
- reinitialize_parameters() None [source]¶
Reinitialize in place the different parameters of a FrameEncoder.
- Return type:
None
- set_to_train() None [source]¶
Set the current model to training mode, in place. This only affects the quantization.
- Return type:
None
- set_to_eval() None [source]¶
Set the current model to test mode, in place. This only affects the quantization.
- Return type:
None
- load_frame_encoder(raw_bytes: BytesIO) FrameEncoder [source]¶
From already loaded raw bytes, load & return a CoolChicEncoder
- Parameters:
raw_bytes (BytesIO) – Already loaded raw bytes from which we’ll instantiate the CoolChicEncoder.
- Returns:
Frame encoder loaded by the function
- Return type: