Skip to content

Commit 644d04b

Browse files
committed
Merge branch 'develop' into v1_api
2 parents 0d4b8ae + 38c6105 commit 644d04b

File tree

6 files changed

+78
-3
lines changed

6 files changed

+78
-3
lines changed

.copyright.hook

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def main(argv=None):
9090
retv = 0
9191
for filename in args.filenames:
9292
first_line = io.open(filename).readline()
93-
if "Copyright" in first_line: continue
93+
if "COPYRIGHT" in first_line.upper() : continue
9494
original_contents = io.open(filename).read()
9595
new_contents = generate_copyright(
9696
COPYRIGHT, lang_type(filename)) + original_contents

adversarial/advbox/attacks/gradientsign.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,39 @@ def _apply(self, image_label, epsilons=1000):
4949

5050

5151
FGSM = GradientSignAttack
52+
53+
54+
class IteratorGradientSignAttack(Attack):
55+
"""
56+
This attack was originally implemented by Alexey Kurakin(Google Brain).
57+
Paper link: https://arxiv.org/pdf/1607.02533.pdf
58+
"""
59+
60+
def _apply(self, image_label, epsilons=100, steps=10):
61+
"""
62+
Apply the iterative gradient sign attack.
63+
Args:
64+
image_label(list): The image and label tuple list of one element.
65+
epsilons(list|tuple|int): The epsilon (input variation parameter).
66+
steps(int): The number of iterator steps.
67+
Return:
68+
numpy.ndarray: The adversarail sample generated by the algorithm.
69+
"""
70+
assert len(image_label) == 1
71+
pre_label = np.argmax(self.model.predict(image_label))
72+
gradient = self.model.gradient(image_label)
73+
min_, max_ = self.model.bounds()
74+
75+
if not isinstance(epsilons, Iterable):
76+
epsilons = np.linspace(0, 1, num=epsilons + 1)
77+
78+
for epsilon in epsilons:
79+
adv_img = image_label[0][0].reshape(gradient.shape)
80+
for _ in range(steps):
81+
gradient = self.model.gradient([(adv_img, image_label[0][1])])
82+
gradient_sign = np.sign(gradient) * (max_ - min_)
83+
adv_img = adv_img + epsilon * gradient_sign
84+
adv_img = np.clip(adv_img, min_, max_)
85+
adv_label = np.argmax(self.model.predict([(adv_img, 0)]))
86+
if pre_label != adv_label:
87+
return adv_img

benchmark/tensorflow/image/googlenet_multi_gpu.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserve.
2+
#
3+
#Licensed under the Apache License, Version 2.0 (the "License");
4+
#you may not use this file except in compliance with the License.
5+
#You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
#Unless required by applicable law or agreed to in writing, software
10+
#distributed under the License is distributed on an "AS IS" BASIS,
11+
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
#See the License for the specific language governing permissions and
13+
#limitations under the License.
114
from six.moves import xrange # pylint: disable=redefined-builtin
215
from datetime import datetime
316
import math

doc/getstarted/concepts/src/infer.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserve.
2+
#
3+
#Licensed under the Apache License, Version 2.0 (the "License");
4+
#you may not use this file except in compliance with the License.
5+
#You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
#Unless required by applicable law or agreed to in writing, software
10+
#distributed under the License is distributed on an "AS IS" BASIS,
11+
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
#See the License for the specific language governing permissions and
13+
#limitations under the License.
114
import paddle.v2 as paddle
215
import numpy as np
316

paddle/operators/op_documentation/batch_norm_op.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ As most C++ operators do, `batch_norm_op` is defined by inputs, outputs, attribu
6666

6767
The following graph showes the training computational process of `batch_norm_op`:
6868

69-
<img src="./images/batch_norm_op_kernel.png" width="800"/>
69+
<img src="../images/batch_norm_op_kernel.png" width="800"/>
7070

7171
cudnn provides APIs to finish the whole series of computation, we can use them in our GPU kernel.
7272

@@ -124,7 +124,7 @@ for pass_id in range(PASS_NUM):
124124
`is_infer` is an attribute. Once an operator is created, its attributes can not be changed. It suggests us that we shall maintain two `batch_norm_op` in the model, one's `is_infer` is `True`(we call it `infer_batch_norm_op`) and the other one's is `False`(we call it `train_batch_norm_op`). They share all parameters and variables, but be placed in two different branches. That is to say, if a network contains a `batch_norm_op`, it will fork into two branches, one go through `train_batch_norm_op` and the other one go through `infer_batch_norm_op`:
125125

126126
<div align=center>
127-
<img src="./images/batch_norm_fork.png" width="500"/>
127+
<img src="../images/batch_norm_fork.png" width="500"/>
128128
</div>
129129

130130
Just like what is shown in the above graph, the net forks before `batch_norm_op` and will never merge again. All the operators after `batch_norm_op` will duplicate.

python/paddle/v2/fluid/tests/test_dynrnn_static_input.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserve.
2+
#
3+
#Licensed under the Apache License, Version 2.0 (the "License");
4+
#you may not use this file except in compliance with the License.
5+
#You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
#Unless required by applicable law or agreed to in writing, software
10+
#distributed under the License is distributed on an "AS IS" BASIS,
11+
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
#See the License for the specific language governing permissions and
13+
#limitations under the License.
114
import unittest
215
import paddle.v2 as paddle
316
import paddle.v2.fluid.core as core

0 commit comments

Comments
 (0)