neural_de.utils packageο
Submodulesο
neural_de.utils.math moduleο
Collection of utility math-based utility methods
- neural_de.utils.math.crop_image(image, ratio)[source]ο
Return cropped image depends on a ratio of its size Ratio = .3 => crop 30% of image size
- Parameters:
image (
ndarray
) β original imageratio (
float
) β Value in rage [0., 1.[
- Return type:
ndarray
- Returns:
Cropped image from its center
- neural_de.utils.math.get_pad_value(dim, ratio)[source]ο
Return the number of pixel to add to dim so that it will be a multiple of ratio
- Parameters:
dim (
int
) β Actual number of pixel in a dimensionratio (
int
) β Value dim should be a multiple of
- Return type:
int
- Returns:
Number of pixel to pad
neural_de.utils.model_manager moduleο
This module implements tools functions to manage external models used within the component
neural_de.utils.twe_logger moduleο
This module provides a logger, adapted from the original Confiance logger, for logging messages with specified formatting and output control. It can log messages to the standard output, to a specified file, or both.
- Usage:
Import the module, then get the default logger:
. code-block:: python
import twe_logger logger = twe_logger.get_logger()
If you need a logger with different parameters, call
get_logger(.)
with the desired parameters:. code-block:: python
logger = twe_logger.get_logger(filename=βmy_logs.logβ) logger = twe_logger.get_logger( name=βmy_loggerβ, level=βdebugβ,filename=βmy_logs.logβ, output=βbothβ)
Then, use the logger within your code:
. code-block:: python
logger.info(βThis is an info messageβ) logger.error(βThis is an error messageβ)
- neural_de.utils.twe_logger.LOGGER_DEFAULT_NAMEο
Default name for the neural_de logger
- neural_de.utils.twe_logger.LOG_LEVELο
Logging level for all the methods. Options are
"info"
,"debug"
, βwarningβ, and ``"critical"
- neural_de.utils.twe_logger.LOG_OUTPUTο
Logging target. Should be
"stdout"
,"file"
, or"both"
. If'file'
or'both'
,LOG_FILE
will be used as the destination file.
- neural_de.utils.twe_logger.LOG_FILEο
Name of the file where the logger should write.
- neural_de.utils.twe_logger.get_logger(name='neural_de_logger', level='debug', filename='log.csv', output='stdout')[source]ο
Creates and returns a logger.
- Parameters:
name (
str
) β Optional, the name of the logger.level (
Union
[int
,str
]) β Optional, the logging level.filename (
str
) β Optional, name of the file where the logger should write.output (
str
) β Optional, where should the logger write. Can bestdout
,file
, orboth
.
- Return type:
Logger
- Returns:
The logger.
- neural_de.utils.twe_logger.log_and_raise(logger, exception, content)[source]ο
Log an error message then raising an exception with the same message.
- Parameters:
logger (
Logger
) β Logger instance.exception (
type
[Exception
]) β The exception we want to raise.content (
str
) β Text content to log and add to the raised exception.
- Raises:
exception β Raises the provided Exception with the provided message
- Return type:
None
neural_de.utils.validation moduleο
This module contains a collection of utility functions to verify that the inputs of the transformation methods are valid.
- neural_de.utils.validation.is_batch_valid(image_batch, same_dim=False)[source]ο
Check if
images
is a valid batch of image: either a list of array numpy of dimension 3 (h,w, c), or a single numpy array of dimension 4 (batch_size, h, w, c).- Parameters:
image_batch (
Union
[list
,ndarray
]) β Input to check.same_dim β If True, will also verify that every image has the same dimension
- Returns:
- The bool is True if the input is a valid batch of images, and
False otherwise. The string is empty if the bool is True, if not it contains the reason of the non validation.
- Return type:
Tuple of (bool,string)
Module contentsο
Modules with the different utility methods of the library :
logging
model download and checking
input validation
mathematical operations