2 #include "caffe2/core/operator.h" 3 #include "caffe2/utils/math.h" 9 class NormalizePlanarYUVOp :
public Operator<CPUContext> {
11 USE_OPERATOR_FUNCTIONS(CPUContext);
12 using Operator<CPUContext>::Operator;
15 const auto& X = Input(0);
16 const auto& M = Input(1);
17 const auto& S = Input(2);
21 CAFFE_ENFORCE(X.dims().size() == 4);
23 const auto N = X.dim32(0);
25 const auto H = X.dim(2);
26 const auto W = X.dim(3);
27 CAFFE_ENFORCE(C == M.dim(1));
28 CAFFE_ENFORCE(C == S.dim(1));
29 const auto* Xdata = X.data<
float>();
30 auto* Zdata = Z->mutable_data<
float>();
33 for (
auto n = 0; n < N; n++) {
34 int batch_offset = n * C * offset;
35 for (
auto c = 0; c < C; c++) {
36 ConstEigenVectorMap<float> channel_s(
37 &Xdata[batch_offset + (c * offset)], offset);
38 EigenVectorMap<float> channel_d(
39 &Zdata[batch_offset + (c * offset)], offset);
40 channel_d = channel_s.array() - M.data<
float>()[c];
41 channel_d = channel_d.array() / S.data<
float>()[c];
48 REGISTER_CPU_OPERATOR(NormalizePlanarYUV, NormalizePlanarYUVOp);
49 OPERATOR_SCHEMA(NormalizePlanarYUV)
52 .AllowInplace({{0, 0}});
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...