Utils¶
nnio.Preprocessing¶
- class nnio.Preprocessing(resize=None, dtype=None, divide_by_255=None, means=None, stds=None, scales=None, imagenet_scaling=False, to_gray=None, padding=False, channels_first=False, batch_dimension=False, bgr=False)¶
This class provides functionality of the image preprocessing.
Example:
preproc = nnio.Preprocessing( resize=(224, 224), dtype='float32', divide_by_255=True, means=[0.485, 0.456, 0.406], stds=[0.229, 0.224, 0.225], batch_dimension=True, channels_first=True, ) # Use with numpy image image_preprocessed = preproc(image_rgb) # Or use to read image from disk image_preprocessed = preproc('path/to/image.png') # Or use to read image from the web image_preprocessed = preproc('http://www.example.com/image.png')
Object of this type is returned every time you call
get_preprocessing()
method of any model from Model Zoo.- __eq__(other)¶
Compare two
Preprocessing
objects. ReturnsTrue
only if all preprocessing parameters are the same.
- __init__(resize=None, dtype=None, divide_by_255=None, means=None, stds=None, scales=None, imagenet_scaling=False, to_gray=None, padding=False, channels_first=False, batch_dimension=False, bgr=False)¶
- Parameters
resize –
None
ortuple
. (width, height) - the new size of imagedtype –
str
ornp.dtype
. Data type. By default will useuint8
.divide_by_255 –
bool
. Divide input image by 255. This is applied beforemeans
,stds
andscales
.means –
float
or iterable orNone
. Substract these values from each channelstds – float` or iterable or
None
. Divide each channel by these valuesscales –
float
or iterable orNone
. Multipy each channel by these valuesimagenet_scaling – apply imagenet scaling. It is equivalent to
divide_by_255=True, means=[0.485, 0.456, 0.406], stds=[0.229, 0.224, 0.225]
. If this is specified, argumentsdivide_by_255
,means
,stds
,scales
must beNone
.to_gray – if
int
, then convert rgb image to grayscale with specified number of channels (usually 1 or 3).padding –
bool
. IfTrue
, images will be resized with the same aspect ratiochannels_first –
bool
. IfTrue
, image will be returned in[B]CHW
format. IfFalse
,[B]HWC
.batch_dimension –
bool
. IfTrue
, add first dimension of size 1.bgr –
bool
. IfTrue
, change channels to BRG order. IfFalse
, keep the RGB order.
- __str__()¶
- Returns
full description of the
Preprocessing
object
- forward(image, return_original=False)¶
Preprocess the image.
- Parameters
image – np.ndarray of type
uint8
orstr
RGB image Ifstr
, it will be concerned as image path.return_original –
bool
. IfTrue
, will return tuple of(preprocessed_image, original_image)
nnio.DetectionBox¶
- class nnio.DetectionBox(x_min, y_min, x_max, y_max, label=None, score=1.0)¶
- __init__(x_min, y_min, x_max, y_max, label=None, score=1.0)¶
- Parameters
x_min –
float
in range[0, 1]
. Relative x (width) coordinate of top-left corner.y_min –
float
in range[0, 1]
. Relative y (height) coordinate of top-left corner.x_max –
float
in range[0, 1]
. Relative x (width) coordinate of bottom-right corner.y_max –
float
in range[0, 1]
. Relative y (height) coordinate of bottom-right corner.label –
str
orNone
. Class label of the detected object.score –
float
. Detection score
- __str__()¶
Return str(self).
- __weakref__¶
list of weak references to the object (if defined)
- draw(image, color=(255, 0, 0), stroke_width=2, text_color=(255, 0, 0), text_width=2)¶
Draws the detection box on an image
- Parameters
image – numpy array.
color – RGB color of the frame.
stroke_width – boldness of the frame.
text_color – RGB color of the text.
text_width – boldness of the text.
- Returns
Image with the box drawn on it.