本文整理汇总了Python中flags.FLAGS属性的典型用法代码示例。如果您正苦于以下问题:Python flags.FLAGS属性的具体用法?Python flags.FLAGS怎么用?Python flags.FLAGS使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类flags
的用法示例。
在下文中一共展示了flags.FLAGS属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import flags [as 别名]
# 或者: from flags import FLAGS [as 别名]
def main(_):
flags.load_config_file()
filenames, images = read_data_inception(FLAGS.input_dir)
batch_shape = [len(images), FLAGS.image_height, FLAGS.image_width, FLAGS.image_channels]
num_classes = FLAGS.num_classes
sess = tf.Session()
with sess.as_default():
x_input = tf.placeholder(tf.float32, shape=batch_shape)
logits_activations = inception(x_input)
restore_model_vars(sess, tf.global_variables(), FLAGS.model_path)
with tf.gfile.Open(FLAGS.output_file, 'w') as out_file:
classifications = sess.run(tf.nn.softmax(logits_activations), feed_dict={x_input: images})
for j in xrange(len(filenames)):
out_file.write("{0},{1}\n".format(filenames[j], top3_as_string(classifications, j)))
示例2: get_print_triplets
# 需要导入模块: import flags [as 别名]
# 或者: from flags import FLAGS [as 别名]
def get_print_triplets(file_path):
'''
Reads the printability triplets from the specified file
and returns a numpy array of shape (num_triplets, FLAGS.img_cols, FLAGS.img_rows, nb_channels)
where each triplet has been copied to create an array the size of the image
:return: as described
'''
p = []
# load the triplets and create an array of the speified size
with open(file_path) as f:
for l in f:
p.append(l.split(","))
p = map(lambda x: [[x for _ in xrange(FLAGS.image_width)] for __ in xrange(FLAGS.image_height)], p)
p = np.float32(p)
p *= 2.0
p -= 1.0
return p
示例3: _get_dest_points
# 需要导入模块: import flags [as 别名]
# 或者: from flags import FLAGS [as 别名]
def _get_dest_points(self, shape):
n = shape[0]
img_rows = shape[-3]
img_cols = shape[-2]
# source points
src = [[[0,0],[0,img_cols],[img_rows,0],[img_rows,img_cols]] for _ in range(n)]
if self.just_apply_noise:
return src
import scipy.stats as stats
lower, upper = -img_rows/3, img_rows/3
mu, sigma = FLAGS.transform_mean, FLAGS.transform_stddev
X = stats.truncnorm(
(lower - mu) / sigma, (upper - mu) / sigma, loc=mu, scale=sigma)
# we will add this to the source points, i.e. these are random offsets
# random = np.random.normal(FLAGS.transform_mean, FLAGS.transform_stddev, (n, 4, 2))
random = X.rvs((n, 4, 2))
return src + random
示例4: optimize
# 需要导入模块: import flags [as 别名]
# 或者: from flags import FLAGS [as 别名]
def optimize(self, num_epochs):
latest_acc = 0.0
latest_loss = 10000.0
for e in range(num_epochs):
acc, loss, noise_img, victim_img = self.epoch(e)
if acc > latest_acc or (acc == latest_acc and loss < latest_loss):
latest_acc = acc
latest_loss = loss
self.saver.save(self.sess, \
os.path.join(FLAGS.save_folder, FLAGS.save_prefix, "%s_epoch_%d"%(FLAGS.save_prefix, e)))
if noise_img is not None:
write_reverse_preprocess_inception( \
os.path.join(FLAGS.save_folder, FLAGS.save_prefix, "noise-epoch-%04d.png"%e), noise_img)
if victim_img is not None:
write_reverse_preprocess_inception( \
os.path.join(FLAGS.save_folder, FLAGS.save_prefix, "victim-epoch-%04d.png"%e), victim_img)
示例5: init_infra
# 需要导入模块: import flags [as 别名]
# 或者: from flags import FLAGS [as 别名]
def init_infra(self, num_switch=0, num_node_p_switch=0, num_gpu_p_node=0, num_cpu_p_node=0, mem_p_node=0):
'''
Init and create cluster infration entities (switches, nodes) by using class _Switch, _Node
'''
if num_switch == 0 and num_node_p_switch == 0 and num_gpu_p_node == 0 and num_cpu_p_node == 0 and mem_p_node == 0:
#no new spec, apply FLAGS spec info
self.set_spec(FLAGS.num_switch, FLAGS.num_node_p_switch, FLAGS.num_gpu_p_node, FLAGS.num_cpu_p_node, FLAGS.mem_p_node)
else:
self.set_spec(num_switch, num_node_p_switch, num_gpu_p_node, num_cpu_p_node, mem_p_node)
'''create/init switch and node objects'''
for s in range(0, self.num_switch):
tmp_s = _Switch(s, self.num_node_p_switch, self.num_gpu_p_node, self.num_cpu_p_node, self.mem_p_node)
tmp_s.add_nodes(self.num_node_p_switch, self.num_gpu_p_node, self.num_cpu_p_node, self.mem_p_node)
self.switch_list.append(tmp_s)
util.print_fn('Cluster is ready to use')
self.print_cluster_spec()
示例6: try_get_job_res
# 需要导入模块: import flags [as 别名]
# 或者: from flags import FLAGS [as 别名]
def try_get_job_res(job):
'''
select placement scheme
'''
if FLAGS.scheme == 'yarn':
ret = CLUSTER.ms_yarn_placement(job)
elif FLAGS.scheme == 'balance':
ret = lp.placement(job)
# ret = lp.min_new_job(job)
elif FLAGS.scheme == 'random':
ret = CLUSTER.random_placement(job)
elif FLAGS.scheme == 'crandom':
ret = CLUSTER.consolidate_random_placement(job)
elif FLAGS.scheme == 'greedy':
ret = CLUSTER.greedy_placement(job)
elif FLAGS.scheme == 'gandiva':
ret = CLUSTER.gandiva_placement(job)
elif FLAGS.scheme == 'count':
ret = CLUSTER.none_placement(job)
else:
ret = CLUSTER.ms_yarn_placement(job)
if ret == True:
# job['status'] = 'RUNNING'
pass
return ret
示例7: sort_all_jobs
# 需要导入模块: import flags [as 别名]
# 或者: from flags import FLAGS [as 别名]
def sort_all_jobs(self, mode=None):
'''
Sort jobs based on their sumbit_time
j1, num_gpu, start_t, end_t, duration
'''
# tmp_list = sorted(self.job_list, key = lambda e:e.__getitem__('start_time'))
# tmp_dict = util.search_dict_list(self.job_list, 'start_time', 4)
# tmp_dict['end_time'] = 15
# print(tmp_dict)
# self.job_list = tmp_list
self.job_list.sort(key = lambda e:e.__getitem__('submit_time'))
util.print_fn(' Jobs are sorted with their start time')
# self.read_all_jobs()
if FLAGS.schedule == 'multi-dlas-gpu' and FLAGS.scheme == 'count':
for num_gpu, gjob in self.gpu_job.items():
util.print_fn('%d-GPU jobs have %d ' % (num_gpu, gjob.total_job))
示例8: get_test_image_preprocessor
# 需要导入模块: import flags [as 别名]
# 或者: from flags import FLAGS [as 别名]
def get_test_image_preprocessor(batch_size, params):
"""Returns the preprocessing.TestImagePreprocessor that should be injected.
Returns None if no preprocessor should be injected.
Args:
batch_size: The batch size across all GPUs.
params: BenchmarkCNN's parameters.
Returns:
Returns the preprocessing.TestImagePreprocessor that should be injected.
Raises:
ValueError: Flag --fake_input is an invalid value.
"""
if FLAGS.fake_input == 'none':
return None
elif FLAGS.fake_input == 'zeros_and_ones':
half_batch_size = batch_size // 2
images = np.zeros((batch_size, 227, 227, 3), dtype=np.float32)
images[half_batch_size:, :, :, :] = 1
labels = np.array([0] * half_batch_size + [1] * half_batch_size,
dtype=np.int32)
preprocessor = preprocessing.TestImagePreprocessor(
batch_size, [227, 227, 3], params.num_gpus,
benchmark_cnn.get_data_type(params))
preprocessor.set_fake_data(images, labels)
preprocessor.expected_subset = 'validation' if params.eval else 'train'
return preprocessor
else:
raise ValueError('Invalid --fake_input: %s' % FLAGS.fake_input)
示例9: inception
# 需要导入模块: import flags [as 别名]
# 或者: from flags import FLAGS [as 别名]
def inception(x_input):
'''
Builds the inception network model,
loads its weights from FLAGS.checkpoint_path,
and returns the softmax activations tensor.
'''
from tensorflow.contrib.slim.nets import inception as inception_tf
slim = tf.contrib.slim
with slim.arg_scope(inception_tf.inception_v3_arg_scope()):
_, end_points = inception_tf.inception_v3(x_input, \
num_classes=FLAGS.num_classes, \
is_training=False)
return end_points['Logits']
示例10: get_noise_init_from_flags
# 需要导入模块: import flags [as 别名]
# 或者: from flags import FLAGS [as 别名]
def get_noise_init_from_flags():
if FLAGS.noise_initial == "zeros":
return tf.constant_initializer(0.0)
elif FLAGS.noise_initial == "random_normal":
return tf.random_normal_initializer(mean=FLAGS.noise_init_mean, \
stddev=FLAGS.noise_init_stddev)
else:
raise Exception("FLAGS.noise_initial must be zeros or random_normal. Currently %s"%\
FLAGS.noise_initial)
示例11: get_reg_losses_from_flags
# 需要导入模块: import flags [as 别名]
# 或者: from flags import FLAGS [as 别名]
def get_reg_losses_from_flags():
if FLAGS.reglosses != "":
return [x.strip() for x in FLAGS.reglosses.split(",")]
else:
return []
示例12: _get_color_shifts
# 需要导入模块: import flags [as 别名]
# 或者: from flags import FLAGS [as 别名]
def _get_color_shifts(self, shape_of_color_shifts):
return np.ones(shape_of_color_shifts)*np.random.uniform(FLAGS.color_shifts_min, FLAGS.color_shifts_max) \
if not self.just_apply_noise \
else np.ones(shape_of_color_shifts)
示例13: create_feed_dict
# 需要导入模块: import flags [as 别名]
# 或者: from flags import FLAGS [as 别名]
def create_feed_dict(self, data, attack_graph):
if len(data.shape) == 4:
n = data.shape[0]
shape_of_color_shifts = data.shape
else:
raise Exception("data needs to be of rank 4, currently %d"%len(data.shape))
feed_dict = {
attack_graph.clean_input: data, \
attack_graph.mask: read_img(FLAGS.attack_mask)/255.0, \
attack_graph.color_shifts: self._get_color_shifts(shape_of_color_shifts),
attack_graph.boxes: self._get_boxes(n), \
attack_graph.dest_points: self._get_dest_points(shape_of_color_shifts)
}
if not self.just_apply_noise:
feed_dict[attack_graph.learning_rate] = FLAGS.attack_learning_rate
if self.losses_dict is None:
self.losses_dict = {}
targets = np.zeros(attack_graph.output_shape)
targets[:, FLAGS.attack_target] = 1.0
self.losses_dict[attack_graph.attack_target] = targets
for l in attack_graph.reg_names:
self.losses_dict[attack_graph.reg_lambdas[l]] = FLAGS.__dict__["__flags"]["lambda_%s"%l]
if l == "l2image":
self.losses_dict[attack_graph.l2image] = read_preprocessed_inception(FLAGS.l2image)
elif l == "nps":
self.losses_dict[attack_graph.nps_triplets] = get_print_triplets(FLAGS.printability_tuples)
feed_dict.update(self.losses_dict)
return feed_dict
示例14: calculate_acc
# 需要导入模块: import flags [as 别名]
# 或者: from flags import FLAGS [as 别名]
def calculate_acc(self):
assert FLAGS.validation_set is not None
assert self.val_data is not None
val_feed_dict = self.create_feed_dict(np.array(self.val_data), self.attack_graph)
net_predictions = self.sess.run(tf.argmax(self.attack_graph.adv_pred, axis=1), \
feed_dict=val_feed_dict)
labels = [FLAGS.attack_target for _ in range(len(net_predictions))]
val_feed_dict = None
gc.collect()
return accuracy_score(labels, net_predictions, normalize=True)
示例15: main
# 需要导入模块: import flags [as 别名]
# 或者: from flags import FLAGS [as 别名]
def main(argv=None):
flags.load_config_file()
flags.print_flags()
if not FLAGS.just_apply_noise:
attack = Attack(False, FLAGS.attack_batch_size)
attack.optimize(FLAGS.attack_epochs)
else:
assert FLAGS.apply_folder != ""
fnames, data = read_data_inception(FLAGS.apply_folder)
attack = Attack(True, len(fnames))
print("apply folder", FLAGS.apply_folder)
attack.extract_noise(FLAGS.apply_folder, fnames, data)