maix.nn
maix.nn module
You can use
maix.nnto access this module with MaixPy
This module is generated from MaixCDK
Module
| module | brief |
|---|---|
| F | maix.nn.F module |
Enum
Variable
Function
Class
YOLOv5
| item | doc |
|---|---|
| brief | YOLOv5 class |
C++ defination code:
class YOLOv5
__init__
| item | doc |
|---|---|
| type | func |
| brief | Constructor of YOLOv5 class |
| param | model: model path, default empty, you can load model later by load function. |
| throw | If model arg is not empty and load failed, will throw err::Exception. |
| static | False |
C++ defination code:
YOLOv5(const string &model = "")
load
| item | doc |
|---|---|
| type | func |
| brief | Load model from file |
| param | model: Model path want to load |
| return | err::Err |
| static | False |
C++ defination code:
err::Err load(const string &model)
detect
| item | doc |
|---|---|
| type | func |
| brief | Detect objects from image |
| param | img: Image want to detect, if image's size not match model input's, will auto resize with fit method. conf_th: Confidence threshold, default 0.5. iou_th: IoU threshold, default 0.45. fit: Resize method, default image.Fit.FIT_CONTAIN. |
| throw | If image format not match model input format, will throw err::Exception. |
| return | Object list. In C++, you should delete it after use. |
| static | False |
C++ defination code:
std::vector<nn::Object> *detect(image::Image &img, float conf_th = 0.5, float iou_th = 0.45, maix::image::Fit fit = maix::image::FIT_CONTAIN)
input_size
| item | doc |
|---|---|
| type | func |
| brief | Get model input size |
| return | model input size |
| static | False |
C++ defination code:
image::Size input_size()
input_width
| item | doc |
|---|---|
| type | func |
| brief | Get model input width |
| return | model input size of width |
| static | False |
C++ defination code:
int input_width()
input_height
| item | doc |
|---|---|
| type | func |
| brief | Get model input height |
| return | model input size of height |
| static | False |
C++ defination code:
int input_height()
input_format
| item | doc |
|---|---|
| type | func |
| brief | Get input image format |
| return | input image format, image::Format type. |
| static | False |
C++ defination code:
image::Format input_format()
labels
| item | doc |
|---|---|
| type | var |
| brief | Labels list |
| static | False |
| readonly | False |
C++ defination code:
std::vector<string> labels
label_path
| item | doc |
|---|---|
| type | var |
| brief | Label file path |
| static | False |
| readonly | False |
C++ defination code:
std::string label_path
mean
| item | doc |
|---|---|
| type | var |
| brief | Get mean value, list type |
| static | False |
| readonly | False |
C++ defination code:
std::vector<float> mean
scale
| item | doc |
|---|---|
| type | var |
| brief | Get scale value, list type |
| static | False |
| readonly | False |
C++ defination code:
std::vector<float> scale
anchors
| item | doc |
|---|---|
| type | var |
| brief | Get anchors |
| static | False |
| readonly | False |
C++ defination code:
std::vector<float> anchors
Classifier
| item | doc |
|---|---|
| brief | Classifier |
C++ defination code:
class Classifier
__init__
| item | doc |
|---|---|
| type | func |
| brief | Construct a new Classifier object |
| param | model: MUD model path, if empty, will not load model, you can call load() later. if not empty, will load model and will raise err::Exception if load failed. |
| static | False |
C++ defination code:
Classifier(const string &model = "")
load
| item | doc |
|---|---|
| type | func |
| brief | Load model from file, model format is .mud,\nMUD file should contain [extra] section, have key-values:\n- model_type: classifier\n- input_type: rgb or bgr\n- mean: 123.675, 116.28, 103.53\n- scale: 0.017124753831663668, 0.01750700280112045, 0.017429193899782137\n- labels: imagenet_classes.txt |
| param | model: MUD model path |
| return | error code, if load failed, return error code |
| static | False |
C++ defination code:
err::Err load(const string &model)
classify
| item | doc |
|---|---|
| type | func |
| brief | Forward image to model, get result. Only for image input, use classify_raw for tensor input. |
| param | img: image, format should match model input_type, or will raise err.Exception softmax: if true, will do softmax to result, or will return raw value |
| throw | If error occurred, will raise err::Exception, you can find reason in log, mostly caused by args error or hardware error. |
| return | result, a list of (label, score). In C++, you need to delete it after use. |
| static | False |
C++ defination code:
std::vector<std::pair<int, float>> *classify(image::Image &img, bool softmax = true)
classify_raw
| item | doc |
|---|---|
| type | func |
| brief | Forward tensor data to model, get result |
| param | data: tensor data, format should match model input_type, or will raise err.Excetion softmax: if true, will do softmax to result, or will return raw value |
| throw | If error occurred, will raise err::Exception, you can find reason in log, mostly caused by args error or hardware error. |
| return | result, a list of (label, score). In C++, you need to delete it after use. |
| static | False |
C++ defination code:
std::vector<std::pair<int, float>> *classify_raw(tensor::Tensor &data, bool softmax = true)
input_size
| item | doc |
|---|---|
| type | func |
| brief | Get model input size, only for image input |
| return | model input size |
| static | False |
C++ defination code:
image::Size input_size()
input_width
| item | doc |
|---|---|
| type | func |
| brief | Get model input width, only for image input |
| return | model input size of width |
| static | False |
C++ defination code:
int input_width()
input_height
| item | doc |
|---|---|
| type | func |
| brief | Get model input height, only for image input |
| return | model input size of height |
| static | False |
C++ defination code:
int input_height()
input_format
| item | doc |
|---|---|
| type | func |
| brief | Get input image format, only for image input |
| return | input image format, image::Format type. |
| static | False |
C++ defination code:
image::Format input_format()
input_shape
| item | doc |
|---|---|
| type | func |
| brief | Get input shape, if have multiple input, only return first input shape |
| return | input shape, list type |
| static | False |
C++ defination code:
std::vector<int> input_shape()
labels
| item | doc |
|---|---|
| type | var |
| brief | Labels list |
| static | False |
| readonly | False |
C++ defination code:
std::vector<string> labels
label_path
| item | doc |
|---|---|
| type | var |
| brief | Label file path |
| static | False |
| readonly | False |
C++ defination code:
std::string label_path
mean
| item | doc |
|---|---|
| type | var |
| brief | Get mean value, list type |
| static | False |
| readonly | False |
C++ defination code:
std::vector<float> mean
scale
| item | doc |
|---|---|
| type | var |
| brief | Get scale value, list type |
| static | False |
| readonly | False |
C++ defination code:
std::vector<float> scale
MUD
| item | doc |
|---|---|
| brief | MUD(model universal describe file) class |
C++ defination code:
class MUD
__init__
| item | doc |
|---|---|
| type | func |
| brief | MUD constructor |
| param | model_path: direction [in], model file path, model format can be MUD(model universal describe file) file. If model_path set, will load model from file, load failed will raise err.Exception. If model_path not set, you can load model later by load function. |
| static | False |
C++ defination code:
MUD(const char *model_path = nullptr)
load
| item | doc |
|---|---|
| type | func |
| brief | Load model from file |
| param | model_path: direction [in], model file path, model format can be MUD(model universal describe file) file. |
| return | error code, if load success, return err::ERR_NONE |
| static | False |
C++ defination code:
err::Err load(const std::string &model_path)
type
| item | doc |
|---|---|
| type | var |
| brief | Model type, string type |
| static | False |
| readonly | False |
C++ defination code:
std::string type
items
| item | doc |
|---|---|
| type | var |
| brief | Model config items, different model type has different config items |
| static | False |
| readonly | False |
C++ defination code:
std::map<std::string, std::map<std::string, std::string>> items
LayerInfo
| item | doc |
|---|---|
| brief | NN model layer info |
C++ defination code:
class LayerInfo
__init__
| item | doc |
|---|---|
| type | func |
| brief | LayerInfo constructor |
| param | name: direction [in], layer name dtype: direction [in], layer data type shape: direction [in], layer shape |
| static | False |
C++ defination code:
LayerInfo(const std::string &name = "", tensor::DType dtype = tensor::DType::FLOAT32, std::vector<int> shape = std::vector<int>())
name
| item | doc |
|---|---|
| type | var |
| brief | Layer name |
| static | False |
| readonly | False |
C++ defination code:
std::string name
dtype
| item | doc |
|---|---|
| type | var |
| brief | Layer data type |
| attention | If model is quantized, this is the real quantized data type like int8 float16, in most scene, inputs and outputs we actually use float32 in API like forward. |
| static | False |
| readonly | False |
C++ defination code:
tensor::DType dtype
shape
| item | doc |
|---|---|
| type | var |
| brief | Layer shape |
| static | False |
| readonly | False |
C++ defination code:
std::vector<int> shape
to_str
| item | doc |
|---|---|
| type | func |
| brief | To string |
| static | False |
C++ defination code:
std::string to_str()
__str__
| item | doc |
|---|---|
| type | func |
| brief | To string |
| static | False |
C++ defination code:
std::string __str__()
NN
| item | doc |
|---|---|
| brief | Neural network class |
C++ defination code:
class NN
__init__
| item | doc |
|---|---|
| type | func |
| brief | Neural network constructor |
| param | model: direction [in], model file path, model format can be MUD(model universal describe file) file. If model_path set, will load model from file, load failed will raise err.Exception. If model_path not set, you can load model later by load function. |
| static | False |
C++ defination code:
NN(const std::string &model = "")
load
| item | doc |
|---|---|
| type | func |
| brief | Load model from file |
| param | model: direction [in], model file path, model format can be MUD(model universal describe file) file. |
| return | error code, if load success, return err::ERR_NONE |
| static | False |
C++ defination code:
err::Err load(const std::string &model)
loaded
| item | doc |
|---|---|
| type | func |
| brief | Is model loaded |
| return | true if model loaded, else false |
| static | False |
C++ defination code:
bool loaded()
inputs_info
| item | doc |
|---|---|
| type | func |
| brief | Get model input layer info |
| return | input layer info |
| static | False |
C++ defination code:
std::vector<nn::LayerInfo> inputs_info()
outputs_info
| item | doc |
|---|---|
| type | func |
| brief | Get model output layer info |
| return | output layer info |
| static | False |
C++ defination code:
std::vector<nn::LayerInfo> outputs_info()
extra_info
| item | doc |
|---|---|
| type | func |
| brief | Get model extra info define in MUD file |
| return | extra info, dict type, key-value object, attention: key and value are all string type. |
| static | False |
C++ defination code:
std::map<std::string, std::string> extra_info()
forward
| item | doc |
|---|---|
| type | func |
| brief | forward run model, get output of model,\nthis is specially for MaixPy, not efficient, but easy to use in MaixPy |
| param | input: direction [in], input tensor |
| return | output tensor. In C++, you should manually delete tensors in return value and return value. |
| static | False |
C++ defination code:
tensor::Tensors *forward(tensor::Tensors &inputs)
forward_image
| item | doc |
|---|---|
| type | func |
| brief | forward model, param is image |
| param | img: input image mean: mean value, a list type, e.g. [0.485, 0.456, 0.406], default is empty list means not normalize. scale: scale value, a list type, e.g. [1/0.229, 1/0.224, 1/0.225], default is empty list means not normalize. fit: fit mode, if the image size of input not equal to model's input, it will auto resize use this fit method, default is image.Fit.FIT_FILL for easy coordinate calculation, but for more accurate result, use image.Fit.FIT_CONTAIN is better. copy_result: If set true, will copy result to a new variable; else will use a internal memory, you can only use it until to the next forward. Default true to avoid problems, you can set it to false manually to make speed faster. |
| return | output tensor. In C++, you should manually delete tensors in return value and return value. |
| static | False |
C++ defination code:
tensor::Tensors *forward_image(image::Image &img, std::vector<float> mean = std::vector<float>(), std::vector<float> scale = std::vector<float>(), image::Fit fit = image::Fit::FIT_FILL, bool copy_result = true)
Object
| item | doc |
|---|---|
| brief | Object for detect result |
C++ defination code:
class Object
__init__
| item | doc |
|---|---|
| type | func |
| brief | Constructor of Object for detect result |
| param | x: left top x y: left top y w: width h: height class_id: class id score: score |
| static | False |
C++ defination code:
Object(int x = 0, int y = 0, int w = 0, int h = 0, int class_id = 0, float score = 0)
__str__
| item | doc |
|---|---|
| type | func |
| brief | Object info to string |
| return | Object info string |
| static | False |
C++ defination code:
std::string to_str()
x
| item | doc |
|---|---|
| type | var |
| brief | Object left top coordinate x |
| static | False |
| readonly | False |
C++ defination code:
int x
y
| item | doc |
|---|---|
| type | var |
| brief | Object left top coordinate y |
| static | False |
| readonly | False |
C++ defination code:
int y
w
| item | doc |
|---|---|
| type | var |
| brief | Object width |
| static | False |
| readonly | False |
C++ defination code:
int w
h
| item | doc |
|---|---|
| type | var |
| brief | Object height |
| static | False |
| readonly | False |
C++ defination code:
int h
class_id
| item | doc |
|---|---|
| type | var |
| brief | Object class id |
| static | False |
| readonly | False |
C++ defination code:
int class_id
score
| item | doc |
|---|---|
| type | var |
| brief | Object score |
| static | False |
| readonly | False |
C++ defination code:
float score