def __init__(self): Model.__init__(self) from keras.applications.vgg16 import VGG16, preprocess_input, decode_predictions self.keras_model = VGG16(weights='imagenet') self.model = KerasModelWrapper(self.keras_model) self.preprocess_input = preprocess_input self.decode_predictions = decode_predictions
def __init__(self, scope, nb_classes, **kwargs): Model.__init__(self, scope, nb_classes, locals()) self.mode = kwargs['mode'] self.image_height, self.image_width, self.image_channel = 60, 180, 1 self.nb_classes = nb_classes self.out_channels = 64 self.cnn_count = 4 self.batch_size = 40 self.num_hidden = 128 self.output_keep_prob = 0.8 self.initial_learning_rate = 1e-3 self.decay_rate = 0.98 self.decay_steps = 10000 self.beta1 = 0.9 self.beta2 = 0.999 self.leakiness = 0.01 del kwargs # image self.inputs = tf.placeholder( tf.float32, [None, self.image_height, self.image_width, self.image_channel]) # SparseTensor required by ctc_loss op self.labels = tf.sparse_placeholder(tf.int32) # 1d array of size [batch_size] # self.seq_len = tf.placeholder(tf.int32, [None]) # l2 self._extra_train_ops = []
def __init__(self, img_in, nb_classes, scope, noisy=False, reuse=False, concat_softmax=False, **kwargs): del kwargs self.scope = scope self.num_actions = nb_classes self.noisy = noisy #self.reuse = reuse self.reuse = tf.AUTO_REUSE self.concat_softmax = concat_softmax #self.img_in = img_in Model.__init__(self, scope, nb_classes, locals()) #self.fprop(tf.placeholder(tf.float32, [128, 28, 28, 1])) #self.fprop (img_in) #self.needs_dummy_fprop = True self.fprop(img_in) train_vars = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES, scope=self.scope + "/convnet") train_vars += tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES, scope=self.scope + "/action_value") self.params = train_vars
def __init__(self, scope, nb_classes, session= tf.Session(), istrain=False, nb_filters=200, **kwargs): del kwargs self.session = session with session.as_default(): Model.__init__(self, scope, nb_classes, locals()) self.nb_filters = nb_filters #self.session.run(tf.global_variables_initializer()) #self.session.run(tf.initialize_all_variables()) self.c1 = tf.Variable(tf.truncated_normal(shape=[3,3,3,32], stddev=0.1)) self.b1 = tf.Variable(tf.constant(1.0, shape=[32, 48,48])) self.c2 = tf.Variable(tf.truncated_normal(shape=[3,3,32,64], stddev=0.1)) self.b2 = tf.Variable(tf.constant(1.0, shape=[64,24,24])) self.c3 = tf.Variable(tf.truncated_normal(shape=[2,2,64,128], stddev=0.1)) self.b3 = tf.Variable(tf.constant(1.0, shape=[128,12,12])) self.w1 = tf.Variable(tf.truncated_normal(shape=[6*6*128, 2048], stddev=0.1)) self.b4 = tf.Variable(tf.constant(0.0, shape=[2048])) self.w2 = tf.Variable(tf.truncated_normal(shape=[2048, 1024], stddev=0.1)) self.b5 = tf.Variable(tf.constant(0.0, shape=[1024])) self.w3 = tf.Variable(tf.truncated_normal(shape=[1024,43], stddev=0.1)) self.b6 = tf.Variable(tf.constant(0.0, shape=[43])) self.istrain = istrain
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.compat.v1.layers.Conv2D(filters=self.nb_filters, kernel_size=8, strides=2, padding='same', activation=tf.nn.relu) self.layers['conv_2'] = tf.compat.v1.layers.Conv2D(filters=self.nb_filters * 2, kernel_size=6, strides=2, padding='valid', activation=tf.nn.relu) self.layers['conv_3'] = tf.compat.v1.layers.Conv2D(filters=self.nb_filters * 2, kernel_size=5, strides=1, padding='valid', activation=tf.nn.relu) self.layers['flatten'] = tf.compat.v1.layers.Flatten() self.layers['logits'] = tf.compat.v1.layers.Dense(self.nb_classes, activation=None) # Dummy fprop to activate the network. self.fprop(dummy_input)
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(tf.placeholder(tf.float32, [128, 64, 64, 1])) # self.params = self.get_params() self.sess = None self.load_model()
def __init__(self, scope, nb_classes, nb_filters, **kwargs): self.train_phase = kwargs['train_phase'] self.keep_prob = kwargs['keep_prob'] del kwargs Model.__init__(self, scope, nb_classes, locals()) self.nb_filters = nb_filters self.fprop(tf.placeholder(tf.float32, [10, 32, 256, 1])) self.params = self.get_params()
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()
def __init__(self, scope, nb_classes, **kwargs): del kwargs Model.__init__(self, scope, nb_classes, locals()) # Do a dummy run of fprop to make sure the variables are created from # the start self.fprop(tf.placeholder(tf.float32, [128, 32, 32, 3])) # Put a reference to the params in self so that the params get pickled self.params = self.get_params()
def __init__(self, scope, **kwargs): del kwargs Model.__init__(self, scope, locals()) #self.n_fcc = n_fcc self.latent_dim = 20 #self.batch_size= batch_size # Do a dummy run of fprop to make sure the variables are created from # the start self.fprop(tf.placeholder(tf.float32, shape = (90, 32, 32, 3)))
def __init__(self, scope, nb_classes, n, input_shape, **kwargs): del kwargs Model.__init__(self, scope, nb_classes, locals()) self.n = n self.net = OrderedDict() # Do a dummy run of fprop to create the variables from the start self.fprop(tf.placeholder(tf.float32, [32] + input_shape)) # Put a reference to the params in self so that the params get pickled self.params = self.get_params()
def __init__(self, scope, **kwargs): del kwargs Model.__init__(self, scope, locals()) self.n_units = 100 # Do a dummy run of fprop to make sure the variables are created from # the start self.fprop(tf.placeholder(tf.float32, shape=(128, 28, 28, 1))) #self.fprop(tf.placeholder(tf.float32, shape = (128, 100, 1))) # Put a reference to the params in self so that the params get pickled self.params = self.get_params()
def __init__(self, scope, nb_classes, input_shape, **kwargs): del kwargs Model.__init__(self, scope, nb_classes, locals()) self.input_shape = input_shape # Do a dummy run of fprop to create the variables from the start self.is_training = False self.fprop(tf.placeholder(tf.float32, [100] + input_shape)) # Put a reference to the params in self so that the params get pickled self.params = self.get_params()
def __init__(self, scope, nb_classes, hparams, **kwargs): del kwargs Model.__init__(self, scope, nb_classes, locals()) self.nb_classes = nb_classes self.dataset = hparams['dataset'] self.secret_seed = hparams['secret_seed'] if self.dataset == 'mnist': self.fprop(tf.placeholder(tf.float32, [128, 28, 28, 1])) elif self.dataset == 'cifar' or self.dataset == 'cifar10': self.fprop(tf.placeholder(tf.float32, [128, 32, 32, 3]))
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, {})
def __init__(self, scope, nb_classes, num_dims, **kwargs): del kwargs Model.__init__(self, scope, nb_classes, locals()) self.nb_filters = 64 self.num_neurons = num_dims * 4 self.num_dims = num_dims # Do a dummy run of fprop to make sure the variables are created from # the start self.fprop(tf.placeholder(tf.float32, [32, 1, 1, self.num_dims])) # Put a reference to the params in self so that the params get pickled self.params = self.get_params()
def __init__(self, scope, nb_classes, nb_filters, input_shape, **kwargs): del kwargs Model.__init__(self, scope, nb_classes, locals()) self.nb_filters = nb_filters self.input_shape = input_shape # Do a dummy run of fprop to create the variables from the start self.fprop(tf.placeholder(tf.float32, [32] + input_shape)) # Put a reference to the params in self so that the params get pickled self.params = self.get_params() self.d1 = tf.layers.Dense(128, activation='relu') self.d2 = tf.layers.Dense(2, activation='softmax')
def __init__(self, scope, nb_classes, nb_filters, input_shape, **kwargs): del kwargs Model.__init__(self, scope, nb_classes, locals()) self.nb_filters = nb_filters self.input_shape = input_shape # [32, 32, 3] self.dummpy_input = tf.placeholder(tf.float32, [FLAGS.batch_size] + input_shape) # Do a dummy run of fprop to create the variables from the start # BATCH_SIZE, img_rows, img_cols, nchannels self.fprop(self.dummpy_input) # Put a reference to the params in self so that the params get pickled self.params = self.get_params()
def __init__(self, scope, nb_classes, nb_filters, weights, **kwargs): del kwargs Model.__init__(self, scope, nb_classes, locals()) self.nb_filters = 32 self.weights = weights self.layer_info = np_weights(self.weights) print(self.layer_info[0][0].shape, self.layer_info[0][1].shape) print(self.layer_info[1][0].shape, self.layer_info[1][1].shape) print(self.layer_info[2][0].shape, self.layer_info[2][1].shape) # Do a dummy run of fprop to make sure the variables are created from # the start self.fprop(tf.placeholder(tf.float32, [1, 28, 28, 1])) # Put a reference to the params in self so that the params get pickled self.params = self.get_params()
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)
def __init__(self, scope, nb_classes, nb_filters, **kwargs): # 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() # print(self.params) del kwargs Model.__init__(self, scope, nb_classes, locals()) self.nb_filters = nb_filters self.nb_classes = nb_classes self.s = scope print("hello") x = tf.placeholder(tf.float32, shape=(None, 28, 28, 1)) # Do a dummy run of fprop to make sure the variables are created from # the start self.fprop(x) # Put areference to the params in self so that the params get pickled self.params = self.get_params()
def __init__(self, scope, img_size, nb_classes, in_channels=3, dim_hidden=64, **kwargs): del kwargs Model.__init__(self, scope, nb_classes, locals()) self.img_size = img_size self.dim_output = nb_classes self.dim_hidden = dim_hidden self.in_channels = in_channels self.max_pool = True self.is_training = False # self.weight = self.construct_conv_weights(dim_output=nb_classes, channels=in_channels, dim_hidden=dim_hidden) # Do a dummy run of fprop to create the variables from the start self.dummpy_input = tf.placeholder( tf.float32, [FLAGS.batch_size, img_size, img_size, in_channels]) self.fprop(self.dummpy_input) self.params = self.get_params()
def __init__(self, nb_classes=10): # we cannot use scopes, give these variables names, etc. self.W_conv1 = self._weight_variable([5, 5, 1, 32], name='classifier/conv1/weights') self.b_conv1 = self._bias_variable([32], name='classifier/conv1/biases') self.W_conv2 = self._weight_variable([5, 5, 32, 64], name='classifier/conv2/weights') self.b_conv2 = self._bias_variable([64], name='classifier/conv2/biases') self.W_fc1 = self._weight_variable([1600, 1024], name='classifier/fc1/weights') self.b_fc1 = self._bias_variable([1024], name='classifier/fc1/biases') self.W_fc2 = self._weight_variable([1024, nb_classes], name='classifier/fc2/weights') self.b_fc2 = self._bias_variable([nb_classes], name='classifier/fc2/biases') self.all_variables = [ self.W_conv1, self.b_conv1, self.W_conv2, self.b_conv2, self.W_fc1, self.b_fc1, self.W_fc2, self.b_fc2 ] #self.xent = tf.Variable(tf.zeros([16,10])) Model.__init__(self, '', nb_classes, {})
def __init__(self, nb_classes=10): # NOTE: for compatibility with Madry Lab downloadable checkpoints, # we cannot use scopes, give these variables names, etc. """ self.conv1 = tf.layers.Conv2D(32, (5, 5), activation='relu', padding='same', name='conv1') self.pool1 = tf.layers.MaxPooling2D((2, 2), (2, 2), padding='same') self.conv2 = tf.layers.Conv2D(64, (5, 5), activation='relu', padding='same', name='conv2') self.pool2 = tf.layers.MaxPooling2D((2, 2), (2, 2), padding='same') self.fc1 = tf.layers.Dense(1024, activation='relu', name='fc1') self.fc2 = tf.layers.Dense(10, name='fc2') """ keras_model = tf.keras.Sequential() keras_model.add( tf.keras.layers.Conv2D(32, (5, 5), activation='relu', padding='same', name='conv1', input_shape=(28, 28, 1))) keras_model.add( tf.keras.layers.MaxPooling2D((2, 2), (2, 2), padding='same')) keras_model.add( tf.keras.layers.Conv2D(64, (5, 5), activation='relu', padding='same', name='conv2')) keras_model.add( tf.keras.layers.MaxPooling2D((2, 2), (2, 2), padding='same')) keras_model.add(tf.keras.layers.Flatten()) keras_model.add( tf.keras.layers.Dense(1024, activation='relu', name='fc1')) keras_model.add(tf.keras.layers.Dense(10, name='fc2')) self.keras_model = keras_model Model.__init__(self, '', nb_classes, {}) self.dataset_factory = Factory(MNIST, {"center": False})
def __init__(self, scope='simple_spatial', nb_classes=2, **kwargs): del kwargs Model.__init__(self, scope, nb_classes, locals())
def __init__(self, scope, nb_classes, nb_filters=200, **kwargs): del kwargs Model.__init__(self, scope, nb_classes, locals()) self.nb_filters = nb_filters
def __init__(self, scope, nb_classes=1000, **kwargs): del kwargs Model.__init__(self, scope, nb_classes, locals())
def __init__(self, scope='dummy_model', nb_classes=10, **kwargs): del kwargs Model.__init__(self, scope, nb_classes, locals())
def __init__(self, scope, num_classes, **kwargs): del kwargs Model.__init__(self, scope, num_classes, locals()) self.scope = scope or self.__class__.__name__ self.num_classes = num_classes Basic_cnn_tf_model.__init__(self,keep_prob=0.5, num_classes=num_classes)
def __init__(self, scope='trivial', nb_classes=2, **kwargs): del kwargs Model.__init__(self, scope, nb_classes, locals())
def __init__(self, scope, nb_classes, nb_filters, **kwargs): del kwargs Model.__init__(self, scope, nb_classes, locals()) self.nb_filters = nb_filters