1 #include "caffe2/operators/shape_op.h" 5 REGISTER_CPU_OPERATOR(Shape, ShapeOp<CPUContext>);
12 "*(type: int[])* Array of interested axes." 13 "If given, this operator only returns the dimensions of the given axes." 14 "Otherwise, the operator returns the dimensions of all axes.")
15 .TensorInferenceFunction([](
const OperatorDef& def,
16 const vector<TensorShape>& in) {
17 ArgumentHelper args(def);
18 const vector<int>& axes = args.GetRepeatedArgument<
int>(
"axes");
19 vector<TensorShape> out(1);
21 out[0].add_dims(in[0].dims().size());
23 out[0].add_dims(axes.size());
25 out[0].set_data_type(TensorProto::INT64);
29 Produce a 1D int64 tensor with the shape of the input tensor. 30 If called with an optional argument `axes`, the result will only 31 contain the dimensions of specified axes. 34 - https://github.com/pytorch/pytorch/blob/master/caffe2/operators/shape_op.cc 38 <summary> <b>Example</b> </summary> 44 workspace.ResetWorkspace() 46 op = core.CreateOperator( 52 workspace.FeedBlob("X", (np.random.randint(10, size=(2,3)))) 53 print("X:", workspace.FetchBlob("X")) 54 workspace.RunOperatorOnce(op) 55 print("shape:", workspace.FetchBlob("shape")) 73 .Input(0,"X",
"*(type: Tensor)* Input tensor.")
74 .Output(0,
"shape",
"*(type: Tensor)* Output tensor containing shape of input tensor.");
76 SHOULD_NOT_DO_GRADIENT(Shape);
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...