Caffe2 - C++ API
A deep learning, cross platform ML framework
lengths_top_k_op.h
1 
2 #ifndef CAFFE2_OPERATORS_LENGTHS_TOP_K_OP_H_
3 #define CAFFE2_OPERATORS_LENGTHS_TOP_K_OP_H_
4 
5 #include "caffe2/core/context.h"
6 #include "caffe2/core/logging.h"
7 #include "caffe2/core/operator.h"
8 #include "caffe2/operators/conv_pool_op_base.h"
9 #include "caffe2/utils/math.h"
10 
11 namespace caffe2 {
12 template <typename T, class Context>
13 class LengthsTopKOp : public Operator<Context> {
14  public:
15  USE_OPERATOR_CONTEXT_FUNCTIONS;
16 
17  LengthsTopKOp(const OperatorDef& operator_def, Workspace* ws)
18  : Operator<Context>(operator_def, ws), OP_SINGLE_ARG(int, "k", k_, -1) {
19  CAFFE_ENFORCE_GE(k_, 1, "k argument must be >= 1");
20  }
21 
22  bool RunOnDevice() override;
23 
24  protected:
25  int k_;
26  INPUT_TAGS(X_IN, Y_IN);
27  OUTPUT_TAGS(TOPK_VALUES_OUT, TOPK_INDICES_OUT);
28 };
29 
30 template <typename T, class Context>
31 class LengthsTopKGradientOp : public Operator<Context> {
32  public:
33  LengthsTopKGradientOp(const OperatorDef& def, Workspace* ws)
34  : Operator<Context>(def, ws), OP_SINGLE_ARG(int, "k", k_, -1) {
35  CAFFE_ENFORCE_GE(k_, 1, "k argument must be >= 1");
36  }
37  USE_OPERATOR_CONTEXT_FUNCTIONS;
38 
39  bool RunOnDevice() override;
40 
41  protected:
42  int k_;
43  INPUT_TAGS(LENGTH_IN, INDICES_IN, DER_TOPK_IN);
44  OUTPUT_TAGS(DER_X_OUT);
45 };
46 
47 } // namespace caffe2
48 
49 #endif // CAFFE2_OPERATORS_LENGTHS_TOP_K_OP_H_
Workspace is a class that holds all the related objects created during runtime: (1) all blobs...
Definition: workspace.h:47
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...