1 #include "caffe2/operators/space_batch_op.h" 5 REGISTER_CPU_OPERATOR(SpaceToBatch, SpaceToBatchOp<CPUContext>);
6 OPERATOR_SCHEMA(SpaceToBatch).NumInputs(1).NumOutputs(1).SetDoc(R
"DOC( 7 Zero-pads and then rearranges (permutes) blocks of spatial data into batch. More specifically, this op outputs a copy of the input tensor where values from the height and width dimensions are moved to the batch dimension. After the zero-padding is according to the `pad` argument, both height and width of the input must be divisible by the `block_size`. Only "NCHW" order is currently supported. 10 - https://github.com/pytorch/pytorch/blob/master/caffe2/operators/space_batch_op.cc 14 <summary> <b>Example</b> </summary> 20 workspace.ResetWorkspace() 22 op = core.CreateOperator( 30 workspace.FeedBlob("X", np.random.rand(1,3,5,5).astype(np.float32)) 31 print("X.shape:", workspace.FetchBlob("X").shape) 32 workspace.RunOperatorOnce(op) 33 print("Y.shape:", workspace.FetchBlob("Y").shape) 49 .Arg("pad",
"(*int*): exclusive axis that divides the first and second dimension of matrix `A` (default=0)")
50 .Arg(
"block_size",
"(*int*): height/width of spatial blocks to be moved (default=2)")
51 .Arg(
"order",
"(*string*): order of dimensions of input and output blobs; only \"NCHW\" order is currently supported (default=\"NCHW\")")
52 .Input(0,
"X",
"(*Tensor`<float>`*): input tensor (NCHW order)")
53 .Output(0,
"Y",
"(*Tensor`<float>`*): output tensor (NCHW order)");
55 REGISTER_CPU_OPERATOR(BatchToSpace, BatchToSpaceOp<CPUContext>);
56 OPERATOR_SCHEMA(BatchToSpace).NumInputs(1).NumOutputs(1).SetDoc(R
"DOC( 57 Rearranges (permutes) data from batch into blocks of spatial data, followed by cropping. This is the reverse transformation of `SpaceToBatch`. More specifically, this op outputs a copy of the input tensor where values from the batch dimension are moved in spatial blocks to the height and width dimensions, followed by cropping along the height and width dimensions. Only "NCHW" order is currently supported. 60 - https://github.com/pytorch/pytorch/blob/master/caffe2/operators/space_batch_op.cc 64 <summary> <b>Example</b> </summary> 70 workspace.ResetWorkspace() 72 op = core.CreateOperator( 79 workspace.FeedBlob("X", np.random.rand(10,3,32,32).astype(np.float32)) 80 print("X.shape:", workspace.FetchBlob("X").shape) 81 workspace.RunOperatorOnce(op) 82 print("Y.shape:", workspace.FetchBlob("Y").shape) 90 X.shape: (10, 3, 32, 32) 91 Y.shape: (2, 3, 58, 58) 98 .Arg("pad",
"(*int*): exclusive axis that divides the first and second dimension of matrix `A` (default=0)")
99 .Arg(
"block_size",
"(*int*): height/width of spatial blocks to be moved (default=2)")
100 .Arg(
"order",
"(*string*): order of dimensions of input and output blobs; only \"NCHW\" order is currently supported (default=\"NCHW\")")
101 .Input(0,
"X",
"(*Tensor`<float>`*): input tensor (NCHW order)")
102 .Output(0,
"Y",
"(*Tensor`<float>`*): output tensor (NCHW order)");
105 using GradientMakerBase::GradientMakerBase;
106 vector<OperatorDef> GetGradientDefs()
override {
108 "BatchToSpace",
"", vector<string>{GO(0)}, vector<string>{GI(0)});
113 using GradientMakerBase::GradientMakerBase;
114 vector<OperatorDef> GetGradientDefs()
override {
116 "SpaceToBatch",
"", vector<string>{GO(0)}, vector<string>{GI(0)});
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 ...