1 #include "caffe2/operators/summarize_op.h" 6 bool SummarizeOp<float, CPUContext>::RunOnDevice() {
8 const auto N = X.size();
9 CAFFE_ENFORCE_GT(N, 0);
11 const float* Xdata = X.data<
float>();
15 for (
auto i = 0; i < N; ++i) {
16 mean +=
static_cast<double>(Xdata[i]) / N;
17 max = std::max(max, Xdata[i]);
18 min = std::min(min, Xdata[i]);
22 double standard_deviation = 0;
23 for (
auto i = 0; i < N; ++i) {
24 double diff = Xdata[i] - mean;
25 standard_deviation += diff * diff;
28 standard_deviation = N == 1 ? 0 : std::sqrt(standard_deviation / (N - 1));
30 (*log_file_) << min <<
" " << max <<
" " << mean <<
" " 31 << standard_deviation << std::endl;
36 float* Ydata = Y->mutable_data<
float>();
39 Ydata[MEAN_IDX] =
static_cast<float>(mean);
40 Ydata[STD_IDX] =
static_cast<float>(standard_deviation);
45 REGISTER_CPU_OPERATOR(Summarize, SummarizeOp<float, CPUContext>);
49 OPERATOR_SCHEMA(Summarize)
53 Summarize computes four statistics of the input tensor (Tensor<float>)- min, 54 max, mean and standard deviation. The output will be written to a 1-D tensor of 55 size 4 if an output tensor is provided. Else, if the argument 'to_file' is 56 greater than 0, the values are written to a log file in the root folder. 60 "(int, default 0) flag to indicate if the summarized " 61 "statistics have to be written to a log file.")
62 .Input(0,
"data",
"The input data as Tensor<float>.")
66 "1-D tensor (Tensor<float>) of size 4 containing min, " 67 "max, mean and standard deviation");
69 SHOULD_NOT_DO_GRADIENT(Summarize);
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...