vitis::ai::YOLOv2
Base class for detecting objects in the input image(cv::Mat). Input is an image(cv::Mat). Output is the position of the objects in the input image. Sample code:
auto img = cv::imread("sample_yolov2.jpg");
auto model = vitis::ai::YOLOv2::create("yolov2_voc");
auto result = model->run(img);
for (const auto &bbox : result.bboxes) {
int label = bbox.label;
float xmin = bbox.x * img.cols + 1;
float ymin = bbox.y * img.rows + 1;
float xmax = xmin + bbox.width * img.cols;
float ymax = ymin + bbox.height * img.rows;
if (xmax > img.cols)
xmax = img.cols;
if (ymax > img.rows)
ymax = img.rows;
float confidence = bbox.score;
cout << "RESULT: " << label << "\t" << xmin << "\t" << ymin << "\t" << xmax
<< "\t" << ymax << "\t" << confidence << "\n";
rectangle(img, Point(xmin, ymin), Point(xmax, ymax), Scalar(0, 255, 0), 1,
1, 0);
}
Quick Function Reference
The following table lists all the functions defined in the vitis::ai::YOLOv2
class:
Type | Name | Arguments |
---|---|---|
std::unique_ptr< YOLOv2 > | create |
|
YOLOv2Result | run |
|
std::vector< YOLOv2Result > | run |
|
int | getInputWidth |
|
int | getInputHeight |
|
size_t | get_input_batch |
|
create
Factory function to get an instance of derived classes of class YOLOv2
.
Prototype
std::unique_ptr< YOLOv2
> create(const std::string &model_name, bool need_preprocess=true);
Parameters
The following table lists the create
function arguments.
Type | Name | Description |
---|---|---|
const std::string & | model_name | Model name |
bool | need_preprocess | Normalize with mean/scale or not, default value is true. |
Returns
An instance ofYOLOv2
class. run
Function to get running result of the YOLOv2
neuron network.
Prototype
YOLOv2Result
run(const cv::Mat &image)=0;
Parameters
The following table lists the run
function arguments.
Type | Name | Description |
---|---|---|
const cv::Mat & | image | Input data of input image (cv::Mat). |
Returns
A Struct ofYOLOv2Result
. run
Function to get running result of the YOLOv2
neuron network in batch mode.
Prototype
std::vector< YOLOv2Result
> run(const std::vector< cv::Mat > &images)=0;
Parameters
The following table lists the run
function arguments.
Type | Name | Description |
---|---|---|
const std::vector< cv::Mat > & | images | Input data of input images (std:vector<cv::Mat>). The size of input images equals batch size obtained by get_input_batch. |
Returns
The vector ofYOLOv2Result
. getInputWidth
Function to get InputWidth of the YOLOv2
network (input image columns).
Prototype
int getInputWidth() const =0;
Returns
InputWidth of theYOLOv2
network getInputHeight
Function to get InputHeight of the YOLOv2
network (input image rows).
Prototype
int getInputHeight() const =0;
Returns
InputHeight of theYOLOv2
network. get_input_batch
Function to get the number of images processed by the DPU at one time.
Note: Different DPU core the batch size may be different. This depends on the IP used.
Prototype
size_t get_input_batch() const =0;