Skip to content

Commit

Permalink
(#3) Defense: Add Cifar10 with Noise and Sql processing
Browse files Browse the repository at this point in the history
  • Loading branch information
betarixm committed May 26, 2022
1 parent 3fac55c commit 47ba5e2
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/utils/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typings.dataset import NumpyDataset

import tensorflow as tf
import numpy as np

keras = tf.keras

Expand Down Expand Up @@ -64,6 +65,26 @@ def postprocess(
return (x_train, y_train), (x_test, y_test)


class NoisySlqCifar10(ImageDataset, SlqMixin):
def __init__(self):
super().__init__(keras.datasets.cifar10)

def postprocess(
self, train: NumpyDataset, test: NumpyDataset
) -> Tuple[NumpyDataset, NumpyDataset]:
def noisy(ds: np.array):
noise = 0.1 * np.random.normal(size=np.shape(ds))
return np.clip(ds + noise, 0.0, 1.0)

(x_train, y_train), (x_test, y_test) = train, test

(x_train, y_train), (x_test, y_test) = SlqMixin.process(
(noisy(x_train), y_train), (noisy(x_test), y_test)
)

return (x_train, y_train), (x_test, y_test)


class IdemCifar10(ImageDataset, IdemMixin):
def __init__(self):
super().__init__(keras.datasets.cifar10)
Expand Down

0 comments on commit 47ba5e2

Please sign in to comment.