1 #include "caffe2/operators/gather_ranges_to_dense_op.h" 6 OPERATOR_SCHEMA(GatherRangesToDense)
8 .NumOutputs(1, INT_MAX)
10 Given DATA tensor of rank 1, and RANGES tensor of rank 3, gather values 11 corresponding to each range into a separate output tensor. If the optional input 12 KEY tensor is also given, the output will be sorted by KEY for each example. 14 RANGES dimensions description: 15 1: represents list of examples within a batch 16 2: represents list features 17 3: two values which are start and length or a range (to be applied on DATA) 19 Each feature has fixed lengths which are passed as lengths argument and a 20 separate tensor will be produced for each feature. 21 i.e. DATA.dim(1) = len(lengths) = NumOuptuts. 23 Missing features (represented by empty ranges) filled with default_value. 26 DATA = [1, 2, 3, 4, 5, 6, 7, 8] 38 OUTPUT[0] = [[3, 4, 5, 6], [0, 0, 0, 0]] 39 OUTPUT[1] = [[1, 2], [7, 8]] 42 DATA = [1, 2, 3, 4, 5, 6, 7, 8] 43 KEY = [0, 1, 3, 2, 1, 0, 1, 0] 55 OUTPUT[0] = [[6, 5, 4, 3], [0, 0, 0, 0]] 56 OUTPUT[1] = [[1, 2], [8, 7]] 58 Contrast Example 2 with Example 1. For each data point per feature, the values 59 are sorted by the corresponding KEY. 61 .Input(0, "DATA",
"Tensor of rank 1.")
65 "Tensor of int32/int64 ranges, of dims (N, M, 2). " 66 "Where N is number of examples and M is a size of each example. " 67 "Last dimention represents a range in the format (start, lengths)")
68 .Input(2,
"KEY",
"Tensor of rank 1 and type int64.")
69 .Output(0,
"OUTPUT",
"1-D tensor of size sum of range lengths")
70 .Arg(
"lengths",
"Expected lengths for ranges")
71 .TensorInferenceFunction([](
const OperatorDef& def,
72 const vector<TensorShape>& in) {
73 ArgumentHelper helper(def);
74 auto lengths = helper.GetRepeatedArgument<
int>(
"lengths");
75 CAFFE_ENFORCE_EQ(in[0].dims_size(), 1,
"DATA should be 1-D tensor.");
76 CAFFE_ENFORCE_EQ(in[1].dims_size(), 3,
"RANGES should be 3-D tensor.");
78 CAFFE_ENFORCE_EQ(in[2].dims_size(), 1,
"KEY should be 1-D tensor.");
80 CAFFE_ENFORCE_GT(lengths.size(), 0,
"lengths should be non-empty.");
81 std::vector<TensorShape> out(lengths.size());
82 for (
int i = 0; i < lengths.size(); ++i) {
83 out[i].set_data_type(in[0].data_type());
84 out[i].add_dims(in[1].dims(0));
85 out[i].add_dims(lengths[i]);
90 REGISTER_CPU_OPERATOR(GatherRangesToDense, GatherRangesToDenseOp<CPUContext>);
91 NO_GRADIENT(GatherRangesToDense);
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...