提交 13e254fa 编写于 作者: J jerrywgz

refine code, test=develop

上级 79cec531
......@@ -174,7 +174,7 @@ paddle.fluid.layers.clip ArgSpec(args=['x', 'min', 'max', 'name'], varargs=None,
paddle.fluid.layers.clip_by_norm ArgSpec(args=['x', 'max_norm', 'name'], varargs=None, keywords=None, defaults=(None,))
paddle.fluid.layers.mean ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,))
paddle.fluid.layers.mul ArgSpec(args=['x', 'y', 'x_num_col_dims', 'y_num_col_dims', 'name'], varargs=None, keywords=None, defaults=(1, 1, None))
paddle.fluid.layers.sigmoid_cross_entropy_with_logits ArgSpec(args=['x', 'label', 'name'], varargs=None, keywords=None, defaults=(None,))
paddle.fluid.layers.sigmoid_cross_entropy_with_logits ArgSpec(args=['x', 'label', 'ignore_index', 'name'], varargs=None, keywords=None, defaults=(-100, None))
paddle.fluid.layers.maxout ArgSpec(args=['x', 'groups', 'name'], varargs=None, keywords=None, defaults=(None,))
paddle.fluid.layers.space_to_depth ArgSpec(args=['x', 'blocksize', 'name'], varargs=None, keywords=None, defaults=(None,))
paddle.fluid.layers.affine_grid ArgSpec(args=['theta', 'out_shape', 'name'], varargs=None, keywords=None, defaults=(None,))
......
......@@ -102,9 +102,9 @@ class SigmoidCrossEntropyWithLogitsOpMaker
" of elementwise logistic losses.");
AddAttr<int>(
"ignore_index",
"(int, default -1), Specifies a target value that is ignored and"
"(int, default -100), Specifies a target value that is ignored and"
"does not contribute to the input gradient.")
.SetDefault(-1);
.SetDefault(-100);
AddComment(R"DOC(
SigmoidCrossEntropyWithLogits Operator.
......
......@@ -31,7 +31,6 @@ using EigenMatrix = framework::EigenMatrix<T, MajorType, IndexType>;
template <typename T>
struct SigmoidCrossEntropyWithLogitsForward {
// EIGEN_EMPTY_STRUCT_CTOR(SigmoidCrossEntropyWithLogitsForward)
HOSTDEVICE SigmoidCrossEntropyWithLogitsForward(const int &ignore_index)
: ignore_index(ignore_index) {}
......@@ -50,7 +49,6 @@ struct SigmoidCrossEntropyWithLogitsForward {
template <typename T>
struct SigmoidCrossEntropyWithLogitsBackward {
// EIGEN_EMPTY_STRUCT_CTOR(SigmoidCrossEntropyWithLogitsForward)
HOSTDEVICE SigmoidCrossEntropyWithLogitsBackward(const int &ignore_index)
: ignore_index(ignore_index) {}
......@@ -83,14 +81,6 @@ class SigmoidCrossEntropyWithLogitsKernel : public framework::OpKernel<T> {
out.device(place) = x.binaryExpr(
labels, SigmoidCrossEntropyWithLogitsForward<T>(ignore_index));
// term1 = max(x, 0)
// auto term1 = x.cwiseMax(static_cast<T>(0));
// term2 = x * labels
// auto term2 = x * labels;
// term3 = log(1 + exp(-abs(x)))
// auto term3 = (static_cast<T>(1) + (-(x.abs())).exp()).log();
// out.device(place) = term1 - term2 + term3;
}
};
......
......@@ -7892,7 +7892,7 @@ def mul(x, y, x_num_col_dims=1, y_num_col_dims=1, name=None):
@templatedoc()
def sigmoid_cross_entropy_with_logits(x, label, ignore_index=-1, name=None):
def sigmoid_cross_entropy_with_logits(x, label, ignore_index=-100, name=None):
"""
${comment}
......
......@@ -173,7 +173,7 @@ class TestBook(unittest.TestCase):
ignore_index = -1
self.assertIsNotNone(
layers.sigmoid_cross_entropy_with_logits(
x=dat, label=lbl, ignore_index=-1))
x=dat, label=lbl, ignore_index=ignore_index))
print(str(program))
def test_hsigmoid(self):
......
......@@ -119,4 +119,3 @@ class TestSigmoidCrossEntropyWithLogitsOp3(OpTest):
if __name__ == '__main__':
unittest.main()
np.random.seed(0)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册