diff --git a/.gitignore b/.gitignore index c325131..446d990 100644 --- a/.gitignore +++ b/.gitignore @@ -244,6 +244,4 @@ $RECYCLE.BIN/ *.msp # Windows shortcuts -*.lnk - -models/ \ No newline at end of file +*.lnk \ No newline at end of file diff --git a/src/__init__.py b/secml2/__init__.py similarity index 100% rename from src/__init__.py rename to secml2/__init__.py diff --git a/src/adv/backends.py b/secml2/adv/backends.py similarity index 100% rename from src/adv/backends.py rename to secml2/adv/backends.py diff --git a/src/adv/evasion/base_evasion_attack.py b/secml2/adv/evasion/base_evasion_attack.py similarity index 91% rename from src/adv/evasion/base_evasion_attack.py rename to secml2/adv/evasion/base_evasion_attack.py index 68e11d0..91b5431 100644 --- a/src/adv/evasion/base_evasion_attack.py +++ b/secml2/adv/evasion/base_evasion_attack.py @@ -3,9 +3,9 @@ from torch.utils.data import DataLoader -from src.adv.backends import Backends -from src.adv.evasion.perturbation_models import PerturbationModels -from src.models.base_model import BaseModel +from secml2.adv.backends import Backends +from secml2.adv.evasion.perturbation_models import PerturbationModels +from secml2.models.base_model import BaseModel class BaseEvasionAttackCreator: diff --git a/src/adv/evasion/composite_attack.py b/secml2/adv/evasion/composite_attack.py similarity index 90% rename from src/adv/evasion/composite_attack.py rename to secml2/adv/evasion/composite_attack.py index 0c24846..a7beb2f 100644 --- a/src/adv/evasion/composite_attack.py +++ b/secml2/adv/evasion/composite_attack.py @@ -2,15 +2,15 @@ import torch.nn from torch.nn import CrossEntropyLoss -from torch.optim import Adam, SGD +from torch.optim import Adam, SGD, Optimizer from torch.utils.data import DataLoader, TensorDataset -from src.adv.evasion.base_evasion_attack import BaseEvasionAttack -from src.manipulations.manipulation import Manipulation -from src.models.base_model import BaseModel -from src.optimization.constraints import Constraint -from src.optimization.gradient_processing import GradientProcessing -from src.optimization.initializer import Initializer +from secml2.adv.evasion.base_evasion_attack import BaseEvasionAttack +from secml2.manipulations.manipulation import Manipulation +from secml2.models.base_model import BaseModel +from secml2.optimization.constraints import Constraint +from secml2.optimization.gradient_processing import GradientProcessing +from secml2.optimization.initializer import Initializer CE_LOSS = "ce_loss" LOGITS_LOSS = "logits_loss" @@ -32,7 +32,7 @@ def __init__( num_steps: int, step_size: float, loss_function: Union[str, torch.nn.Module], - optimizer_cls: Union[str, Type[torch.nn.Module]], + optimizer_cls: Union[str, Type[Optimizer]], manipulation_function: Manipulation, domain_constraints: List[Constraint], perturbation_constraints: List[Type[Constraint]], diff --git a/src/adv/evasion/foolbox.py b/secml2/adv/evasion/foolbox.py similarity index 90% rename from src/adv/evasion/foolbox.py rename to secml2/adv/evasion/foolbox.py index faf6d68..889f11b 100644 --- a/src/adv/evasion/foolbox.py +++ b/secml2/adv/evasion/foolbox.py @@ -1,10 +1,10 @@ from typing import Optional -from src.adv.evasion.base_evasion_attack import BaseEvasionAttack +from secml2.adv.evasion.base_evasion_attack import BaseEvasionAttack from foolbox.attacks.base import Attack from torch.utils.data import DataLoader -from src.models.base_model import BaseModel -from src.models.pytorch.base_pytorch_nn import BasePytorchClassifier -from src.models.base_model import BaseModel +from secml2.models.base_model import BaseModel +from secml2.models.pytorch.base_pytorch_nn import BasePytorchClassifier +from secml2.models.base_model import BaseModel from foolbox.models.pytorch import PyTorchModel from foolbox.criteria import Misclassification, TargetedMisclassification import torch diff --git a/src/adv/evasion/perturbation_models.py b/secml2/adv/evasion/perturbation_models.py similarity index 100% rename from src/adv/evasion/perturbation_models.py rename to secml2/adv/evasion/perturbation_models.py diff --git a/src/adv/evasion/pgd.py b/secml2/adv/evasion/pgd.py similarity index 87% rename from src/adv/evasion/pgd.py rename to secml2/adv/evasion/pgd.py index 7e9be52..f7c24df 100644 --- a/src/adv/evasion/pgd.py +++ b/secml2/adv/evasion/pgd.py @@ -3,15 +3,15 @@ import torch from torch.optim import Adam -from src.adv.evasion.composite_attack import CompositeEvasionAttack, CE_LOSS, SGD -from src.manipulations.manipulation import AdditiveManipulation -from src.optimization.initializer import Initializer -from src.optimization.gradient_processing import LinearProjectionGradientProcessing -from src.adv.evasion.foolbox import BaseFoolboxEvasionAttack - -from src.adv.evasion.perturbation_models import PerturbationModels -from src.adv.backends import Backends -from src.adv.evasion.base_evasion_attack import ( +from secml2.adv.evasion.composite_attack import CompositeEvasionAttack, CE_LOSS, SGD +from secml2.manipulations.manipulation import AdditiveManipulation +from secml2.optimization.initializer import Initializer +from secml2.optimization.gradient_processing import LinearProjectionGradientProcessing +from secml2.adv.evasion.foolbox import BaseFoolboxEvasionAttack + +from secml2.adv.evasion.perturbation_models import PerturbationModels +from secml2.adv.backends import Backends +from secml2.adv.evasion.base_evasion_attack import ( BaseEvasionAttackCreator, ) @@ -21,7 +21,7 @@ LinfProjectedGradientDescentAttack, ) -from src.optimization.constraints import ( +from secml2.optimization.constraints import ( ClipConstraint, L1Constraint, L2Constraint, diff --git a/src/data/__init__.py b/secml2/data/__init__.py similarity index 100% rename from src/data/__init__.py rename to secml2/data/__init__.py diff --git a/src/data/sklearn_dataset.py b/secml2/data/sklearn_dataset.py similarity index 100% rename from src/data/sklearn_dataset.py rename to secml2/data/sklearn_dataset.py diff --git a/src/examples/mnist_example.py b/secml2/examples/mnist_example.py similarity index 93% rename from src/examples/mnist_example.py rename to secml2/examples/mnist_example.py index 8045532..c3136a3 100644 --- a/src/examples/mnist_example.py +++ b/secml2/examples/mnist_example.py @@ -2,12 +2,12 @@ import torch import torchvision.datasets from torch.utils.data import DataLoader, Subset -from src.adv.backends import Backends -from src.adv.evasion.pgd import PGD -from src.adv.evasion.perturbation_models import PerturbationModels +from secml2.adv.backends import Backends +from secml2.adv.evasion.pgd import PGD +from secml2.adv.evasion.perturbation_models import PerturbationModels -from src.metrics.classification import Accuracy -from src.models.pytorch.base_pytorch_nn import BasePytorchClassifier +from secml2.metrics.classification import Accuracy +from secml2.models.pytorch.base_pytorch_nn import BasePytorchClassifier from torch import nn diff --git a/src/examples/run_evasion_attack.py b/secml2/examples/run_evasion_attack.py similarity index 89% rename from src/examples/run_evasion_attack.py rename to secml2/examples/run_evasion_attack.py index b937a6a..7c43a80 100644 --- a/src/examples/run_evasion_attack.py +++ b/secml2/examples/run_evasion_attack.py @@ -1,12 +1,12 @@ import torch import torchvision.datasets from torch.utils.data import DataLoader, Subset -from src.adv.backends import Backends -from src.adv.evasion.pgd import PGD -from src.adv.evasion.perturbation_models import PerturbationModels +from secml2.adv.backends import Backends +from secml2.adv.evasion.pgd import PGD +from secml2.adv.evasion.perturbation_models import PerturbationModels -from src.metrics.classification import Accuracy -from src.models.pytorch.base_pytorch_nn import BasePytorchClassifier +from secml2.metrics.classification import Accuracy +from secml2.models.pytorch.base_pytorch_nn import BasePytorchClassifier from robustbench.utils import load_model diff --git a/src/examples/train_model.py b/secml2/examples/train_model.py similarity index 86% rename from src/examples/train_model.py rename to secml2/examples/train_model.py index 08650f3..c6615ad 100644 --- a/src/examples/train_model.py +++ b/secml2/examples/train_model.py @@ -3,9 +3,9 @@ from torch.optim import Adam from torch.utils.data import DataLoader -from src.metrics.classification import Accuracy -from src.models.pytorch.base_pytorch_nn import BasePytorchClassifier -from src.models.pytorch.base_pytorch_trainer import BasePyTorchTrainer +from secml2.metrics.classification import Accuracy +from secml2.models.pytorch.base_pytorch_nn import BasePytorchClassifier +from secml2.models.pytorch.base_pytorch_trainer import BasePyTorchTrainer class MNISTNet(torch.nn.Module): diff --git a/src/manipulations/__init__.py b/secml2/manipulations/__init__.py similarity index 100% rename from src/manipulations/__init__.py rename to secml2/manipulations/__init__.py diff --git a/src/manipulations/manipulation.py b/secml2/manipulations/manipulation.py similarity index 100% rename from src/manipulations/manipulation.py rename to secml2/manipulations/manipulation.py diff --git a/src/metrics/__init__.py b/secml2/metrics/__init__.py similarity index 100% rename from src/metrics/__init__.py rename to secml2/metrics/__init__.py diff --git a/src/metrics/classification.py b/secml2/metrics/classification.py similarity index 95% rename from src/metrics/classification.py rename to secml2/metrics/classification.py index 2e32254..b2d51fd 100644 --- a/src/metrics/classification.py +++ b/secml2/metrics/classification.py @@ -1,7 +1,7 @@ import torch from torch.utils.data import DataLoader -from src.models.base_model import BaseModel +from secml2.models.base_model import BaseModel def accuracy(y_pred: torch.Tensor, y_true: torch.Tensor) -> torch.Tensor: diff --git a/src/metrics/test/__init__.py b/secml2/metrics/test/__init__.py similarity index 100% rename from src/metrics/test/__init__.py rename to secml2/metrics/test/__init__.py diff --git a/src/models/__init__.py b/secml2/models/__init__.py similarity index 100% rename from src/models/__init__.py rename to secml2/models/__init__.py diff --git a/src/models/base_model.py b/secml2/models/base_model.py similarity index 88% rename from src/models/base_model.py rename to secml2/models/base_model.py index 7b78c46..4840be1 100644 --- a/src/models/base_model.py +++ b/secml2/models/base_model.py @@ -4,8 +4,10 @@ import torch from torch.utils.data import DataLoader -from src.models.data_processing.identity_data_processing import IdentityDataProcessing -from src.models.data_processing.data_processing import DataProcessing +from secml2.models.data_processing.identity_data_processing import ( + IdentityDataProcessing, +) +from secml2.models.data_processing.data_processing import DataProcessing class BaseModel(ABC): diff --git a/src/models/base_trainer.py b/secml2/models/base_trainer.py similarity index 100% rename from src/models/base_trainer.py rename to secml2/models/base_trainer.py diff --git a/src/models/data_processing/__init__.py b/secml2/models/data_processing/__init__.py similarity index 100% rename from src/models/data_processing/__init__.py rename to secml2/models/data_processing/__init__.py diff --git a/src/models/data_processing/data_processing.py b/secml2/models/data_processing/data_processing.py similarity index 100% rename from src/models/data_processing/data_processing.py rename to secml2/models/data_processing/data_processing.py diff --git a/src/models/data_processing/identity_data_processing.py b/secml2/models/data_processing/identity_data_processing.py similarity index 74% rename from src/models/data_processing/identity_data_processing.py rename to secml2/models/data_processing/identity_data_processing.py index f02ffd8..13452a6 100644 --- a/src/models/data_processing/identity_data_processing.py +++ b/secml2/models/data_processing/identity_data_processing.py @@ -1,6 +1,6 @@ import torch -from src.models.data_processing.data_processing import DataProcessing +from secml2.models.data_processing.data_processing import DataProcessing class IdentityDataProcessing(DataProcessing): diff --git a/src/models/data_processing/test/__init__.py b/secml2/models/data_processing/test/__init__.py similarity index 100% rename from src/models/data_processing/test/__init__.py rename to secml2/models/data_processing/test/__init__.py diff --git a/src/models/pytorch/__init__.py b/secml2/models/pytorch/__init__.py similarity index 100% rename from src/models/pytorch/__init__.py rename to secml2/models/pytorch/__init__.py diff --git a/src/models/pytorch/base_pytorch_nn.py b/secml2/models/pytorch/base_pytorch_nn.py similarity index 90% rename from src/models/pytorch/base_pytorch_nn.py rename to secml2/models/pytorch/base_pytorch_nn.py index eca9075..e542038 100644 --- a/src/models/pytorch/base_pytorch_nn.py +++ b/secml2/models/pytorch/base_pytorch_nn.py @@ -1,9 +1,9 @@ import torch from torch.utils.data import DataLoader -from src.models.base_model import BaseModel -from src.models.data_processing.data_processing import DataProcessing -from src.models.pytorch.base_pytorch_trainer import BasePyTorchTrainer +from secml2.models.base_model import BaseModel +from secml2.models.data_processing.data_processing import DataProcessing +from secml2.models.pytorch.base_pytorch_trainer import BasePyTorchTrainer class BasePytorchClassifier(BaseModel): diff --git a/src/models/pytorch/base_pytorch_trainer.py b/secml2/models/pytorch/base_pytorch_trainer.py similarity index 95% rename from src/models/pytorch/base_pytorch_trainer.py rename to secml2/models/pytorch/base_pytorch_trainer.py index af069cd..ad5aca5 100644 --- a/src/models/pytorch/base_pytorch_trainer.py +++ b/secml2/models/pytorch/base_pytorch_trainer.py @@ -2,7 +2,7 @@ from torch.optim.lr_scheduler import _LRScheduler # noqa from torch.utils.data import DataLoader -from src.models.base_trainer import BaseTrainer +from secml2.models.base_trainer import BaseTrainer class BasePyTorchTrainer(BaseTrainer): diff --git a/src/models/pytorch/test/__init__.py b/secml2/models/pytorch/test/__init__.py similarity index 100% rename from src/models/pytorch/test/__init__.py rename to secml2/models/pytorch/test/__init__.py diff --git a/src/models/pytorch/test/base_pytorch.py b/secml2/models/pytorch/test/base_pytorch.py similarity index 100% rename from src/models/pytorch/test/base_pytorch.py rename to secml2/models/pytorch/test/base_pytorch.py diff --git a/src/models/pytorch/test/test_pytorch_nn.py b/secml2/models/pytorch/test/test_pytorch_nn.py similarity index 76% rename from src/models/pytorch/test/test_pytorch_nn.py rename to secml2/models/pytorch/test/test_pytorch_nn.py index ba94e59..9800b7f 100644 --- a/src/models/pytorch/test/test_pytorch_nn.py +++ b/secml2/models/pytorch/test/test_pytorch_nn.py @@ -1,9 +1,9 @@ import torch from torch.optim import Adam -from src.models.pytorch.base_pytorch_nn import BasePytorchClassifier -from src.models.pytorch.base_pytorch_trainer import BasePyTorchTrainer -from src.models.pytorch.test.base_pytorch import BasePytorchTests +from secml2.models.pytorch.base_pytorch_nn import BasePytorchClassifier +from secml2.models.pytorch.base_pytorch_trainer import BasePyTorchTrainer +from secml2.models.pytorch.test.base_pytorch import BasePytorchTests class TestPytorchNN(BasePytorchTests): diff --git a/src/models/pytorch/test/test_pytorch_trainer.py b/secml2/models/pytorch/test/test_pytorch_trainer.py similarity index 83% rename from src/models/pytorch/test/test_pytorch_trainer.py rename to secml2/models/pytorch/test/test_pytorch_trainer.py index 7835e8d..a3f19b4 100644 --- a/src/models/pytorch/test/test_pytorch_trainer.py +++ b/secml2/models/pytorch/test/test_pytorch_trainer.py @@ -1,7 +1,7 @@ from torch.optim import Adam -from src.models.pytorch.base_pytorch_trainer import BasePyTorchTrainer -from src.models.pytorch.test.base_pytorch import BasePytorchTests +from secml2.models.pytorch.base_pytorch_trainer import BasePyTorchTrainer +from secml2.models.pytorch.test.base_pytorch import BasePytorchTests class TestPytorchTrainer(BasePytorchTests): diff --git a/src/models/sklearn/__init__.py b/secml2/models/sklearn/__init__.py similarity index 100% rename from src/models/sklearn/__init__.py rename to secml2/models/sklearn/__init__.py diff --git a/src/models/sklearn/base_sklearn_model.py b/secml2/models/sklearn/base_sklearn_model.py similarity index 92% rename from src/models/sklearn/base_sklearn_model.py rename to secml2/models/sklearn/base_sklearn_model.py index 7e7830f..a5a3351 100644 --- a/src/models/sklearn/base_sklearn_model.py +++ b/secml2/models/sklearn/base_sklearn_model.py @@ -5,9 +5,9 @@ import torch from torch.utils.data import DataLoader -from src.data.sklearn_dataset import SklearnDataset -from src.models.base_model import BaseModel -from src.models.data_processing.data_processing import DataProcessing +from secml2.data.sklearn_dataset import SklearnDataset +from secml2.models.base_model import BaseModel +from secml2.models.data_processing.data_processing import DataProcessing class BaseSklearnModel(BaseModel): diff --git a/src/models/sklearn/test/__init__.py b/secml2/models/sklearn/test/__init__.py similarity index 100% rename from src/models/sklearn/test/__init__.py rename to secml2/models/sklearn/test/__init__.py diff --git a/src/models/tensorflow/__init__.py b/secml2/models/tensorflow/__init__.py similarity index 100% rename from src/models/tensorflow/__init__.py rename to secml2/models/tensorflow/__init__.py diff --git a/src/models/tensorflow/base_tensorflow_nn.py b/secml2/models/tensorflow/base_tensorflow_nn.py similarity index 85% rename from src/models/tensorflow/base_tensorflow_nn.py rename to secml2/models/tensorflow/base_tensorflow_nn.py index 87f67c5..0a41822 100644 --- a/src/models/tensorflow/base_tensorflow_nn.py +++ b/secml2/models/tensorflow/base_tensorflow_nn.py @@ -1,9 +1,9 @@ import tensorflow as tf import torch -from src.models.base_model import BaseModel -from src.models.data_processing.data_processing import DataProcessing -from src.models.tensorflow.base_tensorflow_trainer import BaseTensorflowTrainer +from secml2.models.base_model import BaseModel +from secml2.models.data_processing.data_processing import DataProcessing +from secml2.models.tensorflow.base_tensorflow_trainer import BaseTensorflowTrainer class BaseTensorflowClassifier(BaseModel): diff --git a/src/models/tensorflow/base_tensorflow_trainer.py b/secml2/models/tensorflow/base_tensorflow_trainer.py similarity index 72% rename from src/models/tensorflow/base_tensorflow_trainer.py rename to secml2/models/tensorflow/base_tensorflow_trainer.py index 4bdf65f..ff484ac 100644 --- a/src/models/tensorflow/base_tensorflow_trainer.py +++ b/secml2/models/tensorflow/base_tensorflow_trainer.py @@ -1,4 +1,4 @@ -from src.models.base_trainer import BaseTrainer +from secml2.models.base_trainer import BaseTrainer class BaseTensorflowTrainer(BaseTrainer): diff --git a/src/models/test/__init__.py b/secml2/models/test/__init__.py similarity index 100% rename from src/models/test/__init__.py rename to secml2/models/test/__init__.py diff --git a/src/optimization/__init__.py b/secml2/optimization/__init__.py similarity index 100% rename from src/optimization/__init__.py rename to secml2/optimization/__init__.py diff --git a/src/optimization/constraints.py b/secml2/optimization/constraints.py similarity index 100% rename from src/optimization/constraints.py rename to secml2/optimization/constraints.py diff --git a/src/optimization/gradient_processing.py b/secml2/optimization/gradient_processing.py similarity index 93% rename from src/optimization/gradient_processing.py rename to secml2/optimization/gradient_processing.py index af42932..b77f0df 100644 --- a/src/optimization/gradient_processing.py +++ b/secml2/optimization/gradient_processing.py @@ -3,7 +3,7 @@ import torch.linalg from torch.nn.functional import normalize -from src.adv.evasion.perturbation_models import PerturbationModels +from secml2.adv.evasion.perturbation_models import PerturbationModels class GradientProcessing: diff --git a/src/optimization/initializer.py b/secml2/optimization/initializer.py similarity index 87% rename from src/optimization/initializer.py rename to secml2/optimization/initializer.py index aff9094..9fff9b3 100644 --- a/src/optimization/initializer.py +++ b/secml2/optimization/initializer.py @@ -1,6 +1,6 @@ import torch -from src.adv.evasion.perturbation_models import PerturbationModels +from secml2.adv.evasion.perturbation_models import PerturbationModels class Initializer: