1 #include "caffe2/operators/lengths_pad_op.h" 4 REGISTER_CPU_OPERATOR(LengthsPad, LengthsPadOp<CPUContext>);
6 OPERATOR_SCHEMA(LengthsPad)
10 Given DATA tensor of rank r >= 1, and LENGTHS tensor of rank 1, pad each 11 segment in DATA with `value`, so that each segment's length is `target_length`. 12 If will throw, if there is segment of length larger than `target_length`. 20 LENGTHS = [0, 1, 1, 1] 21 and target_length = 2, padding value = -1.0 36 "Tensor of rank r >= 1. First dimension must be equal to the size of " 38 .Input(1,
"LENGTHS",
"Tensor of int32 lengths of rank 1")
39 .Output(0,
"OUTPUT",
"Padded DATA tensor")
40 .Arg(
"padding_value",
"The value to pad the data")
41 .Arg(
"target_length",
"The target length of each segment")
42 .TensorInferenceFunction([](
const OperatorDef& def,
43 const vector<TensorShape>& in) {
44 vector<TensorShape> out(1);
45 ArgumentHelper helper(def);
46 int target_length = helper.GetSingleArgument<
int>(
"target_length", -1);
47 CAFFE_ENFORCE_GE(target_length, 1);
48 vector<int> output_dims;
49 const auto& data_dims = GetDimsVector(in[0]);
50 const auto& lengths_dims = GetDimsVector(in[1]);
51 output_dims.push_back(lengths_dims[0] * target_length);
53 output_dims.end(), data_dims.begin() + 1, data_dims.end());
55 out[0] = CreateTensorShape(output_dims, in[0].data_type());
59 NO_GRADIENT(LengthsPad);
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...