-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfocalloss.cc
69 lines (59 loc) · 2.3 KB
/
focalloss.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*!
* Copyright (c) 2017 by Contributors
* \file focalloss.cc
* \brief focalloss
* \author deepearthgo
*/
#include "./focalloss-inl.h"
namespace mshadow {
template <typename DType>
inline void FocallossForward(const Tensor<cpu, 2, DType> &cls_score,
const Tensor<cpu, 2, DType> &cls_score_max,
const Tensor<cpu, 2, DType> &cls_score_sub,
const Tensor<cpu, 1, DType> &label,
const Tensor<cpu, 2, DType> &pro_,
const Tensor<cpu, 2, DType> &pro_sum,
const Tensor<cpu, 2, DType> &pro_div,
const Tensor<cpu, 1, DType> &_pt,
Tensor<cpu, 2, DType> out,
const float gamma,
const float alpha) {
LOG(FATAL) << "Not Implemented.";
}
template <typename DType>
inline void FocallossBackward(const Tensor<cpu, 1, DType> &label,
const Tensor<cpu, 1, DType> &_pt,
const Tensor<cpu, 2, DType> &pro_,
const Tensor<cpu, 2, DType> &o_grad,
const Tensor<cpu, 2, DType> &x_grad,
const float gamma,
const float alpha) {
LOG(FATAL) << "Not Implemented.";
}
} // namespace mshadow
namespace mxnet {
namespace op {
template<>
Operator *CreateOp<cpu>(FocallossParam param, int dtype) {
Operator *op = NULL;
MSHADOW_REAL_TYPE_SWITCH(dtype, DType, {
op = new FocallossOp<cpu, DType>(param);
})
return op;
}
Operator *FocallossProp::CreateOperatorEx(Context ctx, std::vector<TShape> *in_shape,
std::vector<int> *in_type) const {
std::vector<TShape> out_shape, aux_shape;
std::vector<int> out_type, aux_type;
CHECK(InferType(in_type, &out_type, &aux_type));
CHECK(InferShape(in_shape, &out_shape, &aux_shape));
DO_BIND_DISPATCH(CreateOp, param_, in_type->at(0));
}
DMLC_REGISTER_PARAMETER(centerlossParam);
MXNET_REGISTER_OP_PROPERTY(centerloss, centerlossProp)
.describe("Focalloss")
.add_argument("data", "Symbol", "data")
.add_argument("label", "Symbol", "label")
.add_arguments(centerlossParam::__FIELDS__());
} // namespace op
} // namespace mxne