-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcenterloss.cc
68 lines (58 loc) · 2.26 KB
/
centerloss.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
/*!
* Copyright (c) 2017 by Contributors
* \file centerloss.cc
* \brief centerloss
* \author deepearthgo
*/
#include "./centerloss-inl.h"
namespace mshadow {
template <typename DType>
inline void centerlossForward(const Tensor<cpu, 2, DType> &x,
const Tensor<cpu, 2, DType> &w,
const Tensor<cpu, 1, DType> &label,
const Tensor<cpu, 2, DType> &out,
const Tensor<cpu, 2, DType> &diff,
const Tensor<cpu, 2, DType> ¢er,
const int batch_size) {
LOG(FATAL) << "Not Implemented.";
}
template <typename DType>
inline void centerlossBackward(const Tensor<cpu, 2, DType> &diff,
const Tensor<cpu, 2, DType> ¢er,
const Tensor<cpu, 1, DType> &label,
const Tensor<cpu, 2, DType> &o_grad,
const Tensor<cpu, 2, DType> &x_grad,
const float scale,
const int batch_size,
const int class_num,
const float alpha) {
LOG(FATAL) << "Not Implemented.";
}
} // namespace mshadow
namespace mxnet {
namespace op {
template<>
Operator *CreateOp<cpu>(centerlossParam param, int dtype) {
Operator *op = NULL;
MSHADOW_REAL_TYPE_SWITCH(dtype, DType, {
op = new centerlossOp<cpu, DType>(param);
})
return op;
}
Operator *centerlossProp::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("Centerloss from <Centerloss Loss for Convolutional Neural Networks>")
.add_argument("data", "Symbol", "data")
.add_argument("weight", "Symbol", "weight")
.add_argument("label", "Symbol", "label")
.add_arguments(centerlossParam::__FIELDS__());
} // namespace op
} // namespace mxne