2 #include "caffe2/core/operator.h" 3 #include "caffe2/utils/eigen_utils.h" 4 #include "caffe2/utils/math.h" 10 class NormalizePlanarYUVOp :
public Operator<CPUContext> {
12 USE_OPERATOR_FUNCTIONS(CPUContext);
13 using Operator<CPUContext>::Operator;
15 bool RunOnDevice()
override {
16 const auto& X = Input(0);
17 const auto&
M = Input(1);
18 const auto& S = Input(2);
20 auto* Z = Output(0, X.sizes(), at::dtype<float>());
22 CAFFE_ENFORCE(X.sizes().size() == 4);
24 const auto N = X.dim32(0);
26 const auto H = X.size(2);
27 const auto W = X.size(3);
28 CAFFE_ENFORCE(
C ==
M.size(1));
29 CAFFE_ENFORCE(
C == S.size(1));
30 const auto* Xdata = X.data<
float>();
31 auto* Zdata = Z->template mutable_data<float>();
34 for (
auto n = 0; n < N; n++) {
35 int batch_offset = n *
C * offset;
36 for (
auto c = 0; c <
C; c++) {
37 ConstEigenVectorMap<float> channel_s(
38 &Xdata[batch_offset + (c * offset)], offset);
39 EigenVectorMap<float> channel_d(
40 &Zdata[batch_offset + (c * offset)], offset);
41 channel_d = channel_s.array() -
M.data<
float>()[c];
42 channel_d = channel_d.array() / S.data<
float>()[c];
49 REGISTER_CPU_OPERATOR(NormalizePlanarYUV, NormalizePlanarYUVOp);
50 OPERATOR_SCHEMA(NormalizePlanarYUV)
53 .AllowInplace({{0, 0}});
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...