Пример #1
0
  def __init__(self, scope, nb_classes, nb_filters, **kwargs):
    del kwargs
    Model.__init__(self, scope, nb_classes, locals())
    self.nb_filters = nb_filters

    self.fprop(self.make_input_placeholder())

    self.params = self.get_params()
Пример #2
0
    def test_fprop(self):
        # Define empty model
        model = Model('model', 10, {})
        x = []

        # Exception is thrown when `fprop` not implemented
        with self.assertRaises(Exception) as context:
            model.fprop(x)
        self.assertTrue(context.exception)
Пример #3
0
    def __init__(self, scope, nb_classes, nb_filters, **kwargs):
        del kwargs
        Model.__init__(self, scope, nb_classes, locals())
        self.nb_filters = nb_filters

        # Do a dummy run of fprop to make sure the variables are created from
        # the start
        self.fprop(tf.placeholder(tf.float32, [128, 28, 28, 1]))
        # Put a reference to the params in self so that the params get pickled
        self.params = self.get_params()
Пример #4
0
 def __init__(self, nb_classes=10):
     # NOTE: for compatibility with Madry Lab downloadable checkpoints,
     # we cannot use scopes, give these variables names, etc.
     self.W_conv1 = self._weight_variable([5, 5, 1, 32])
     self.b_conv1 = self._bias_variable([32])
     self.W_conv2 = self._weight_variable([5, 5, 32, 64])
     self.b_conv2 = self._bias_variable([64])
     self.W_fc1 = self._weight_variable([7 * 7 * 64, 1024])
     self.b_fc1 = self._bias_variable([1024])
     self.W_fc2 = self._weight_variable([1024, nb_classes])
     self.b_fc2 = self._bias_variable([nb_classes])
     Model.__init__(self, '', nb_classes, {})
     self.dataset_factory = Factory(MNIST, {"center": False})
Пример #5
0
 def test_cache(self):
   """test_cache: Test that _CorrectFactory can be cached"""
   model = Model()
   factory_1 = _CorrectFactory(model)
   factory_2 = _CorrectFactory(model)
   cache = {}
   cache[factory_1] = True
   self.assertTrue(factory_2 in cache)
Пример #6
0
    def __init__(self,
                 nb_classes=10,
                 nb_filters=64,
                 dummy_input=tf.zeros((32, 28, 28, 1))):
        Model.__init__(self, nb_classes=nb_classes)

        # Parametes
        # number of filters, number of classes.
        self.nb_filters = nb_filters
        self.nb_classes = nb_classes

        # Lists for layers attributes.
        # layer names , layers, layer activations
        self.layer_names = [
            'input', 'conv_1', 'conv_2', 'conv_3', 'flatten', 'logits'
        ]
        self.layers = {}
        self.layer_acts = {}

        # layer definitions
        self.layers['conv_1'] = tf.layers.Conv2D(filters=self.nb_filters,
                                                 kernel_size=8,
                                                 strides=2,
                                                 padding='same',
                                                 activation=tf.nn.relu)
        self.layers['conv_2'] = tf.layers.Conv2D(filters=self.nb_filters * 2,
                                                 kernel_size=6,
                                                 strides=2,
                                                 padding='valid',
                                                 activation=tf.nn.relu)
        self.layers['conv_3'] = tf.layers.Conv2D(filters=self.nb_filters * 2,
                                                 kernel_size=5,
                                                 strides=1,
                                                 padding='valid',
                                                 activation=tf.nn.relu)
        self.layers['flatten'] = tf.layers.Flatten()
        self.layers['logits'] = tf.layers.Dense(self.nb_classes,
                                                activation=None)

        # Dummy fprop to activate the network.
        self.fprop(dummy_input)
Пример #7
0
  def test_sess_generate_np(self):
    model = Model('model', 10, {})

    class DummyAttack(Attack):
      def generate(self, x, **kwargs):
        return x

    # Test that generate_np is NOT permitted without a session.
    # The session still needs to be created prior to running the attack.
    # TODO: does anyone know why we need to make an unused session and put it in a with statement?
    with tf.Session():
      attack = DummyAttack(model, sess=None)
      with self.assertRaises(Exception) as context:
        attack.generate_np(0.)
      self.assertTrue(context.exception)
Пример #8
0
 def __init__(self, scope='simple', nb_classes=2, **kwargs):
     del kwargs
     Model.__init__(self, scope, nb_classes, locals())
Пример #9
0
 def __init__(self, scope, nb_classes=1000, **kwargs):
     del kwargs
     Model.__init__(self, scope, nb_classes, locals())
Пример #10
0
 def __init__(self, f):
     dummy_model = Model()
     super(Wrapper, self).__init__(model=dummy_model)
     self.f = f
Пример #11
0
 def __init__(self, scope='dummy_model', nb_classes=10, **kwargs):
   del kwargs
   Model.__init__(self, scope, nb_classes, locals())
Пример #12
0
  def test_parse(self):
    sess = tf.Session()

    test_attack = Attack(Model('model', 10, {}), sess=sess)
    self.assertTrue(test_attack.parse_params({}))
Пример #13
0
 def test_sess(self):
   # Test that it is permitted to provide no session.
   # The session still needs to be created prior to running the attack.
   # TODO: does anyone know why we need to make an unused session and put it in a with statement?
   with tf.Session():
     Attack(Model('model', 10, {}), sess=None)
Пример #14
0
 def __init__(self, scope, nb_classes, nb_filters=200, **kwargs):
     del kwargs
     Model.__init__(self, scope, nb_classes, locals())
     self.nb_filters = nb_filters