Caffe2 - C++ API
A deep learning, cross platform ML framework
space_batch_op.cc
1 #include "caffe2/operators/space_batch_op.h"
2 
3 namespace caffe2 {
4 
5 REGISTER_CPU_OPERATOR(SpaceToBatch, SpaceToBatchOp<CPUContext>);
6 OPERATOR_SCHEMA(SpaceToBatch).NumInputs(1).NumOutputs(1).SetDoc(R"DOC(
7 
8 SpaceToBatch for 4-D tensors of type T.
9 
10 Zero-pads and then rearranges (permutes) blocks of spatial data into
11 batch. More specifically, this op outputs a copy of the input tensor
12 where values from the height and width dimensions are moved to the
13 batch dimension. After the zero-padding, both height and width of the
14 input must be divisible by the block size.
15 
16 )DOC");
17 
18 REGISTER_CPU_OPERATOR(BatchToSpace, BatchToSpaceOp<CPUContext>);
19 OPERATOR_SCHEMA(BatchToSpace).NumInputs(1).NumOutputs(1).SetDoc(R"DOC(
20 
21 BatchToSpace for 4-D tensors of type T.
22 
23 Rearranges (permutes) data from batch into blocks of spatial data,
24 followed by cropping. This is the reverse transformation of
25 SpaceToBatch. More specifically, this op outputs a copy of the input
26 tensor where values from the batch dimension are moved in spatial
27 blocks to the height and width dimensions, followed by cropping along
28 the height and width dimensions.
29 
30 )DOC");
31 
33  using GradientMakerBase::GradientMakerBase;
34  vector<OperatorDef> GetGradientDefs() override {
35  return SingleGradientDef(
36  "BatchToSpace", "", vector<string>{GO(0)}, vector<string>{GI(0)});
37  }
38 };
39 
41  using GradientMakerBase::GradientMakerBase;
42  vector<OperatorDef> GetGradientDefs() override {
43  return SingleGradientDef(
44  "SpaceToBatch", "", vector<string>{GO(0)}, vector<string>{GI(0)});
45  }
46 };
47 REGISTER_GRADIENT(SpaceToBatch, GetSpaceToBatchGradient);
48 REGISTER_GRADIENT(BatchToSpace, GetBatchToSpaceGradient);
49 }
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
static vector< OperatorDef > SingleGradientDef(const Args &...args)
a helper function to allow one to create one single operator def, which is usually the case for many ...