2021-12-07 10:57:55 +08:00
|
|
|
// Copyright (c) OpenMMLab. All rights reserved.
|
|
|
|
|
|
|
|
#include "core/registry.h"
|
2021-12-21 10:47:21 +08:00
|
|
|
#include "core/utils/device_utils.h"
|
2021-12-07 10:57:55 +08:00
|
|
|
#include "opencv_utils.h"
|
|
|
|
#include "preprocess/transform/normalize.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
namespace mmdeploy {
|
|
|
|
namespace cpu {
|
|
|
|
|
|
|
|
class NormalizeImpl : public ::mmdeploy::NormalizeImpl {
|
|
|
|
public:
|
|
|
|
NormalizeImpl(const Value& value) : ::mmdeploy::NormalizeImpl(value){};
|
|
|
|
~NormalizeImpl() = default;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Result<Tensor> NormalizeImage(const Tensor& tensor) override {
|
|
|
|
OUTCOME_TRY(auto src_tensor, MakeAvailableOnDevice(tensor, device_, stream_));
|
|
|
|
auto mat = Tensor2CVMat(src_tensor);
|
|
|
|
auto dst_mat = Normalize(mat, arg_.mean, arg_.std, arg_.to_rgb, true);
|
|
|
|
return CVMat2Tensor(dst_mat);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NormalizeImplCreator : public Creator<::mmdeploy::NormalizeImpl> {
|
|
|
|
public:
|
|
|
|
const char* GetName() const override { return "cpu"; }
|
|
|
|
int GetVersion() const override { return 1; }
|
|
|
|
std::unique_ptr<::mmdeploy::NormalizeImpl> Create(const Value& args) override {
|
|
|
|
return make_unique<NormalizeImpl>(args);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace cpu
|
|
|
|
} // namespace mmdeploy
|
|
|
|
|
|
|
|
using mmdeploy::NormalizeImpl;
|
|
|
|
using mmdeploy::cpu::NormalizeImplCreator;
|
|
|
|
REGISTER_MODULE(NormalizeImpl, NormalizeImplCreator);
|