Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/cpp/models/include/models/anomaly_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
*/

#pragma once
#include "models/image_model.h"
#include "models/base_model.h"

namespace ov {
class Model;
} // namespace ov
struct AnomalyResult;
struct ImageInputData;

class AnomalyModel : public ImageModel {
class AnomalyModel : public BaseModel {
public:
AnomalyModel(std::shared_ptr<ov::Model>& model, const ov::AnyMap& configuration);
AnomalyModel(std::shared_ptr<InferenceAdapter>& adapter, const ov::AnyMap& configuration = {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
#include <memory>
#include <string>

#include "adapters/inference_adapter.h"
#include "models/input_data.h"
#include "models/model_base.h"
#include "models/results.h"
#include "utils/args_helper.hpp"
#include "utils/image_utils.h"
#include "utils/ocv_common.hpp"

namespace ov {
class InferRequest;
Expand All @@ -20,22 +23,37 @@ struct InputData;
struct InternalModelData;

// ImageModel implements preprocess(), ImageModel's direct or indirect children are expected to implement prostprocess()
class ImageModel : public ModelBase {
class BaseModel {
public:
/// Constructor
/// @param modelFile name of model to load
/// @param useAutoResize - if true, image is resized by openvino
/// @param layout - model input layout
ImageModel(const std::string& modelFile,
const std::string& resize_type,
bool useAutoResize,
const std::string& layout = "");
BaseModel(const std::string& modelFile,
const std::string& resize_type,
bool useAutoResize,
const std::string& layout = "");

ImageModel(std::shared_ptr<ov::Model>& model, const ov::AnyMap& configuration);
ImageModel(std::shared_ptr<InferenceAdapter>& adapter, const ov::AnyMap& configuration = {});
using ModelBase::ModelBase;
BaseModel(std::shared_ptr<ov::Model>& model, const ov::AnyMap& configuration);
BaseModel(std::shared_ptr<InferenceAdapter>& adapter, const ov::AnyMap& configuration = {});

virtual std::shared_ptr<InternalModelData> preprocess(const InputData& inputData, InferenceInput& input);
virtual std::unique_ptr<ResultBase> postprocess(InferenceResult& infResult) = 0;

void load(ov::Core& core, const std::string& device, size_t num_infer_requests = 1);

std::shared_ptr<ov::Model> prepare();

virtual size_t getNumAsyncExecutors() const;
virtual bool isReady();
virtual void awaitAll();
virtual void awaitAny();
virtual void setCallback(
std::function<void(std::unique_ptr<ResultBase>, const ov::AnyMap& callback_args)> callback);

std::shared_ptr<ov::Model> getModel();
std::shared_ptr<InferenceAdapter> getInferenceAdapter();

std::shared_ptr<InternalModelData> preprocess(const InputData& inputData, InferenceInput& input) override;
static std::vector<std::string> loadLabels(const std::string& labelFilename);
std::shared_ptr<ov::Model> embedProcessing(std::shared_ptr<ov::Model>& model,
const std::string& inputName,
Expand All @@ -54,7 +72,7 @@ class ImageModel : public ModelBase {

protected:
RESIZE_MODE selectResizeMode(const std::string& resize_type);
void updateModelInfo() override;
virtual void updateModelInfo();
void init_from_config(const ov::AnyMap& top_priority, const ov::AnyMap& mid_priority);

std::string getLabelName(size_t labelID) {
Expand All @@ -73,4 +91,18 @@ class ImageModel : public ModelBase {
bool reverse_input_channels = false;
std::vector<float> scale_values;
std::vector<float> mean_values;

protected:
virtual void prepareInputsOutputs(std::shared_ptr<ov::Model>& model) = 0;

InputTransform inputTransform = InputTransform();

std::shared_ptr<ov::Model> model;
std::vector<std::string> inputNames;
std::vector<std::string> outputNames;
std::string modelFile;
std::shared_ptr<InferenceAdapter> inferenceAdapter;
std::map<std::string, ov::Layout> inputsLayouts;
ov::Layout getInputLayout(const ov::Output<ov::Node>& input);
std::function<void(std::unique_ptr<ResultBase>, const ov::AnyMap&)> lastCallback;
};
4 changes: 2 additions & 2 deletions src/cpp/models/include/models/classification_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <unordered_map>
#include <vector>

#include "models/image_model.h"
#include "models/base_model.h"

namespace ov {
class Model;
Expand Down Expand Up @@ -88,7 +88,7 @@ class ProbabilisticLabelsResolver : public GreedyLabelsResolver {
SimpleLabelsGraph label_tree;
};

class ClassificationModel : public ImageModel {
class ClassificationModel : public BaseModel {
public:
ClassificationModel(std::shared_ptr<ov::Model>& model, const ov::AnyMap& configuration);
ClassificationModel(std::shared_ptr<InferenceAdapter>& adapter, const ov::AnyMap& configuration = {});
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/models/include/models/detection_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

#include <string>

#include "models/image_model.h"
#include "models/base_model.h"

struct DetectionResult;
struct ImageInputData;
struct InferenceAdatper;

class DetectionModel : public ImageModel {
class DetectionModel : public BaseModel {
public:
DetectionModel(std::shared_ptr<ov::Model>& model, const ov::AnyMap& configuration);
DetectionModel(std::shared_ptr<InferenceAdapter>& adapter, const ov::AnyMap& configuration = {});
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/models/include/models/instance_segmentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <string>
#include <vector>

#include "models/image_model.h"
#include "models/base_model.h"

namespace ov {
class Model;
Expand All @@ -19,7 +19,7 @@ struct InstanceSegmentationResult;
struct ImageInputData;
struct SegmentedObject;

class MaskRCNNModel : public ImageModel {
class MaskRCNNModel : public BaseModel {
public:
MaskRCNNModel(std::shared_ptr<ov::Model>& model, const ov::AnyMap& configuration);
MaskRCNNModel(std::shared_ptr<InferenceAdapter>& adapter, const ov::AnyMap& configuration = {});
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/models/include/models/keypoint_detection.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <string>
#include <vector>

#include "models/image_model.h"
#include "models/base_model.h"

namespace ov {
class Model;
Expand All @@ -18,7 +18,7 @@ struct ResultBase;
struct KeypointDetectionResult;
struct ImageInputData;

class KeypointDetectionModel : public ImageModel {
class KeypointDetectionModel : public BaseModel {
public:
KeypointDetectionModel(std::shared_ptr<ov::Model>& model, const ov::AnyMap& configuration);
KeypointDetectionModel(std::shared_ptr<InferenceAdapter>& adapter, const ov::AnyMap& configuration = {});
Expand Down
73 changes: 0 additions & 73 deletions src/cpp/models/include/models/model_base.h

This file was deleted.

4 changes: 2 additions & 2 deletions src/cpp/models/include/models/segmentation_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <string>
#include <vector>

#include "models/image_model.h"
#include "models/base_model.h"

namespace ov {
class Model;
Expand All @@ -20,7 +20,7 @@ struct ImageResultWithSoftPrediction;
struct ImageInputData;
struct Contour;

class SegmentationModel : public ImageModel {
class SegmentationModel : public BaseModel {
public:
SegmentationModel(std::shared_ptr<ov::Model>& model, const ov::AnyMap& configuration);
SegmentationModel(std::shared_ptr<InferenceAdapter>& adapter, const ov::AnyMap& configuration = {});
Expand Down
14 changes: 7 additions & 7 deletions src/cpp/models/src/anomaly_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <openvino/core/model.hpp>
#include <ostream>

#include "models/image_model.h"
#include "models/base_model.h"
#include "models/input_data.h"
#include "models/internal_model_data.h"
#include "models/results.h"
Expand All @@ -29,23 +29,23 @@ void AnomalyModel::init_from_config(const ov::AnyMap& top_priority, const ov::An
}

AnomalyModel::AnomalyModel(std::shared_ptr<ov::Model>& model, const ov::AnyMap& configuration)
: ImageModel(model, configuration) {
: BaseModel(model, configuration) {
init_from_config(configuration, model->get_rt_info<ov::AnyMap>("model_info"));
}

AnomalyModel::AnomalyModel(std::shared_ptr<InferenceAdapter>& adapter, const ov::AnyMap& configuration)
: ImageModel(adapter, configuration) {
: BaseModel(adapter, configuration) {
init_from_config(configuration, adapter->getModelConfig());
}

std::unique_ptr<AnomalyResult> AnomalyModel::infer(const ImageInputData& inputData) {
auto result = ImageModel::inferImage(inputData);
auto result = BaseModel::inferImage(inputData);

return std::unique_ptr<AnomalyResult>(static_cast<AnomalyResult*>(result.release()));
}

std::vector<std::unique_ptr<AnomalyResult>> AnomalyModel::inferBatch(const std::vector<ImageInputData>& inputImgs) {
auto results = ImageModel::inferBatchImage(inputImgs);
auto results = BaseModel::inferBatchImage(inputImgs);
std::vector<std::unique_ptr<AnomalyResult>> anoResults;
anoResults.reserve(results.size());
for (auto& result : results) {
Expand Down Expand Up @@ -177,7 +177,7 @@ void AnomalyModel::prepareInputsOutputs(std::shared_ptr<ov::Model>& model) {
const ov::Layout& inputLayout = getInputLayout(input);

if (!embedded_processing) {
model = ImageModel::embedProcessing(
model = BaseModel::embedProcessing(
model,
inputNames[0],
inputLayout,
Expand All @@ -194,7 +194,7 @@ void AnomalyModel::prepareInputsOutputs(std::shared_ptr<ov::Model>& model) {
}

void AnomalyModel::updateModelInfo() {
ImageModel::updateModelInfo();
BaseModel::updateModelInfo();

model->set_rt_info(AnomalyModel::ModelType, "model_info", "model_type");
model->set_rt_info(task, "model_info", "task");
Expand Down
Loading