{
LOGI("ENTER");
- _preprocess.run<T>(mv_src, metaInfo, inputVector);
+ PreprocessConfig config = { false,
+ metaInfo->colorSpace,
+ metaInfo->dataType,
+ metaInfo->getChannel(),
+ metaInfo->getWidth(),
+ metaInfo->getHeight() };
+
+ auto normalization = static_pointer_cast<DecodingNormal>(metaInfo->decodingTypeMap.at(DecodingType::NORMAL));
+ if (normalization) {
+ config.normalize = normalization->use;
+ config.mean = normalization->mean;
+ config.std = normalization->std;
+ }
+
+ auto quantization =
+ static_pointer_cast<DecodingQuantization>(metaInfo->decodingTypeMap.at(DecodingType::QUANTIZATION));
+ if (quantization) {
+ config.quantize = quantization->use;
+ config.scale = quantization->scale;
+ config.zeropoint = quantization->zeropoint;
+ }
+
+ _preprocess.setConfig(config);
+ _preprocess.run<T>(mv_src, inputVector);
LOGI("LEAVE");
}
{
LOGI("ENTER");
- _preprocess.run<T>(mv_src, metaInfo, inputVector);
+ PreprocessConfig config = { false,
+ metaInfo->colorSpace,
+ metaInfo->dataType,
+ metaInfo->getChannel(),
+ metaInfo->getWidth(),
+ metaInfo->getHeight() };
+
+ auto normalization = static_pointer_cast<DecodingNormal>(metaInfo->decodingTypeMap.at(DecodingType::NORMAL));
+ if (normalization) {
+ config.normalize = normalization->use;
+ config.mean = normalization->mean;
+ config.std = normalization->std;
+ }
+
+ auto quantization =
+ static_pointer_cast<DecodingQuantization>(metaInfo->decodingTypeMap.at(DecodingType::QUANTIZATION));
+ if (quantization) {
+ config.quantize = quantization->use;
+ config.scale = quantization->scale;
+ config.zeropoint = quantization->zeropoint;
+ }
+
+ _preprocess.setConfig(config);
+ _preprocess.run<T>(mv_src, inputVector);
LOGI("LEAVE");
}
{
LOGI("ENTER");
- _preprocess.run<T>(mv_src, metaInfo, inputVector);
+ PreprocessConfig config = { false,
+ metaInfo->colorSpace,
+ metaInfo->dataType,
+ metaInfo->getChannel(),
+ metaInfo->getWidth(),
+ metaInfo->getHeight() };
+
+ auto normalization = static_pointer_cast<DecodingNormal>(metaInfo->decodingTypeMap.at(DecodingType::NORMAL));
+ if (normalization) {
+ config.normalize = normalization->use;
+ config.mean = normalization->mean;
+ config.std = normalization->std;
+ }
+
+ auto quantization =
+ static_pointer_cast<DecodingQuantization>(metaInfo->decodingTypeMap.at(DecodingType::QUANTIZATION));
+ if (quantization) {
+ config.quantize = quantization->use;
+ config.scale = quantization->scale;
+ config.zeropoint = quantization->zeropoint;
+ }
+
+ _preprocess.setConfig(config);
+ _preprocess.run<T>(mv_src, inputVector);
LOGI("LEAVE");
}
#include <memory>
#include <vector>
+#include <inference_engine_type.h>
+#include <mv_inference_type.h>
+
#include "mv_private.h"
#include "mv_common.h"
-#include "TensorBuffer.h"
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
-#include "MetaParser.h"
-#include "types.h"
-
/**
* @file Preprocess.h
* @brief This file contains the Preprocess class definition which
{
namespace machine_learning
{
+struct PreprocessConfig {
+ bool skip_csc {}; /**< It indicates whether color space conversion operation should be skipped or not. */
+ mv_colorspace_e output_format {}; /**< The pixel format of output tensor to be converted. */
+ mv_inference_data_type_e output_data_type {}; /**< The data type of output tensor to be converted. */
+ int output_channel {}; /** The channel size of output tensor te be converted. */
+ int output_width {}; /** The width size of output tensor to be converted. */
+ int output_height {}; /** The height size of output tensor to be converted. */
+ bool normalize {}; /**< It indicates whether normalization to input data should be performed or not. */
+ std::vector<double> mean;
+ std::vector<double> std;
+ bool quantize {}; /**< It indicates whether quantization to input data should be performed or not. */
+ std::vector<double> scale;
+ std::vector<double> zeropoint;
+};
+
class Preprocess
{
public:
{}
~Preprocess() = default;
- //void run(std::vector<mv_source_h> &mv_srcs, MetaMap &tensorMetaInfo, IETensorBuffer &tensorBufferMap);
- template<typename T> void run(mv_source_h &mv_src, std::shared_ptr<MetaInfo> metaInfo, std::vector<T> &inputVector);
+ void setConfig(const PreprocessConfig &config);
+ template<typename T> void run(mv_source_h &mv_src, std::vector<T> &inputVector);
std::vector<unsigned int> &getImageWidth()
{
private:
std::vector<unsigned int> _vImageWidth;
std::vector<unsigned int> _vImageHeight;
+ PreprocessConfig _config;
int convertToCv(int given_type, int ch);
void colorConvert(cv::Mat &source, cv::Mat &dest, int sType, int dType);
};
using namespace std;
-using namespace mediavision::inference;
using namespace mediavision::machine_learning::exception;
namespace mediavision
}
}
-template<typename T> void Preprocess::run(mv_source_h &mv_src, shared_ptr<MetaInfo> metaInfo, vector<T> &inputVector)
+void Preprocess::setConfig(const PreprocessConfig &config)
+{
+ _config = config;
+}
+
+template<typename T> void Preprocess::run(mv_source_h &mv_src, vector<T> &inputVector)
{
LOGI("ENTER");
_vImageHeight.clear();
convertToCvSource(mv_srcs, oriCvSources);
- inputVector.resize(metaInfo->getHeight() * metaInfo->getWidth() * metaInfo->getChannel());
+ inputVector.resize(_config.output_height * _config.output_width * _config.output_channel);
- mv_colorspace_e colorspace = MEDIA_VISION_COLORSPACE_INVALID;
- int ret = mv_source_get_colorspace(mv_srcs[0], &colorspace);
- if (ret != MEDIA_VISION_ERROR_NONE)
- throw InvalidOperation("Fail to get color space.");
-
- int data_type = convertToCv(metaInfo->dataType, metaInfo->getChannel());
+ int data_type = convertToCv(_config.output_data_type, _config.output_channel);
// dest is a wrapper of the buffer.
- cv::Mat dest(cv::Size(metaInfo->getWidth(), metaInfo->getHeight()), data_type, inputVector.data());
+ cv::Mat dest(cv::Size(_config.output_width, _config.output_height), data_type, inputVector.data());
cv::Mat cvSource, cvDest;
// cvSource has new allocation with dest.size()
cv::resize(oriCvSources[0], cvSource, dest.size());
- // cvDest has new allocation if it's colorSpace is not RGB888
- // cvDest share the data with cvSource it's colorSpace is RGB888
- colorConvert(cvSource, cvDest, colorspace, metaInfo->colorSpace);
-
- cvDest.convertTo(dest, dest.type());
-
- try {
- auto normalization = static_pointer_cast<DecodingNormal>(metaInfo->decodingTypeMap.at(DecodingType::NORMAL));
-
- if (normalization && normalization->use)
- normalize(dest, dest, normalization->mean, normalization->std);
- } catch (const std::exception &e) {
- LOGI("No normalization node.");
+ if (_config.skip_csc) {
+ cvSource.convertTo(dest, dest.type());
+ } else {
+ mv_colorspace_e colorspace = MEDIA_VISION_COLORSPACE_INVALID;
+ int ret = mv_source_get_colorspace(mv_srcs[0], &colorspace);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw InvalidOperation("Fail to get color space.");
+
+ // cvDest is allocated if colorspace is not RGB888, and
+ // cvDest shares the data with cvSource if the colorspace is RGB888.
+ colorConvert(cvSource, cvDest, colorspace, _config.output_format);
+ cvDest.convertTo(dest, dest.type());
}
- try {
- auto quantization =
- static_pointer_cast<DecodingQuantization>(metaInfo->decodingTypeMap.at(DecodingType::QUANTIZATION));
+ if (_config.normalize)
+ normalize(dest, dest, _config.mean, _config.std);
- if (quantization && quantization->use)
- quantize(dest, dest, quantization->scale, quantization->zeropoint);
- } catch (const std::exception &e) {
- LOGI("No quantization node.");
- }
+ if (_config.quantize)
+ quantize(dest, dest, _config.scale, _config.zeropoint);
LOGI("LEAVE");
}
-template void Preprocess::run<float>(mv_source_h &mv_src, shared_ptr<MetaInfo> metaInfo, vector<float> &inputVector);
-template void Preprocess::run<unsigned char>(mv_source_h &mv_src, shared_ptr<MetaInfo> metaInfo,
- vector<unsigned char> &inputVector);
+template void Preprocess::run<float>(mv_source_h &mv_src, vector<float> &inputVector);
+template void Preprocess::run<unsigned char>(mv_source_h &mv_src, vector<unsigned char> &inputVector);
} /* machine_learning */
} /* mediavision */
{
LOGI("ENTER");
- _preprocess.run<T>(mv_src, metaInfo, inputVector);
+ PreprocessConfig config = { false,
+ metaInfo->colorSpace,
+ metaInfo->dataType,
+ metaInfo->getChannel(),
+ metaInfo->getWidth(),
+ metaInfo->getHeight() };
+
+ auto normalization = static_pointer_cast<DecodingNormal>(metaInfo->decodingTypeMap.at(DecodingType::NORMAL));
+ if (normalization) {
+ config.normalize = normalization->use;
+ config.mean = normalization->mean;
+ config.std = normalization->std;
+ }
+
+ auto quantization =
+ static_pointer_cast<DecodingQuantization>(metaInfo->decodingTypeMap.at(DecodingType::QUANTIZATION));
+ if (quantization) {
+ config.quantize = quantization->use;
+ config.scale = quantization->scale;
+ config.zeropoint = quantization->zeropoint;
+ }
+
+ _preprocess.setConfig(config);
+ _preprocess.run<T>(mv_src, inputVector);
LOGI("LEAVE");
}
{
LOGI("ENTER");
- _preprocess.run<T>(mv_src, metaInfo, inputVector);
+ PreprocessConfig config = { false,
+ metaInfo->colorSpace,
+ metaInfo->dataType,
+ metaInfo->getChannel(),
+ metaInfo->getWidth(),
+ metaInfo->getHeight() };
+
+ auto normalization = static_pointer_cast<DecodingNormal>(metaInfo->decodingTypeMap.at(DecodingType::NORMAL));
+ if (normalization) {
+ config.normalize = normalization->use;
+ config.mean = normalization->mean;
+ config.std = normalization->std;
+ }
+
+ auto quantization =
+ static_pointer_cast<DecodingQuantization>(metaInfo->decodingTypeMap.at(DecodingType::QUANTIZATION));
+ if (quantization) {
+ config.quantize = quantization->use;
+ config.scale = quantization->scale;
+ config.zeropoint = quantization->zeropoint;
+ }
+
+ _preprocess.setConfig(config);
+ _preprocess.run<T>(mv_src, inputVector);
LOGI("LEAVE");
}