# Source code for mindarmour.attacks.attack

# Copyright 2019 Huawei Technologies Co., Ltd
#
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# Unless required by applicable law or agreed to in writing, software
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
"""
Base Class of Attack.
"""
from abc import abstractmethod

import numpy as np

from mindarmour.utils._check_param import check_pair_numpy_param, \
check_int_positive
from mindarmour.utils.logger import LogUtil

LOGGER = LogUtil.get_instance()
TAG = 'Attack'

[docs]class Attack: """ The abstract base class for all attack classes creating adversarial examples. """ def __init__(self): pass
[docs] @abstractmethod def generate(self, inputs, labels): """ Generate adversarial examples based on normal samples and their labels. Args: inputs (numpy.ndarray): Samples based on which adversarial examples are generated. labels (numpy.ndarray): Labels of samples, whose values determined by specific attacks. Raises: NotImplementedError: It is an abstract method. """ msg = 'The function generate() is an abstract function in class ' \ 'Attack and should be implemented in child class.' LOGGER.error(TAG, msg) raise NotImplementedError(msg)