1 #include "caffe2/operators/filler_op.h" 6 bool RangeFillOp<float, CPUContext>::Fill(
8 float* data = output->mutable_data<
float>();
9 for (
int i = 0; i < output->size(); ++i) {
17 bool DiagonalFillOp<CPUContext>::FillWithType(TensorCPU* output) {
18 VerifyOutputShape(output);
19 T value = OperatorBase::GetSingleArgument<T>(
"value", 0);
20 auto* data = output->template mutable_data<T>();
22 math::Set<T, CPUContext>(output->size(), T(0), data, &context_);
24 auto step = GetStepSize(output);
25 for (TIndex i = 0; i < output->size(); i += step) {
26 math::Set<T, CPUContext>(1, value, data, &context_);
32 REGISTER_CPU_OPERATOR(UniformFill, UniformFillOp<float, CPUContext>);
33 REGISTER_CPU_OPERATOR(UniformIntFill, UniformFillOp<int, CPUContext>);
34 REGISTER_CPU_OPERATOR(UniqueUniformFill, UniqueUniformFillOp<CPUContext>);
35 REGISTER_CPU_OPERATOR(ConstantFill, ConstantFillOp<CPUContext>);
36 REGISTER_CPU_OPERATOR(DiagonalFill, DiagonalFillOp<CPUContext>);
37 REGISTER_CPU_OPERATOR(GaussianFill, GaussianFillOp<float, CPUContext>);
38 REGISTER_CPU_OPERATOR(XavierFill, XavierFillOp<float, CPUContext>);
39 REGISTER_CPU_OPERATOR(MSRAFill, MSRAFillOp<float, CPUContext>);
40 REGISTER_CPU_OPERATOR(RangeFill, RangeFillOp<float, CPUContext>);
41 REGISTER_CPU_OPERATOR(LengthsRangeFill, LengthsRangeFillOp<CPUContext>);
43 OPERATOR_SCHEMA(ConstantFill)
46 .AllowInplace({{0, 0}})
47 .TensorInferenceFunction(FillerTensorInference<>)
49 The operator fills the elements of the output tensor with a constant value 50 specified by the 'value' argument. 52 The data type is specified by the 'dtype' argument. The 'dtype' argument must 53 be one of the data types specified in the 'DataType' enum field in the 54 TensorProto message. If the 'dtype' argument is not provided, the data type of 57 The output tensor shape is specified by the 'shape' argument. If the number of 58 input is 1, the shape will be identical to that of the input at run time with 59 optional additional dimensions appended at the end as specified by 'extra_shape' 60 argument. In that case the 'shape' argument should not be set. 62 If input_as_shape is set to true, then the input should be a 1D tensor 63 containing the desired output shape (the dimensions specified in extra_shape 64 will also be appended) 66 NOTE: Currently, it supports data type of float, int32, int64, and bool. 68 .Arg("value",
"The value for the elements of the output tensor.")
71 "The data type for the elements of the output tensor." 72 "Strictly must be one of the types from DataType enum in TensorProto.")
75 "The shape of the output tensor." 76 "Cannot set the shape argument and pass in an input at the same time.")
79 "The additional dimensions appended at the end of the shape indicated" 81 "Cannot set the extra_shape argument when there is no input blob.")
84 "1D tensor containing the desired output shape. First input must be in CPU context.")
85 .Input(0,
"input",
"Input tensor (optional) to provide shape information.")
89 "Output tensor of constant values specified by 'value'" 90 "argument and its type is specified by the 'dtype' argument");
92 OPERATOR_SCHEMA(DiagonalFill)
95 .AllowInplace({{0, 0}})
96 .TensorInferenceFunction(FillerTensorInference<>)
98 The operator fills the diagonal elements of the output tensor (>= 2D) 99 with a constant value specified by the 'value' argument, and others 0. If 100 number of dimensions of the output tensor is greater than 2, all dimensions 103 The data type is specified by the 'dtype' argument. The 'dtype' argument must 104 be one of the data types specified in the 'DataType' enum field in the 105 TensorProto message. If the 'dtype' argument is not provided, the data type of 108 The output tensor shape is specified by the 'shape' argument. If the number of 109 input is 1, the shape will be identical to that of the input at run time with 110 optional additional dimensions appended at the end as specified by 'extra_shape' 111 argument. In that case the 'shape' argument should not be set. 113 If input_as_shape is set to true, then the input should be a 1D tensor 114 containing the desired output shape (the dimensions specified in extra_shape 115 will also be appended) 117 NOTE: Currently, it supports data type of float, int32, int64, and bool. 119 .Arg("value",
"The value for the elements of the output tensor.")
122 "The data type for the elements of the output tensor." 123 "Strictly must be one of the types from DataType enum in TensorProto.")
126 "The shape of the output tensor." 127 "Cannot set the shape argument and pass in an input at the same time.")
130 "The additional dimensions appended at the end of the shape indicated" 132 "Cannot set the extra_shape argument when there is no input blob.")
133 .Arg(
"input_as_shape",
"1D tensor containing the desired output shape")
134 .Input(0,
"input",
"Input tensor (optional) to provide shape information.")
139 "argument and its type is specified by the 'dtype' argument");
141 OPERATOR_SCHEMA(UniformFill)
142 .NumInputs({0, 1, 3})
144 .AllowInplace({{0, 0}})
145 .TensorInferenceFunction(FillerTensorInference<>)
147 Fill the output tensor with FLOAT samples from uniform distribution [min, max]. 149 The range can be defined either by arguments or input blobs. If the range is 150 given by input blobs, you also need to give the shape as input. When the range 151 is given as arguments, this operator enforces min <= max. When the range is 152 given as inputs, the constraint is not enforced. When MAX < MIN, the first 153 dimension of the output is set to 0. This behavior is allowed so that 154 dynamically sampling indices into a dynamically sized tensor is possible. 156 The shape of the output can be given as argument or input. 158 .Arg("min",
"minimum value, inclusive")
159 .Arg(
"max",
"maximum value, inclusive")
160 .Arg(
"shape",
"shape of the output, do not set when input_as_shape=1")
163 "set to 1 to use the first input as shape. First input must be in CPU context.")
167 "1-D tensor of the shape of the output, " 168 "must be used with input_as_shape")
169 .Input(1,
"MIN",
"scalar blob of mininum value")
170 .Input(2,
"MAX",
"scalar blob of maximum value")
171 .Output(0,
"OUTPUT",
"output tensor");
172 OPERATOR_SCHEMA(UniformIntFill)
173 .NumInputs({0, 1, 3})
175 .AllowInplace({{0, 0}})
176 .TensorInferenceFunction(FillerTensorInference<>)
178 Like `UniformFill` but fill with INT32. 180 OPERATOR_SCHEMA(UniqueUniformFill) 183 .AllowInplace({{0, 0}}) 184 .TensorInferenceFunction(FillerTensorInference<>) 186 Fill the output tensor with uniform samples between min and max (inclusive). 187 If the second input is given, its elements will be excluded from uniform 188 sampling. Using the second input will require you to provide shape via the first 191 .Arg("min",
"Minimum value, inclusive")
192 .Arg(
"max",
"Maximum value, inclusive")
195 "The data type for the elements of the output tensor." 196 "Strictly must be one of the types from DataType enum in TensorProto." 197 "This only supports INT32 and INT64 now. If not set, assume INT32")
200 "The shape of the output tensor." 201 "Cannot set the shape argument and pass in an input at the same time.")
204 "The additional dimensions appended at the end of the shape indicated" 205 "by the input blob. " 206 "Cannot set the extra_shape argument when there is no input blob.")
209 "1D tensor containing the desired output shape. First input must be in CPU context.")
210 .Input(0,
"input",
"Input tensor to provide shape information")
214 "(optional) Avoid elements in this tensor. Elements must be unique.")
215 .Output(0,
"output",
"Output tensor of unique uniform samples");
216 OPERATOR_SCHEMA(GaussianFill)
219 .AllowInplace({{0, 0}})
220 .TensorInferenceFunction(FillerTensorInference<>);
221 OPERATOR_SCHEMA(XavierFill)
224 .AllowInplace({{0, 0}})
225 .TensorInferenceFunction(FillerTensorInference<>);
226 OPERATOR_SCHEMA(MSRAFill)
229 .AllowInplace({{0, 0}})
230 .TensorInferenceFunction(FillerTensorInference<>);
231 OPERATOR_SCHEMA(RangeFill)
234 .AllowInplace({{0, 0}})
235 .TensorInferenceFunction(FillerTensorInference<>);
237 NO_GRADIENT(UniformFill);
238 NO_GRADIENT(UniformIntFill);
239 NO_GRADIENT(UniqueUniformFill);
240 NO_GRADIENT(ConstantFill);
241 NO_GRADIENT(DiagonalFill);
242 NO_GRADIENT(GaussianFill);
243 NO_GRADIENT(XavierFill);
244 NO_GRADIENT(MSRAFill);
245 NO_GRADIENT(RangeFill);
247 OPERATOR_SCHEMA(LengthsRangeFill)
251 Convert a length vector to a range sequence. For example, input=[4,3,1], the 252 output would be [0,1,2,3,0,1,2,0]. 254 .Input(0, "lengths",
"1D tensor of int32 or int64 segment lengths.")
258 "1D tensor whose size is the sum of `lengths`");
259 NO_GRADIENT(LengthsRangeFill);
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...