本文整理匯總了Python中tensorflow.python.platform.flags.FLAGS屬性的典型用法代碼示例。如果您正苦於以下問題:Python flags.FLAGS屬性的具體用法?Python flags.FLAGS怎麽用?Python flags.FLAGS使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類tensorflow.python.platform.flags
的用法示例。
在下文中一共展示了flags.FLAGS屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: create_mparams
# 需要導入模塊: from tensorflow.python.platform import flags [as 別名]
# 或者: from tensorflow.python.platform.flags import FLAGS [as 別名]
def create_mparams():
return {
'conv_tower_fn':
model.ConvTowerParams(final_endpoint=FLAGS.final_endpoint),
'sequence_logit_fn':
model.SequenceLogitsParams(
use_attention=FLAGS.use_attention,
use_autoregression=FLAGS.use_autoregression,
num_lstm_units=FLAGS.num_lstm_units,
weight_decay=FLAGS.weight_decay,
lstm_state_clip_value=FLAGS.lstm_state_clip_value),
'sequence_loss_fn':
model.SequenceLossParams(
label_smoothing=FLAGS.label_smoothing,
ignore_nulls=FLAGS.ignore_nulls,
average_across_timesteps=FLAGS.average_across_timesteps)
}
示例2: get_args
# 需要導入模塊: from tensorflow.python.platform import flags [as 別名]
# 或者: from tensorflow.python.platform.flags import FLAGS [as 別名]
def get_args():
navtask = nec.nav_env_base_config()
navtask.task_params.type = 'rng_rejection_sampling_many'
navtask.task_params.rejection_sampling_M = 2000
navtask.task_params.min_dist = 10
sz = FLAGS.image_size
navtask.camera_param.fov = FLAGS.fov
navtask.camera_param.height = sz
navtask.camera_param.width = sz
navtask.task_params.img_height = sz
navtask.task_params.img_width = sz
# navtask.task_params.semantic_task.class_map_names = ['chair', 'door', 'table']
# navtask.task_params.type = 'to_nearest_obj_acc'
logging.info('navtask: %s', navtask)
return navtask
示例3: test
# 需要導入模塊: from tensorflow.python.platform import flags [as 別名]
# 或者: from tensorflow.python.platform.flags import FLAGS [as 別名]
def test(model, dataset, sess, inner_lr):
# for each batch
eval_valid_loss_list = []
for i in range(int(FLAGS.test_total_num_tasks/FLAGS.num_tasks)):
# load data
[follow_x, _, valid_x,
follow_y, _, valid_y] = dataset.generate_batch(is_training=False,
batch_idx=i * FLAGS.num_tasks,
inc_follow=True)
# set input
feed_in = OrderedDict()
feed_in[model.follow_lr] = inner_lr
feed_in[model.follow_x] = follow_x
feed_in[model.follow_y] = follow_y
feed_in[model.valid_x] = valid_x
feed_in[model.valid_y] = valid_y
# result
eval_valid_loss_list.append(sess.run(model.eval_valid_loss, feed_in))
# aggregate results
eval_valid_loss_list = np.array(eval_valid_loss_list)
eval_valid_loss_mean = np.mean(eval_valid_loss_list, axis=0)
return eval_valid_loss_mean
示例4: test
# 需要導入模塊: from tensorflow.python.platform import flags [as 別名]
# 或者: from tensorflow.python.platform.flags import FLAGS [as 別名]
def test(model, dataset, sess, inner_lr):
# for each batch
eval_valid_loss_list = []
for i in range(int(FLAGS.test_total_num_tasks/FLAGS.num_tasks)):
# load data
[train_x, valid_x,
train_y, valid_y] = dataset.generate_batch(is_training=False,
batch_idx=i * FLAGS.num_tasks)
# set input
feed_in = OrderedDict()
feed_in[model.in_lr] = inner_lr
feed_in[model.train_x] = train_x
feed_in[model.valid_x] = valid_x
feed_in[model.train_y] = train_y
feed_in[model.valid_y] = valid_y
# result
eval_valid_loss_list.append(sess.run(model.eval_valid_loss, feed_in))
# aggregate results
eval_valid_loss_list = np.array(eval_valid_loss_list)
eval_valid_loss_mean = np.mean(eval_valid_loss_list, axis=0)
return eval_valid_loss_mean
示例5: kernel
# 需要導入模塊: from tensorflow.python.platform import flags [as 別名]
# 或者: from tensorflow.python.platform.flags import FLAGS [as 別名]
def kernel(self, particle_tensor, h=-1):
euclidean_dists = tf_utils.pdist(particle_tensor)
pairwise_dists = tf_utils.squareform(euclidean_dists) ** 2
if h == -1:
if FLAGS.kernel == 'org':
mean_dist = tf_utils.median(pairwise_dists) # tf.reduce_mean(euclidean_dists) ** 2
h = mean_dist / math.log(self.num_particles)
h = tf.stop_gradient(h)
elif FLAGS.kernel == 'med':
mean_dist = tf_utils.median(euclidean_dists) ** 2
h = mean_dist / math.log(self.num_particles)
h = tf.stop_gradient(h)
else:
mean_dist = tf.reduce_mean(euclidean_dists) ** 2
h = mean_dist / math.log(self.num_particles)
kernel_matrix = tf.exp(-pairwise_dists / h)
kernel_sum = tf.reduce_sum(kernel_matrix, axis=1, keep_dims=True)
grad_kernel = -tf.matmul(kernel_matrix, particle_tensor)
grad_kernel += particle_tensor * kernel_sum
grad_kernel /= h
return kernel_matrix, grad_kernel, h
示例6: attack_single
# 需要導入模塊: from tensorflow.python.platform import flags [as 別名]
# 或者: from tensorflow.python.platform.flags import FLAGS [as 別名]
def attack_single(self, img, target):
"""
Run the attack on a single image and label
"""
# the previous image
prev = np.copy(img).reshape((1, FLAGS.IMAGE_ROWS, FLAGS.IMAGE_COLS, FLAGS.NUM_CHANNELS))
tau = self.EPS
const = self.INITIAL_CONST
res = self.grad([np.copy(img)], [target], np.copy(prev), tau, const)
if res is None:
# the attack failed, we return this as our final answer
return prev
scores, origscores, nimg, const = res
prev = nimg
return prev
示例7: modelA
# 需要導入模塊: from tensorflow.python.platform import flags [as 別名]
# 或者: from tensorflow.python.platform.flags import FLAGS [as 別名]
def modelA():
model = Sequential()
model.add(Conv2D(64, (5, 5),
padding='valid'))
model.add(Activation('relu'))
model.add(Conv2D(64, (5, 5)))
model.add(Activation('relu'))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(128))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(FLAGS.NUM_CLASSES))
return model
示例8: modelB
# 需要導入模塊: from tensorflow.python.platform import flags [as 別名]
# 或者: from tensorflow.python.platform.flags import FLAGS [as 別名]
def modelB():
model = Sequential()
model.add(Dropout(0.2, input_shape=(FLAGS.IMAGE_ROWS,
FLAGS.IMAGE_COLS,
FLAGS.NUM_CHANNELS)))
model.add(Convolution2D(64, 8, 8,
subsample=(2, 2),
border_mode='same'))
model.add(Activation('relu'))
model.add(Convolution2D(128, 6, 6,
subsample=(2, 2),
border_mode='valid'))
model.add(Activation('relu'))
model.add(Convolution2D(128, 5, 5,
subsample=(1, 1)))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Flatten())
model.add(Dense(FLAGS.NUM_CLASSES))
return model
示例9: modelC
# 需要導入模塊: from tensorflow.python.platform import flags [as 別名]
# 或者: from tensorflow.python.platform.flags import FLAGS [as 別名]
def modelC():
model = Sequential()
model.add(Convolution2D(128, 3, 3,
border_mode='valid',
input_shape=(FLAGS.IMAGE_ROWS,
FLAGS.IMAGE_COLS,
FLAGS.NUM_CHANNELS)))
model.add(Activation('relu'))
model.add(Convolution2D(64, 3, 3))
model.add(Activation('relu'))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(128))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(FLAGS.NUM_CLASSES))
return model
示例10: modelF
# 需要導入模塊: from tensorflow.python.platform import flags [as 別名]
# 或者: from tensorflow.python.platform.flags import FLAGS [as 別名]
def modelF():
model = Sequential()
model.add(Convolution2D(32, 3, 3,
border_mode='valid',
input_shape=(FLAGS.IMAGE_ROWS,
FLAGS.IMAGE_COLS,
FLAGS.NUM_CHANNELS)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Convolution2D(64, 3, 3))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Flatten())
model.add(Dense(1024))
model.add(Activation('relu'))
model.add(Dense(FLAGS.NUM_CLASSES))
return model
示例11: forward_conv
# 需要導入模塊: from tensorflow.python.platform import flags [as 別名]
# 或者: from tensorflow.python.platform.flags import FLAGS [as 別名]
def forward_conv(self, inp, weights, prefix, reuse=False, scope=''):
# reuse is for the normalization parameters.
channels = self.channels
inp = tf.reshape(inp, [-1, self.img_size, self.img_size, channels])
hidden1 = conv_block(inp, weights['conv1'], weights['b1'], reuse, scope+'0')
hidden2 = conv_block(hidden1, weights['conv2'], weights['b2'], reuse, scope+'1')
hidden3 = conv_block(hidden2, weights['conv3'], weights['b3'], reuse, scope+'2')
hidden4 = conv_block(hidden3, weights['conv4'], weights['b4'], reuse, scope+'3')
if FLAGS.dataset == 'miniimagenet' or FLAGS.dataset == 'celeba' or FLAGS.dataset == 'imagenet':
# last hidden layer is 6x6x64-ish, reshape to a vector
hidden4 = tf.reshape(hidden4, [-1, np.prod([int(dim) for dim in hidden4.get_shape()[1:]])])
else:
hidden4 = tf.reduce_mean(hidden4, [1, 2])
logits = tf.matmul(hidden4, weights['w5']) + weights['b5']
if 'val' in prefix:
logits = tf.gather(logits, tf.range(self.dim_output_val), axis=1)
return logits
示例12: run
# 需要導入模塊: from tensorflow.python.platform import flags [as 別名]
# 或者: from tensorflow.python.platform.flags import FLAGS [as 別名]
def run(main=None, argv=None):
"""Runs the program with an optional 'main' function and 'argv' list."""
f = flags.FLAGS
# Extract the args from the optional `argv` list.
args = argv[1:] if argv else None
# Parse the known flags from that list, or from the command
# line otherwise.
# pylint: disable=protected-access
flags_passthrough = f._parse_flags(args=args)
# pylint: enable=protected-access
main = main or _sys.modules['__main__'].main
# Call the main function, passing through any arguments
# to the final program.
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
示例13: create_tb_app
# 需要導入模塊: from tensorflow.python.platform import flags [as 別名]
# 或者: from tensorflow.python.platform.flags import FLAGS [as 別名]
def create_tb_app(plugins):
"""Read the flags, and create a TensorBoard WSGI application.
Args:
plugins: A list of plugins for TensorBoard to initialize.
Raises:
ValueError: if a logdir is not specified.
Returns:
A new TensorBoard WSGI application.
"""
if not FLAGS.logdir:
raise ValueError('A logdir must be specified. Run `tensorboard --help` for '
'details and examples.')
logdir = os.path.expanduser(FLAGS.logdir)
return application.standard_tensorboard_wsgi(
logdir=logdir,
purge_orphaned_data=FLAGS.purge_orphaned_data,
reload_interval=FLAGS.reload_interval,
plugins=plugins)
示例14: forward_conv
# 需要導入模塊: from tensorflow.python.platform import flags [as 別名]
# 或者: from tensorflow.python.platform.flags import FLAGS [as 別名]
def forward_conv(self, inp, weights, reuse=False, scope=''):
# reuse is for the normalization parameters.
channels = self.channels
inp = tf.reshape(inp, [-1, self.img_size, self.img_size, channels])
hidden1 = conv_block(inp, weights['conv1'], weights['b1'], reuse, scope+'0')
hidden2 = conv_block(hidden1, weights['conv2'], weights['b2'], reuse, scope+'1')
hidden3 = conv_block(hidden2, weights['conv3'], weights['b3'], reuse, scope+'2')
hidden4 = conv_block(hidden3, weights['conv4'], weights['b4'], reuse, scope+'3')
if FLAGS.datasource == 'miniimagenet':
# last hidden layer is 6x6x64-ish, reshape to a vector
hidden4 = tf.reshape(hidden4, [-1, np.prod([int(dim) for dim in hidden4.get_shape()[1:]])])
else:
hidden4 = tf.reduce_mean(hidden4, [1, 2])
return tf.matmul(hidden4, weights['w5']) + weights['b5']
示例15: jacobian_graph
# 需要導入模塊: from tensorflow.python.platform import flags [as 別名]
# 或者: from tensorflow.python.platform.flags import FLAGS [as 別名]
def jacobian_graph(predictions, x):
"""
Create the Jacobian graph to be ran later in a TF session
:param predictions: the model's symbolic output (linear output, pre-softmax)
:param x: the input placeholder
:return:
"""
# This function will return a list of TF gradients
list_derivatives = []
# Define the TF graph elements to compute our derivatives for each class
for class_ind in xrange(FLAGS.nb_classes):
derivatives, = tf.gradients(predictions[:, class_ind], x)
list_derivatives.append(derivatives)
return list_derivatives