本文整理汇总了Python中cifar10.inputs方法的典型用法代码示例。如果您正苦于以下问题:Python cifar10.inputs方法的具体用法?Python cifar10.inputs怎么用?Python cifar10.inputs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cifar10
的用法示例。
在下文中一共展示了cifar10.inputs方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: loss
# 需要导入模块: import cifar10 [as 别名]
# 或者: from cifar10 import inputs [as 别名]
def loss(logits, labels):
# """Add L2Loss to all the trainable variables.
# Add summary for "Loss" and "Loss/avg".
# Args:
# logits: Logits from inference().
# labels: Labels from distorted_inputs or inputs(). 1-D tensor
# of shape [batch_size]
# Returns:
# Loss tensor of type float.
# """
# # Calculate the average cross entropy loss across the batch.
labels = tf.cast(labels, tf.int64)
cross_entropy = tf.nn.sparse_softmax_cross_entropy_with_logits(
logits=logits, labels=labels, name='cross_entropy_per_example')
cross_entropy_mean = tf.reduce_mean(cross_entropy, name='cross_entropy')
tf.add_to_collection('losses', cross_entropy_mean)
# The total loss is defined as the cross entropy loss plus all of the weight
# decay terms (L2 loss).
return tf.add_n(tf.get_collection('losses'), name='total_loss')
###
示例2: evaluate
# 需要导入模块: import cifar10 [as 别名]
# 或者: from cifar10 import inputs [as 别名]
def evaluate():
"""Eval CIFAR-10 for a number of steps."""
with tf.Graph().as_default() as g:
# Get images and labels for CIFAR-10.
eval_data = FLAGS.eval_data == 'test'
images, labels = cifar10.inputs(eval_data=eval_data)
# Build a Graph that computes the logits predictions from the
# inference model.
logits = cifar10.inference(images)
# Calculate predictions.
top_k_op = tf.nn.in_top_k(logits, labels, 1)
# Restore the moving average version of the learned variables for eval.
variable_averages = tf.train.ExponentialMovingAverage(
cifar10.MOVING_AVERAGE_DECAY)
variables_to_restore = variable_averages.variables_to_restore()
saver = tf.train.Saver(variables_to_restore)
# Build the summary operation based on the TF collection of Summaries.
summary_op = tf.summary.merge_all()
summary_writer = tf.summary.FileWriter(FLAGS.eval_dir, g)
while True:
eval_once(saver, summary_writer, top_k_op, summary_op)
if FLAGS.run_once:
break
time.sleep(FLAGS.eval_interval_secs)
示例3: evaluate
# 需要导入模块: import cifar10 [as 别名]
# 或者: from cifar10 import inputs [as 别名]
def evaluate():
"""Eval CIFAR-10 for a number of steps."""
with tf.Graph().as_default():
# Get images and labels for CIFAR-10.
eval_data = FLAGS.eval_data == 'test'
images, labels = cifar10.inputs(eval_data=eval_data)
# Build a Graph that computes the logits predictions from the
# inference model.
logits = cifar10.inference(images)
# Calculate predictions.
top_k_op = tf.nn.in_top_k(logits, labels, 1)
# Restore the moving average version of the learned variables for eval.
variable_averages = tf.train.ExponentialMovingAverage(
cifar10.MOVING_AVERAGE_DECAY)
variables_to_restore = variable_averages.variables_to_restore()
saver = tf.train.Saver(variables_to_restore)
# Build the summary operation based on the TF collection of Summaries.
summary_op = tf.summary.merge_all()
graph_def = tf.get_default_graph().as_graph_def()
summary_writer = tf.summary.FileWriter(FLAGS.eval_dir,
graph_def=graph_def)
while True:
eval_once(saver, summary_writer, top_k_op, summary_op)
if FLAGS.run_once:
break
time.sleep(FLAGS.eval_interval_secs)
示例4: evaluate
# 需要导入模块: import cifar10 [as 别名]
# 或者: from cifar10 import inputs [as 别名]
def evaluate(eval_dir):
"""Eval CIFAR-10 for a number of steps."""
with tf.Graph().as_default() as g:
# Get images and labels for CIFAR-10.
eval_data = FLAGS.eval_data == 'test'
images, labels = cifar10.inputs(eval_data=eval_data)
phase = tf.Variable(False, name='is_train', dtype=bool, trainable=False)
# Build a Graph that computes the logits predictions from the
# inference model.
if not FLAGS.vanilla:
logits = cifar10.inference(images, phase, vd.conv2d)
else:
logits = cifar10.inference(images, phase, None)
# Calculate predictions.
top_k_op = tf.nn.in_top_k(logits, labels, 1)
# Restore the moving average version of the learned variables for eval.
variable_averages = tf.train.ExponentialMovingAverage(
cifar10.MOVING_AVERAGE_DECAY)
variables_to_restore = variable_averages.variables_to_restore()
saver = tf.train.Saver(variables_to_restore)
# Build the summary operation based on the TF collection of Summaries.
summary_op = tf.summary.merge_all()
summary_writer = tf.summary.FileWriter(eval_dir, g)
while True:
eval_once(saver, summary_writer, top_k_op, summary_op)
if FLAGS.run_once:
break
time.sleep(FLAGS.eval_interval_secs)
示例5: evaluate
# 需要导入模块: import cifar10 [as 别名]
# 或者: from cifar10 import inputs [as 别名]
def evaluate():
"""Eval CIFAR-10 for a number of steps."""
with tf.Graph().as_default() as g:
# Get images and labels for CIFAR-10.
images, labels = cifar10.inputs(eval_data=FLAGS.eval_data)
# Build a Graph that computes the logits predictions from the
# inference model.
logits = cifar10.inference(images)
logits = tf.cast(logits, "float32")
labels = tf.cast(labels, "int32")
# Calculate predictions.
top_k_op = tf.nn.in_top_k(logits, labels, 1)
# Restore the moving average version of the learned variables for eval.
variable_averages = tf.train.ExponentialMovingAverage(
cifar10.MOVING_AVERAGE_DECAY)
variables_to_restore = variable_averages.variables_to_restore()
saver = tf.train.Saver(variables_to_restore)
# Build the summary operation based on the TF collection of Summaries.
summary_op = tf.summary.merge_all()
summary_writer = tf.summary.FileWriter(FLAGS.eval_dir, g)
while True:
eval_once(saver, summary_writer, top_k_op, summary_op)
if FLAGS.run_once:
break
time.sleep(FLAGS.eval_interval_secs)
开发者ID:ShivangShekhar,项目名称:Live-feed-object-device-identification-using-Tensorflow-and-OpenCV,代码行数:34,代码来源:cifar10_eval.py
示例6: main
# 需要导入模块: import cifar10 [as 别名]
# 或者: from cifar10 import inputs [as 别名]
def main(_):
with tf.Graph().as_default() as g:
with tf.device("/cpu:0"):
images_eval_train, _ = inputs(batch_size=FLAGS.finetune_batch_size,
validation=FLAGS.validation,
shuffle=True)
images_eval_test, labels_eval_test = inputs(batch_size=FLAGS.eval_batch_size,
train=False,
validation=FLAGS.validation,
shuffle=False, num_epochs=1)
with tf.device(FLAGS.device):
with tf.variable_scope("CNN") as scope:
# Build graph of finetuning BN stats
finetune_op = build_finetune_graph(images_eval_train)
scope.reuse_variables()
# Build eval graph
n_correct, m = build_eval_graph(images_eval_test, labels_eval_test)
init_op = tf.global_variables_initializer()
saver = tf.train.Saver(tf.global_variables())
sess = tf.Session()
sess.run(init_op)
ckpt = tf.train.get_checkpoint_state(FLAGS.log_dir)
print("Checkpoints:", ckpt)
if ckpt and ckpt.model_checkpoint_path:
saver.restore(sess, ckpt.model_checkpoint_path)
sess.run(tf.local_variables_initializer())
coord = tf.train.Coordinator()
tf.train.start_queue_runners(sess=sess, coord=coord)
print("Finetuning...")
for _ in range(FLAGS.finetune_iter):
sess.run(finetune_op)
sum_correct_examples= 0
sum_m = 0
try:
while not coord.should_stop():
_n_correct, _m = sess.run([n_correct, m])
sum_correct_examples += _n_correct
sum_m += _m
except tf.errors.OutOfRangeError:
print('Done evaluation -- epoch limit reached')
finally:
# When done, ask the threads to stop.
coord.request_stop()
print("Test: num_test_examples:{}, num_correct_examples:{}, accuracy:{}".format(
sum_m, sum_correct_examples, sum_correct_examples/float(sum_m)))