提交 982be7ce 编写于 作者: wgzqz's avatar wgzqz

Fix some PEP8 warning.

上级 9542bab2
......@@ -2,6 +2,6 @@
A set of tools for generating adversarial example on paddle platform
"""
from . import attacks # type: ignore # noqa: F401
from . import models # type: ignore # noqa: F401
from .adversary import Adversary # noqa: F401
from . import attacks
from . import models
from .adversary import Adversary
......@@ -29,18 +29,19 @@ class Attack(object):
Args:
adversary(object): The adversary object.
**kwargs: Other params.
**kwargs: Other named arguments.
"""
self._preprocess(adversary)
return self._apply(adversary, **kwargs)
@abstractmethod
def _apply(self, adversary):
def _apply(self, adversary, **kwargs):
"""
Search an adversarial example.
Args:
adversary(object): The adversary object.
**kwargs: Other named arguments.
"""
raise NotImplementedError
......@@ -65,6 +66,6 @@ class Attack(object):
logging.info('adversary:\noriginal_label: {}'
'\n target_lable: {}'
'\n is_targeted_attack: {}'.format(
adversary.original_label, adversary.target_label,
adversary.is_targeted_attack))
'\n is_targeted_attack: {}'
''.format(adversary.original_label, adversary.target_label,
adversary.is_targeted_attack))
......@@ -20,6 +20,14 @@ class GradientSignAttack(Attack):
"""
def _apply(self, adversary, epsilons=1000):
"""
Apply the gradient sign attack.
Args:
adversary(Adversary): The Adversary object.
epsilons(list|tuple|int): The epsilon (input variation parameter).
Return:
adversary: The Adversary object.
"""
assert adversary is not None
if not isinstance(epsilons, Iterable):
......
......@@ -21,11 +21,11 @@ class IteratorGradientSignAttack(Attack):
"""
Apply the iterative gradient sign attack.
Args:
adversary(object): The image and label tuple list of one element.
adversary(Adversary): The Adversary object.
epsilons(list|tuple|int): The epsilon (input variation parameter).
steps(int): The number of iterator steps.
Return:
numpy.ndarray: The adversarail sample generated by the algorithm.
adversary(Adversary): The Adversary object.
"""
if not isinstance(epsilons, Iterable):
......
"""
Paddle model for target of attack
"""
from .base import Model # noqa: F401
from .paddle import PaddleModel # noqa: F401
from .base import Model
from .paddle import PaddleModel
"""
Paddle model
"""
from __future__ import absolute_import
import paddle.v2.fluid as fluid
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册