当前位置: 首页>>代码示例>>Python>>正文


Python resnet_model.HParams方法代码示例

本文整理汇总了Python中resnet_model.HParams方法的典型用法代码示例。如果您正苦于以下问题:Python resnet_model.HParams方法的具体用法?Python resnet_model.HParams怎么用?Python resnet_model.HParams使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在resnet_model的用法示例。


在下文中一共展示了resnet_model.HParams方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: import resnet_model [as 别名]
# 或者: from resnet_model import HParams [as 别名]
def main(_):
  if FLAGS.num_gpus == 0:
    dev = '/cpu:0'
  elif FLAGS.num_gpus == 1:
    dev = '/gpu:0'
  else:
    raise ValueError('Only support 0 or 1 gpu.')

  if FLAGS.mode == 'train':
    batch_size = 128
  elif FLAGS.mode == 'eval':
    batch_size = 100

  if FLAGS.dataset == 'cifar10':
    num_classes = 10
  elif FLAGS.dataset == 'cifar100':
    num_classes = 100

  hps = resnet_model.HParams(batch_size=batch_size,
                             num_classes=num_classes,
                             min_lrn_rate=0.0001,
                             lrn_rate=0.1,
                             num_residual_units=5,
                             use_bottleneck=False,
                             weight_decay_rate=0.0002,
                             relu_leakiness=0.1,
                             optimizer='mom')

  with tf.device(dev):
    if FLAGS.mode == 'train':
      train(hps)
    elif FLAGS.mode == 'eval':
      evaluate(hps) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:35,代码来源:resnet_main.py

示例2: main

# 需要导入模块: import resnet_model [as 别名]
# 或者: from resnet_model import HParams [as 别名]
def main(_):
  if FLAGS.num_gpus == 0:
    dev = '/cpu:0'
  elif FLAGS.num_gpus == 1:
    dev = '/gpu:0'
  else:
    raise ValueError('Only support 0 or 1 gpu.')

  if FLAGS.mode == 'train':
    batch_size = 128
  elif FLAGS.mode == 'eval':
    batch_size = 100

  if FLAGS.dataset == 'cifar10':
    num_classes = 10
  elif FLAGS.dataset == 'cifar100':
    num_classes = 100

  hps = resnet_model.HParams(batch_size=batch_size,
                             num_classes=num_classes,
                             min_lrn_rate=0.0001,
                             lrn_rate=0.1,
                             num_residual_units=5,
                             use_bottleneck=False,
                             weight_decay_rate=0.0002,
                             relu_leakiness=0.1,
                             optimizer='mom')

#   with tf.device(dev):
  if FLAGS.mode == 'train':
    train(hps)
  elif FLAGS.mode == 'eval':
    evaluate(hps) 
开发者ID:awslabs,项目名称:deeplearning-benchmark,代码行数:35,代码来源:resnet_main.py

示例3: eval_resnet

# 需要导入模块: import resnet_model [as 别名]
# 或者: from resnet_model import HParams [as 别名]
def eval_resnet():
  """Evaluates the resnet model."""
  if not os.path.exists(FLAGS.eval_dir):
    os.makedirs(FLAGS.eval_dir)
  g = tf.Graph()
  with g.as_default():
    # pylint: disable=line-too-long
    images, one_hot_labels, num_samples, num_of_classes = cifar_data_provider.provide_resnet_data(
        FLAGS.dataset_name,
        FLAGS.split_name,
        FLAGS.batch_size,
        dataset_dir=FLAGS.data_dir,
        num_epochs=None)

    hps = resnet_model.HParams(
        batch_size=FLAGS.batch_size,
        num_classes=num_of_classes,
        min_lrn_rate=0.0001,
        lrn_rate=0,
        num_residual_units=9,
        use_bottleneck=False,
        weight_decay_rate=0.0002,
        relu_leakiness=0.1,
        optimizer='mom')

    # Define the model:
    images.set_shape([FLAGS.batch_size, 32, 32, 3])
    resnet = resnet_model.ResNet(hps, images, one_hot_labels, mode='test')

    logits = resnet.build_model()

    total_loss = tf.nn.softmax_cross_entropy_with_logits(
        labels=one_hot_labels, logits=logits)
    total_loss = tf.reduce_mean(total_loss, name='xent')

    slim.summaries.add_scalar_summary(
        total_loss, 'total_loss', print_summary=True)

    # Define the metrics:
    predictions = tf.argmax(logits, 1)
    labels = tf.argmax(one_hot_labels, 1)

    names_to_values, names_to_updates = slim.metrics.aggregate_metric_map({
        'accuracy': tf.metrics.accuracy(predictions, labels),
    })

    for name, value in names_to_values.iteritems():
      slim.summaries.add_scalar_summary(
          value, name, prefix='eval', print_summary=True)

    # This ensures that we make a single pass over all of the data.
    num_batches = math.ceil(num_samples / float(FLAGS.batch_size))

    slim.evaluation.evaluation_loop(
        master=FLAGS.master,
        checkpoint_dir=FLAGS.checkpoint_dir,
        logdir=FLAGS.eval_dir,
        num_evals=num_batches,
        eval_op=names_to_updates.values(),
        eval_interval_secs=FLAGS.eval_interval_secs) 
开发者ID:google,项目名称:mentornet,代码行数:62,代码来源:cifar_eval.py


注:本文中的resnet_model.HParams方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。