Skip to content

Commit

Permalink
Remove unused headers, hide BBox (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wovchena authored Jan 16, 2024
1 parent cec3def commit 5e64d0b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 32 deletions.
3 changes: 0 additions & 3 deletions model_api/cpp/models/include/models/detection_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@
*/

#pragma once
#include <stddef.h>

#include <string>
#include <vector>

#include "models/image_model.h"

struct DetectionResult;
Expand Down
16 changes: 0 additions & 16 deletions model_api/cpp/models/include/models/detection_model_centernet.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#pragma once
#include <memory>
#include <string>
#include <vector>

#include "models/detection_model.h"

Expand All @@ -32,21 +31,6 @@ struct ResultBase;

class ModelCenterNet : public DetectionModel {
public:
struct BBox {
float left;
float top;
float right;
float bottom;

float getWidth() const {
return (right - left) + 1.0f;
}
float getHeight() const {
return (bottom - top) + 1.0f;
}
};
static const int INIT_VECTOR_SIZE = 200;

ModelCenterNet(std::shared_ptr<ov::Model>& model, const ov::AnyMap& configuration);
ModelCenterNet(std::shared_ptr<InferenceAdapter>& adapter);

Expand Down
1 change: 1 addition & 0 deletions model_api/cpp/models/include/models/image_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class InferRequest;
struct InputData;
struct InternalModelData;

// ImageModel implements preprocess(), ImageModel's direct or indirect children are expected to implement prostprocess()
class ImageModel : public ModelBase {
public:
/// Constructor
Expand Down
1 change: 1 addition & 0 deletions model_api/cpp/models/include/models/model_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ModelBase {

std::shared_ptr<ov::Model> prepare();
void load(ov::Core& core, const std::string& device);
// Modifying ov::Model doesn't affect the model wrapper
std::shared_ptr<ov::Model> getModel();
std::shared_ptr<InferenceAdapter> getInferenceAdapter();

Expand Down
35 changes: 22 additions & 13 deletions model_api/cpp/models/src/detection_model_centernet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@

#include "models/detection_model_centernet.h"

#include <stddef.h>

#include <algorithm>
#include <cmath>
#include <map>
#include <stdexcept>
#include <utility>

#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <openvino/openvino.hpp>
Expand Down Expand Up @@ -156,9 +148,11 @@ std::shared_ptr<InternalModelData> ModelCenterNet::preprocess(const InputData& i
return std::make_shared<InternalImageModelData>(img.cols, img.rows);
}

namespace {
std::vector<std::pair<size_t, float>> nms(float* scoresPtr, const ov::Shape& shape, float threshold, int kernel = 3) {
std::vector<std::pair<size_t, float>> scores;
scores.reserve(ModelCenterNet::INIT_VECTOR_SIZE);
constexpr size_t INIT_VECTOR_SIZE = 200;
scores.reserve(INIT_VECTOR_SIZE);
auto chSize = shape[2] * shape[3];

for (size_t i = 0; i < shape[1] * shape[2] * shape[3]; ++i) {
Expand Down Expand Up @@ -237,11 +231,25 @@ std::vector<std::pair<float, float>> filterWH(const ov::Tensor& whTensor,
return wh;
}

std::vector<ModelCenterNet::BBox> calcBoxes(const std::vector<std::pair<size_t, float>>& scores,
struct BBox {
float left;
float top;
float right;
float bottom;

float getWidth() const {
return (right - left) + 1.0f;
}
float getHeight() const {
return (bottom - top) + 1.0f;
}
};

std::vector<BBox> calcBoxes(const std::vector<std::pair<size_t, float>>& scores,
const std::vector<std::pair<float, float>>& reg,
const std::vector<std::pair<float, float>>& wh,
const ov::Shape& shape) {
std::vector<ModelCenterNet::BBox> boxes(scores.size());
std::vector<BBox> boxes(scores.size());

for (size_t i = 0; i < boxes.size(); ++i) {
size_t chIdx = scores[i].first % (shape[2] * shape[3]);
Expand All @@ -257,15 +265,15 @@ std::vector<ModelCenterNet::BBox> calcBoxes(const std::vector<std::pair<size_t,
return boxes;
}

void transform(std::vector<ModelCenterNet::BBox>& boxes,
void transform(std::vector<BBox>& boxes,
const ov::Shape& shape,
int scale,
float centerX,
float centerY) {
cv::Mat1f trans = getAffineTransform(centerX, centerY, scale, 0, shape[2], shape[3], true);

for (auto& b : boxes) {
ModelCenterNet::BBox newbb;
BBox newbb;

newbb.left = trans.at<float>(0, 0) * b.left + trans.at<float>(0, 1) * b.top + trans.at<float>(0, 2);
newbb.top = trans.at<float>(1, 0) * b.left + trans.at<float>(1, 1) * b.top + trans.at<float>(1, 2);
Expand All @@ -275,6 +283,7 @@ void transform(std::vector<ModelCenterNet::BBox>& boxes,
b = newbb;
}
}
}

std::unique_ptr<ResultBase> ModelCenterNet::postprocess(InferenceResult& infResult) {
// --------------------------- Filter data and get valid indices ---------------------------------
Expand Down

0 comments on commit 5e64d0b

Please sign in to comment.