keras_utils module
Common multi-backend Keras utilities
- class lib.keras_utils.ColorSpaceConvert(from_space: str, to_space: str)
Bases:
object
Transforms inputs between different color spaces on the GPU
Notes
- The following color space transformations are implemented:
rgb to lab
rgb to xyz
srgb to _rgb
srgb to ycxcz
xyz to ycxcz
xyz to lab
xyz to rgb
ycxcz to rgb
ycxcz to xyz
- Parameters:
from_space (str) – One of “srgb”, “rgb”, “xyz”
to_space (str) – One of “lab”, “rgb”, “ycxcz”, “xyz”
- Raises:
ValueError – If the requested color space conversion is not defined
- lib.keras_utils.frobenius_norm(matrix: Tensor, axis: int = -1, keep_dims: bool = True, epsilon: float = 1e-15) Tensor
Frobenius normalization for Keras Tensor
- Parameters:
matrix (Tensor) – The matrix to normalize
axis (int, optional) – The axis to normalize. Default: -1
keep_dims (bool, Optional) – Whether to retain the original matrix shape or not. Default:
True
epsilon (flot, optional) – Epsilon to apply to the normalization to preven NaN errors on zero values
- Returns:
The normalized output
- Return type:
Tensor
- lib.keras_utils.replicate_pad(image: Tensor, padding: int) Tensor
Apply replication padding to an input batch of images. Expects 4D tensor in BHWC format.
Notes
At the time of writing Keras/Tensorflow does not have a native replication padding method. The implementation here is probably not the most efficient, but it is a pure keras method which should work on TF.
- Parameters:
image (Tensor) – Image tensor to pad
pad (int) – The amount of padding to apply to each side of the input image
- Returns:
The input image with replication padding applied
- Return type:
Tensor