Skip to content

Instantly share code, notes, and snippets.

View maurapintor's full-sized avatar

Maura Pintor maurapintor

View GitHub Profile
@maurapintor
maurapintor / plot_settings.py
Created May 2, 2022 12:53
The settings that I like for figures :D
import seaborn as sns
import matplotlib.pyplot as plt
sns.set_style('whitegrid')
plt.rc('axes', titlesize=18)
plt.rc('axes', labelsize=14)
plt.rc('xtick', labelsize=13)
plt.rc('ytick', labelsize=13)
plt.rc('legend', fontsize=13)
plt.rc('font', size=13)
plt.rc('text', usetex=True)
@maurapintor
maurapintor / pytorch_model_tracker.py
Last active March 22, 2022 13:06
Track queries on PyTorch Model
import torch
class PyTorchModelTracker:
def __init__(self, model):
self._func_counter = None
self._tracked_x = None
self._model = model
self.reset()
@maurapintor
maurapintor / plot_debug.py
Created November 25, 2021 16:16
Plot debugging curves with secml
import matplotlib.pyplot as plt
from secml.adv.attacks import CFoolboxPGD
from secml.array import CArray
from secml.core.constants import inf
from secml.data.loader import CDataLoaderMNIST
from secml.ml import CNormalizerMinMax
from secml.ml.peval.metrics import CMetric
from secml.model_zoo import load_model
@maurapintor
maurapintor / ImageNet images to h5py
Last active October 25, 2021 12:31
Loads the ImageNet dataset with torchvision, and stores a subset of the samples and labels on a target hdf5 file.
import h5py as h5py
import numpy as np
import torch.utils.data
from torchvision import datasets, transforms
source_path = 'path-to-the-extracted-imagenet-dataset'
destination_path = 'destination-hdf5-file'
# place here your own transforms
transform = transforms.Compose([