Utils¶
nnio.Preprocessing¶
- class nnio.Preprocessing(resize=None, dtype='uint8', divide_by_255=False, means=None, stds=None, scales=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
Preprocessingobjects. ReturnsTrueonly if all preprocessing parameters are the same.
- __init__(resize=None, dtype='uint8', divide_by_255=False, means=None, stds=None, scales=None, padding=False, channels_first=False, batch_dimension=False, bgr=False)¶
- Parameters
resize –
Noneortuple. (width, height) - the new size of imagedtype –
strornp.dtype. Data typedivide_by_255 –
bool. Divide input image by 255. This is applied beforemeans,stdsandscales.means –
floator iterable orNone. Substract these values from each channelstds – float` or iterable or
None. Divide each channel by these valuesscales –
floator iterable orNone. Multipy each channel by these valuespadding –
bool. IfTrue, images will be resized with the same aspect ratiochannels_first –
bool. IfTrue, image will be returned in[B]CHWformat. 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
Preprocessingobject
- forward(image, return_original=False)¶
Preprocess the image.
- Parameters
image – np.ndarray of type
uint8orstrRGB 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 –
floatin range[0, 1]. Relative x (width) coordinate of top-left corner.y_min –
floatin range[0, 1]. Relative y (height) coordinate of top-left corner.x_max –
floatin range[0, 1]. Relative x (width) coordinate of bottom-right corner.y_max –
floatin range[0, 1]. Relative y (height) coordinate of bottom-right corner.label –
strorNone. 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.