def build(self): temp = 100 network1 = DistillationWrapper(resnet.ResNet18().to(self.device), temp) self.target_instance = DefenseInstance(model=network1) network2 = DistillationWrapper( ConvMedBig(device=self.device, dataset='cifar10', width1=4, width2=4, width3=4, linear_size=200, input_channel=3, with_normalization=True), temp) instance = DefenseInstance(model=network2, detector=None) return instance
def build(self): import zoo.saved_instances.Odds.cifar_model as cifar_model import zoo.saved_instances.Odds.robustify as robustify classifier = cifar_model.cifar10(128, pretrained=True, map_location=None, trained_adv=False).to(self.device) detector = robustify.OddsAreOdd(classifier=classifier) instance = DefenseInstance(model=classifier, detector=detector) return instance
def build(self): Jpegdefense = JpegCompression((0, 1), 30) RSdefense = ReverseSigmoid() network1 = SimpleNet(in_ch=1, out_ch=10) classifier = DAGModule([Jpegdefense, network1, RSdefense], device=self.device) instance = DefenseInstance(model=classifier, detector=None) return instance
def build(self): Jpegdefense = JpegCompression((0, 1), COMPRESSION_QUALITY) RSdefense = ReverseSigmoid() classifier = DAGModule([Jpegdefense, self.network, RSdefense], device=self.device) instance = DefenseInstance(model=classifier, detector=None) return instance
def build(self): from zoo.saved_instances.TurningWeakness.vgg19 import vgg19, TurningWeaknessDetector classifier = vgg19() classifier.features = torch.nn.DataParallel(classifier.features) classifier.to(self.device) detector = TurningWeaknessDetector(classifier=classifier) instance = DefenseInstance(model=classifier, detector=detector) return instance
def build(self): network1 = SimpleNet1(in_ch=1, out_ch=10) network2 = SimpleNet2(in_ch=1, out_ch=10) detector1 = SimpleDetector(network1) module1 = DAGModule([network1, network2], dependency=[[-1], [0]], output=[1], device=self.device) module2 = DAGModule([network1, detector1], dependency=[[-1], [0]], output=[1], device=self.device) instance = DefenseInstance(model=module1, detector=module2) return instance
def build(self): ITdefense = InputTransformation(degrees=(-30, 30)) # Varmin = VarianceMinimization(prob=0.3, norm=2) # Jpegdefense = JpegCompression((0, 1), 30) # RSdefense = ReverseSigmoid() network1 = SimpleNet(in_ch=1, out_ch=10) classifier = DAGModule([ITdefense, network1], device=self.device) instance = DefenseInstance(model=classifier, detector=None) return instance
def build(self): from zoo.saved_instances.JEM.CCF_model import CCF # nsteps = 10 classifier = CCF(28, 10, None, dropout_rate=0, n_classes=10).to(self.device) # classifier = WrapperModel(f, nsteps).to(self.device) # classifier = gradient_attack_wrapper(f) # classifier = f.to(self.device) # classifier = nn.DataParallel(classifier).to(self.device) instance = DefenseInstance(model=classifier, detector=None) return instance
def build(self): from zoo.saved_instances.JEM.CCF_model import CCF # nsteps = 10 ITdefense = InputTransformation(degrees=(-ROTATION_DEGREES, ROTATION_DEGREES)) classifier = DAGModule([ITdefense, self.network], device=self.device) # classifier = WrapperModel(f, nsteps).to(self.device) # classifier = gradient_attack_wrapper(f) # classifier = f.to(self.device) # classifier = nn.DataParallel(classifier).to(self.device) instance = DefenseInstance(model=classifier, detector=None) return instance
def build(self): from zoo.saved_instances.JEM.CCF_model import CCF Jpegdefense = JpegCompression((0, 1), COMPRESSION_QUALITY) RSdefense = ReverseSigmoid() classifier = DAGModule([Jpegdefense, self.network, RSdefense], device=self.device) # classifier = WrapperModel(f, nsteps).to(self.device) # classifier = gradient_attack_wrapper(f) # classifier = f.to(self.device) # classifier = nn.DataParallel(classifier).to(self.device) instance = DefenseInstance(model=classifier, detector=None) return instance
def build(self): network1 = ConvMedBig(device=self.device, dataset='cifar10', width1=4, width2=4, width3=4, linear_size=200, input_channel=3, with_normalization=True) classifier = DAGModule([network1], device=self.device) instance = DefenseInstance(model=classifier, detector=None) return instance
def build(self): TEdefense = ThermometerEncoding((0, 1), num_space=10) network1 = ConvMedBig(device=self.device, dataset='cifar10', width1=4, width2=4, width3=2, linear_size=200, input_channel=30, with_normalization=False) classifier = DAGModule([TEdefense, network1], device=self.device) instance = DefenseInstance(model=classifier, detector=None) return instance
def build(self): import zoo.saved_instances.CCAT.common.state as state from zoo.saved_instances.CCAT.detector import CCATDetector import sys import os dir_path = os.path.dirname(os.path.realpath(__file__)) sys.path.insert(1, dir_path + '/saved_instances/CCAT') import zoo.saved_instances.CCAT.models as models model_file = osp.join(self.path, self.name, "classifier.model") state = state.State.load(model_file) classifier = state.model.to(self.device) detector = CCATDetector(classifier, 0.4) instance = DefenseInstance(model=classifier, detector=detector) # , detector=detector) return instance
def build(self): Jpegdefense = JpegCompression((0, 1), 60) RSdefense = ReverseSigmoid() network1 = ConvMedBig(device=self.device, dataset='cifar10', width1=4, width2=4, width3=4, linear_size=200, input_channel=3, with_normalization=True) classifier = DAGModule([Jpegdefense, network1, RSdefense], device=self.device) instance = DefenseInstance(model=classifier, detector=None) return instance
def build(self): from zoo.wideresnet import WideResNetNormalize from zoo.saved_instances.FeatureScatter.attack_methods import Attack_FeaScatter config_feature_scatter = { 'train': True, 'epsilon': 8.0 / 255 * 2, 'num_steps': 1, 'step_size': 8.0 / 255 * 2, 'random_start': True, 'ls_factor': 0.5, } basic_net = WideResNetNormalize(28, 10, widen_factor=10, dropRate=0.0) net = Attack_FeaScatter(basic_net, config_feature_scatter) net = torch.nn.DataParallel(net) instance = DefenseInstance(model=net, detector=None) return instance
def build(self): ITdefense = InputTransformation(degrees=(-30, 30)) TEdefense = ThermometerEncoding((0, 1), num_space=10) Jpegdefense = JpegCompression((0, 1), 30) RSdefense = ReverseSigmoid() network1 = SimpleNet(in_ch=1, out_ch=10) network2 = SimpleNet(in_ch=10, out_ch=10) network3 = SimpleNet(in_ch=1, out_ch=10) module1 = DAGModule([TEdefense, network2], device=self.device) module2 = DAGModule([Jpegdefense, network1, RSdefense], device=self.device) module3 = DAGModule([ITdefense, network3], device=self.device) losscomb = LossCombine() classifier = DAGModule([module1, module2, module3, losscomb], dependency=[[-1], [-1], [-1], [0, 1, 2]], output=[3], device=self.device) instance = DefenseInstance(model=classifier) return instance
class Model8(CIFARInstance): def __init__(self, load=False, device='cuda'): name = 'model8' self.target_instance = None super(Model8, self).__init__(name, load, device) def build(self): temp = 100 network1 = DistillationWrapper(resnet.ResNet18().to(self.device), temp) self.target_instance = DefenseInstance(model=network1) network2 = DistillationWrapper( ConvMedBig(device=self.device, dataset='cifar10', width1=4, width2=4, width3=4, linear_size=200, input_channel=3, with_normalization=True), temp) instance = DefenseInstance(model=network2, detector=None) return instance def train(self, train_loader, eps, save=True): train_loss = nn.CrossEntropyLoss() optimizer = optim.Adam( self.target_instance.model.train_model.parameters(), lr=0.001) nb_epoches = 25 attack = None kwargs = {} self.target_instance.train() self.target_instance.advfit(train_loader, loss_fcn=train_loss, optimizer=optimizer, epsilon=eps, attack=attack, nb_epochs=nb_epoches, ratio=0.6, **kwargs) self.target_instance.eval() nb_epoches = 25 optimizer = optim.Adam(self.instance.model.train_model.parameters(), lr=0.001) defensive_distillation = DefensiveDistillation(self.target_instance) defensive_distillation.fit(self.instance, loader=train_loader, optimizer=optimizer, nb_epochs=nb_epoches, temp=5) if save: self._save() return
def build(self): ITdefense = InputTransformation(degrees=(-30, 30)) TEdefense = ThermometerEncoding((0, 1), num_space=10) Jpegdefense = JpegCompression((0, 1), 30) RSdefense = ReverseSigmoid() network1 = ConvMedBig(device=self.device, dataset='cifar10', width1=4, width2=4, width3=4, linear_size=200, input_channel=3, with_normalization=True) network2 = ConvMedBig(device=self.device, dataset='cifar10', width1=4, width2=4, width3=2, linear_size=200, input_channel=30, with_normalization=False) network3 = ConvMedBig(device=self.device, dataset='cifar10', width1=4, width2=4, width3=4, linear_size=200, input_channel=3, with_normalization=True) module1 = DAGModule([TEdefense, network2], device=self.device) module2 = DAGModule([Jpegdefense, network1, RSdefense], device=self.device) module3 = DAGModule([ITdefense, network3], device=self.device) losscomb = LossCombine() classifier = DAGModule([module1, module2, module3, losscomb], dependency=[[-1], [-1], [-1], [0, 1, 2]], output=[3], device=self.device) instance = DefenseInstance(model=classifier) return instance
def build(self): network = ConvMedBig(device=self.device, dataset='cifar10', width1=4, width2=4, width3=4, linear_size=200, input_channel=3, with_normalization=True) network1 = ConvMedBig1(network) network2 = ConvMedBig2(network) detector1 = SimpleDetector(network1, 200) module1 = DAGModule([network1, network2], dependency=[[-1], [0]], output=[1], device=self.device) module2 = DAGModule([network1, detector1], dependency=[[-1], [0]], output=[1], device=self.device) classifier = module1 instance = DefenseInstance(model=classifier, detector=module2) # return instance return instance
def build(self): TEdefense = ThermometerEncoding((0, 1), num_space=10) network1 = SimpleNet(in_ch=10, out_ch=10) classifier = DAGModule([TEdefense, network1], device=self.device) instance = DefenseInstance(model=classifier, detector=None) return instance
def build(self): network1 = SimpleNet(in_ch=1, out_ch=10) classifier = DAGModule([network1], device=self.device) instance = DefenseInstance(model=classifier, detector=None) return instance
def build(self): from zoo.saved_instances.kWTA_0p1_adv import resnet classifier = resnet.SparseResNet18(sparsities=[0.1,0.1,0.1,0.1], sparse_func='vol').to(self.device) instance = DefenseInstance(model=classifier, detector=None) return instance
def build(self): import zoo.saved_instances.EnResNet.enresnet_wideresnet as EWRes classifier = EWRes.WideResNet(noise_coef=0.0).cuda() instance = DefenseInstance(model=classifier, detector=None) return instance
def build(self): network = resnet.SparseResNet18(sparsities=[0.1, 0.1, 0.1, 0.1], sparse_func='reg').to(self.device) classifier = DAGModule([network], device=self.device) instance = DefenseInstance(model=classifier, detector=None) return instance
def build(self): model = load_model(model_name=self.name, norm='Linf') instance = DefenseInstance(model=model.to(self.device), detector=None) return instance
def build(self): ITdefense = InputTransformation(degrees=(-ROTATION_DEGREES, ROTATION_DEGREES)) classifier = DAGModule([ITdefense, self.network], device=self.device) instance = DefenseInstance(model=classifier, detector=None) return instance
def build(self): from zoo.wideresnet import WideResNet classifier = WideResNet(28, 10, widen_factor=10, dropRate=0.0) classifier = nn.DataParallel(classifier).cuda() instance = DefenseInstance(model=classifier, detector=None) return instance