neural_de.transformations packageο
Subpackagesο
- neural_de.transformations.diffusion package
- Subpackages
- neural_de.transformations.diffusion.unet package
- Submodules
- neural_de.transformations.diffusion.unet.attention_block module
- neural_de.transformations.diffusion.unet.downsample module
- neural_de.transformations.diffusion.unet.nn module
- neural_de.transformations.diffusion.unet.qkv_attention module
- neural_de.transformations.diffusion.unet.qkv_attention_legacy module
- neural_de.transformations.diffusion.unet.res_block module
- neural_de.transformations.diffusion.unet.timestep_block module
- neural_de.transformations.diffusion.unet.timestep_embed_sequential module
- neural_de.transformations.diffusion.unet.unet_model module
- neural_de.transformations.diffusion.unet.upsample module
- neural_de.transformations.diffusion.unet.utils module
- Module contents
- neural_de.transformations.diffusion.unet package
- Submodules
- neural_de.transformations.diffusion.diffpure_config module
DiffPureConfig
DiffPureConfig.weights_path
DiffPureConfig.img_shape
DiffPureConfig.attention_resolutions
DiffPureConfig.num_classes
DiffPureConfig.dims
DiffPureConfig.learn_sigma
DiffPureConfig.num_channels
DiffPureConfig.num_head_channels
DiffPureConfig.num_res_blocks
DiffPureConfig.resblock_updown
DiffPureConfig.use_fp16
DiffPureConfig.use_scale_shift_norm
DiffPureConfig.num_heads
DiffPureConfig.num_heads_upsample
DiffPureConfig.channel_mult
DiffPureConfig.dropout
DiffPureConfig.use_new_attention_order
DiffPureConfig.t
DiffPureConfig.t_delta
DiffPureConfig.use_bm
DiffPureConfig.use_checkpoint
DiffPureConfig.conv_resample
DiffPureConfig.sample_step
DiffPureConfig.rand_t
DiffPureConfig.attention_resolutions
DiffPureConfig.channel_mult
DiffPureConfig.conv_resample
DiffPureConfig.dims
DiffPureConfig.dropout
DiffPureConfig.img_shape
DiffPureConfig.learn_sigma
DiffPureConfig.num_channels
DiffPureConfig.num_classes
DiffPureConfig.num_head_channels
DiffPureConfig.num_heads
DiffPureConfig.num_heads_upsample
DiffPureConfig.num_res_blocks
DiffPureConfig.rand_t
DiffPureConfig.resblock_updown
DiffPureConfig.sample_step
DiffPureConfig.t
DiffPureConfig.t_delta
DiffPureConfig.use_bm
DiffPureConfig.use_checkpoint
DiffPureConfig.use_fp16
DiffPureConfig.use_new_attention_order
DiffPureConfig.use_scale_shift_norm
DiffPureConfig.weights_path
- neural_de.transformations.diffusion.diffusion_enhancer module
- neural_de.transformations.diffusion.rev_guided_diffusion module
- neural_de.transformations.diffusion.rev_vpsde module
- Module contents
- Subpackages
Submodulesο
neural_de.transformations.brightness_enhancer moduleο
Image brightness enhancement method.
- class neural_de.transformations.brightness_enhancer.BrightnessEnhancer(logger=None)[source]ο
Bases:
BaseTransformation
BaseTransformation method for image brightness change. It uses NPLIE-based method for brightness enhancement, and Opencv for transforming the image.
Example :
See the notebook examples/BrightnessEnhancer_example.ipynb for more usage details.
1- Import the class
. code-block:: python
from neural_de.transformations import BrightnessEnhancer
2- Create an instance of BrightnessEnhancer.
. code-block:: python
bright_ehn = BrightnessEnhancer()
3- Apply the brightness change to a batch of images to a given shape
. code-block:: python
out_images = bright_ehn.transform(images)
- Parameters:
logger (
Optional
[Logger
]) β It is recommended to use the Confiance logger, obtainable withneural_de.utils.get_logger β
None (If) β
provided. (one logging with stdout will be) β
- enhance_brightness(image)[source]ο
- Parameters:
Image β numpy array format with float32 dtype.
- Returns:
Image numpy array format with float32 dtype.
- transform(images)[source]ο
Improve brightness a batch of images using a NPLIE-based method.
- Parameters:
images (
Union
[list
[ndarray
],ndarray
]) β Batch of images. Each image should be of anp.ndarray
of target_shape (h,w, channels). Images dimensions do not need to be the same across the batch.- Returns:
The same images with improved brightness.
neural_de.transformations.centered_zoom moduleο
Simple wrapper to share experimental results on working params for a CenteredZoom
- class neural_de.transformations.centered_zoom.CenteredZoom(keep_ratio, logger=None)[source]ο
Bases:
BaseTransformation
CenteredZoom image transformation based on a numpy implementation. Given a batch of 3-channels image of size width x height, return the centered tile of size width*keep_ratio x height*keep_ratio. This transformation does not perform any resolution enhancement of the returned content. See ResolutionEnhancer to perform both crop and resolution enhancement.
- Parameters:
keep_ratio (
float
) β The proportion of the input image we keep. Must be in ]0,1[.logger (
Optional
[Logger
]) β It is recommended to use the Confiance logger, obtainable with neural_de.utils.get_logger(β¦). If None, one logging with stdout will be provided.
- transform(images)[source]ο
Apply CenteredZoom to a batch of images using numpy slicing method.
- Parameters:
images (
Union
[list
[ndarray
],ndarray
]) β Batch of images. Each image should be of anp.ndarray
of target_shape (h,w, channels). Images dimensions do not need to be the same across the batch.- Returns:
The images zoomed to a given ratio in respect to its center.
- transform_with_annotations(images, bbox)[source]ο
Transform bounding boxes to the reference in the new zoomed image. :type images:
Union
[list
[ndarray
],ndarray
] :param images: Batch of images. Each image should be of anp.ndarray
of target_shape (h,w, :param channels). Images dimensions do not need to be the same across the batch.: :type bbox:list
:param bbox: list of list of list [batch_dim, nb_object_per_image, [x1, y1, x2, y2]] :param with the x1: :param y1: :param x2: :param y2 bounding box position in the original image.:- Returns:
The images zoomed to a given ratio in respect to its center. The list of
np.ndarray
with the x1, y1, x2, y2 bounding box position in the zoomedimage.
neural_de.transformations.de_rain_enhancer moduleο
DeRain enhancer
- class neural_de.transformations.de_rain_enhancer.DeRainConfig(upsample_mode='bilinear', ngf=64, n_blocks=9, use_dropout=False, input_nc=3, output_nc=3, padding_type='reflect')[source]ο
Bases:
object
Interal configuration of the DeRain enhancer.
-
input_nc:
int
= 3ο
-
n_blocks:
int
= 9ο
-
ngf:
int
= 64ο
-
output_nc:
int
= 3ο
-
padding_type:
str
= 'reflect'ο
-
upsample_mode:
str
= 'bilinear'ο
-
use_dropout:
bool
= Falseο
-
input_nc:
- class neural_de.transformations.de_rain_enhancer.DeRainEnhancer(device='cpu', logger=None)[source]ο
Bases:
BaseTransformation
Provides a rain removal image transformation using the GT-Rain Derain Model.
- Parameters:
device (
str
) β Any torch-compatible device string.logger (
Optional
[Logger
]) β It is recommended to use the Confiance logger, obtainable with neural_de.utils.get_logger(β¦). If None, one logging with stdout will be provided.
- transform(images)[source]ο
Removes the rain in a batch of images. It differs from style transfer, as it does not remove pools and ground reflection. The outputs are as βas if the rained just stop fallingβ.
- Parameters:
images (
Union
[list
[ndarray
],ndarray
]) β Batch of images. Each image should be of anp.ndarray
of target_shape (h,w, channels). Images dimensions should be identical across one batch.- Return type:
ndarray
- Returns:
The same images without rain falling on it.
neural_de.transformations.de_snow_enhancer moduleο
Snow removal enhancer - Prenet Based implementation
- class neural_de.transformations.de_snow_enhancer.DeSnowEnhancer(device='cpu', logger=None)[source]ο
Bases:
BaseTransformation
Snow Removal Enhancer, Prenet based implementation.
** WARNING ** : The current method may have bad results on real images. The model had been trained on a simulated dataset, thus if the dataset is so different of the trained dataset, the results are not guaranteed.
- Parameters:
device β Any torch-compatible device string.
logger β It is recommended to use the Confiance logger, obtainable with neural_de.utils.get_logger(β¦). If None, one logging with stdout will be provided.
- transform(images)[source]ο
Removes the snow in a batch of images.
WARNING : The current method may have bad results on real images.
- Parameters:
images (
ndarray
) β Batch of images. Each image should be of anp.ndarray
of target_shape (h,w, channels). Images dimensions should be identical across one batch.- Return type:
ndarray
- Returns:
The same images without snow on it.
neural_de.transformations.kernel_deblurring_enhancer moduleο
Simple wrapper to share experimental results on working params for a Deblurring Kernel
- class neural_de.transformations.kernel_deblurring_enhancer.KernelDeblurringEnhancer(kernel='high', custom_kernel=None, logger=None)[source]ο
Bases:
BaseTransformation
Kernel Deblurring image transformation based on OpenCv implementation. Provides pre-set filter of medium and high intensity.
- Parameters:
kernel (
str
) βhigh
ormedium
: use a pre-set kernel with high or medium intensity.custom β Optional, custom kernel to use. It can be any non empty 2D matrix. If provided, the value of kernel will not be used.
logger (
Optional
[Logger
]) β It is recommended to use the Confiance logger, obtainable with neural_de.utils.get_logger(β¦). If None, one logging with stdout will be provided.
- transform(images)[source]ο
Deblur a batch of images using a Kernel-based method.
- Parameters:
images (
Union
[list
[ndarray
],ndarray
]) β Batch of images. Each image should be of anp.ndarray
of target_shape (h,w, channels). Images dimensions do not need to be the same across the batch.- Returns:
The same images with less blurr.
neural_de.transformations.night_image_enhancer moduleο
Night to day enhancer - Maxim based implementation
- class neural_de.transformations.night_image_enhancer.NightConfig(variant='S-2', dropout_rate=0.0, num_outputs=3, use_bias=True, num_supervision_scales=3)[source]ο
Bases:
object
Static Enhancer configuration
-
dropout_rate:
float
= 0.0ο
-
num_outputs:
int
= 3ο
-
num_supervision_scales:
int
= 3ο
-
use_bias:
bool
= Trueο
-
variant:
str
= 'S-2'ο
-
dropout_rate:
- class neural_de.transformations.night_image_enhancer.NightImageEnhancer(device='cpu', logger=None)[source]ο
Bases:
BaseTransformation
Provides Night to Day image transformation using the MAXIM model.
- Parameters:
logger (
Optional
[Logger
]) β It is recommended to use the Confiance logger, obtainable with neural_de.utils.get_logger(β¦). If None, one logging with stdout will be provided.
- transform(images)[source]ο
Transform a batch of night image into βday imagesβ, ie the same image but looking as if taken in daylight.
- Parameters:
images (
Union
[list
[ndarray
],ndarray
]) β Batch of images. Each image should be of anp.ndarray
of target_shape (h,w, channels).- Returns:
The same images transformed as if taken in daylight.
neural_de.transformations.resolution_enhancer moduleο
Implementation of the ResolutionEnhancer method.
- neural_de.transformations.resolution_enhancer.UPSCALE_MODELο
version of the transformer model used for image upscaling
- class neural_de.transformations.resolution_enhancer.ResolutionEnhancer(device='cpu', logger=None)[source]ο
Bases:
BaseTransformation
BaseTransformation method for image resolution change. It uses neural-based method for resolution enhancement, and Opencv for diminishing the resolution.
- Example :
See the notebook examples/ResolutionEnhancer_example.ipynb for more usage details.
1- Import the class
from neural_de.transformations import ResolutionEnhancer
2- Create an instance of ResolutionEnhancer.
device ="Cuda"
is recommended if you have a gpu and torch with cuda enabled.res_shift = ResolutionEnhancer(device= "cpu")
3- Apply the resolution change to a batch of images to a given shape
out_images = res_shift.transform(images, ratio=2)
- Parameters:
device (
str
) β Any torch-compatible device string.logger (
Optional
[Logger
]) β It is recommended to use the Confiance logger, obtainable with neural_de.utils.get_logger(β¦). If None, one logging with stdout will be provided.
- transform(images, target_shape, crop_ratio=0.0)[source]ο
Modify the resolution of a batch of images to a given target_shape.
- Parameters:
images (
Union
[list
[ndarray
],ndarray
]) β Batch of images. Each image should be of anp.ndarray
of target_shape (h,w, channels)target_shape (
Union
[list
,tuple
]) β New resolution (h,w) in pixel.crop_ratio (
float
) β image cropping ratio (range in [0., 1.[)
- Return type:
ndarray
- Returns:
Images with new resolution.
neural_de.transformations.transformation moduleο
Parent class for any transformation method.
- class neural_de.transformations.transformation.BaseTransformation(logger=None)[source]ο
Bases:
object
Parent class for any transformation methods of the library. Provides the methods for logging and input validation.
- Parameters:
logger (
Optional
[Logger
]) β logging.logger. It is recommended to use the Confiance one, obtainable with neural_de.utils.get_logger(β¦)
neural_de.transformations.transformation_pipeline moduleο
Transformation pipeline for automation of multiple transformations methods
- class neural_de.transformations.transformation_pipeline.TransformationPipeline(config, logger=None)[source]ο
Bases:
BaseTransformation
Provides a pipeline object, to facilitate the automation of multiple transformations methods, and/or offer loading from a yaml file.
You can check the example notebook examples/Pipeline_example.ipynb for details on the syntax and usage. An example of valid config file can be found in examples/config/conf_user.yaml
- Parameters:
config (
Union
[str
,list
,Path
]) β either a path toward a yaml configuration file, or a list of dict.logger (
Optional
[Logger
]) β It is recommended to use the confiance.ai logger, obtainable with neural_de.utils.get_logger(β¦). If None, one logging with stdout will be provided.
- transform(images)[source]ο
Sequentially apply every method of the pipeline on a batch of image, and returns the resulting images.
- Parameters:
images (
Union
[list
,ndarray
]) β Batch of images. Each image should be of anp.ndarray
of target_shape (h,w, channels)- Return type:
Union
[list
,ndarray
]- Returns:
Resulting batch of images, one per image provided.
Module contentsο
Module with the main images transformations methods of the neural_de library.
You can find more on how to use any of the proposed method in ./examples
, or in the methodβs
class documentation.
- List of the available methods :
ResolutionEnhancer: enhance image resolution
NightImageEnhancer: transform night images into daylight ones
KernelDeblurringEnhancer: Improve blurry images
DeSnowEnhancer: Removes snow from images
DeRainEnhancer: Removes rain from images
BrightnessEnhancer: Improves image brightness
CenteredZoom: Centered crop of an image at a given ratio
DiffusionEnhancer : Enhance the image using diffusion-based denoising
- Special methods :
TransformationPipeline : Allows the automation of any combination of the previous methods, and loading from file.