Skip to content

feat: save and reuse trained shadow models #357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Changes:
* Add example running attacks with only csv probabilities supplied ([#353](https://github.com/AI-SDC/SACRO-ML/pull/353))
* Add PDF report generation for structural attacks ([#355](https://github.com/AI-SDC/SACRO-ML/pull/355))
* Save and reuse trained shadow models ([#357](https://github.com/AI-SDC/SACRO-ML/pull/357))

## Version 1.4.0 (Jul 4, 2025)

Expand Down
12 changes: 4 additions & 8 deletions sacroml/attacks/attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from __future__ import annotations

import importlib
import inspect
import logging
import os
Expand Down Expand Up @@ -39,6 +38,10 @@ def __init__(self, output_dir: str = "outputs", write_report: bool = True) -> No
if not os.path.exists(self.output_dir):
os.makedirs(self.output_dir)

# Create folder for saving trained shadow models
self.shadow_path: str = os.path.normpath(f"{self.output_dir}/shadow_models")
os.makedirs(self.shadow_path, exist_ok=True)

@classmethod
@abstractmethod
def attackable(cls, target: Target) -> bool:
Expand Down Expand Up @@ -123,10 +126,3 @@ def get_params(self) -> dict:
for key in self._get_param_names():
out[key] = getattr(self, key)
return out


def get_class_by_name(class_path: str):
"""Return a class given its name."""
module_path, class_name = class_path.rsplit(".", 1)
module = importlib.import_module(module_path)
return getattr(module, class_name)
Loading