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


Python Network.test方法代码示例

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


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

示例1: demo

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import test [as 别名]
def demo():
    params = iho_len(add_set[0])
    first = Network(params[0], params[1], params[2], 5000, 0.08, momentum=0.1)
    first.train(add_set)
    first.test(add_set)

    """
  Used when dealing with entirely binary inputs.
  """
    """
  x = [0, 1, 2, 3, 4, 5, 6]
  y = [9, 8, 7, 6, 4, 3, 3]
  print ''
  for i, j in zip(x, y):
    first.test([[dec_bin(i) + dec_bin(j), dec_bin(i + j)]])
  """
    """
开发者ID:narrowmark,项目名称:nn_calc,代码行数:19,代码来源:nn_calc.py

示例2: test_xor

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import test [as 别名]
def test_xor():
    n = Network(2, 4, 1)
    train = (
        ([0, 0], [0]),
        ([1, 1], [0]),
        ([0, 1], [1]),
        ([1, 0], [1]),
    )

    for i in xrange(20000):
        inp, out = train[randint(0, 3)]
        n.train(inp, out)

    for inp, out in train:
        assert round(n.test(inp)[0]) == out[0]
开发者ID:nopper,项目名称:pyocr,代码行数:17,代码来源:__init__.py

示例3: test_bindec

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import test [as 别名]
def test_bindec():
    n = Network(4, 6, 16)
    train = {}

    for i in xrange(16):
        bstr = bin(i)[2:]
        bstr = '0' * (4 - len(bstr)) + bstr

        inp = map(int, [c for c in bstr])

        out = [0] * 16
        out[i] = 1

        train[i] = (inp, out)

    for i in xrange(100000):
        n.train(*train[randint(0, 15)])

    for k, (inp, out) in train.items():
        ret = n.test(inp)
        assert ret.index(max(ret)) == k
开发者ID:nopper,项目名称:pyocr,代码行数:23,代码来源:__init__.py

示例4: main

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import test [as 别名]
def main(_):
  model_dir = get_model_dir(conf,
      ['data_dir', 'sample_dir', 'max_epoch', 'test_step', 'save_step',
       'is_train', 'random_seed', 'log_level', 'display'])
  preprocess_conf(conf)

  DATA_DIR = os.path.join(conf.data_dir, conf.data)
  SAMPLE_DIR = os.path.join(conf.sample_dir, conf.data, model_dir)

  check_and_create_dir(DATA_DIR)
  check_and_create_dir(SAMPLE_DIR)

  # 0. prepare datasets
  if conf.data == "mnist":
    from tensorflow.examples.tutorials.mnist import input_data
    mnist = input_data.read_data_sets(DATA_DIR, one_hot=True)

    next_train_batch = lambda x: mnist.train.next_batch(x)[0]
    next_test_batch = lambda x: mnist.test.next_batch(x)[0]

    height, width, channel = 28, 28, 1

    train_step_per_epoch = mnist.train.num_examples / conf.batch_size
    test_step_per_epoch = mnist.test.num_examples / conf.batch_size
  elif conf.data == "cifar":
    from cifar10 import IMAGE_SIZE, inputs

    maybe_download_and_extract(DATA_DIR)
    images, labels = inputs(eval_data=False,
        data_dir=os.path.join(DATA_DIR, 'cifar-10-batches-bin'), batch_size=conf.batch_size)

    height, width, channel = IMAGE_SIZE, IMAGE_SIZE, 3

  with tf.Session() as sess:
    network = Network(sess, conf, height, width, channel)

    stat = Statistic(sess, conf.data, model_dir, tf.trainable_variables(), conf.test_step)
    stat.load_model()

    if conf.is_train:
      logger.info("Training starts!")

      initial_step = stat.get_t() if stat else 0
      iterator = trange(conf.max_epoch, ncols=70, initial=initial_step)

      for epoch in iterator:
        # 1. train
        total_train_costs = []
        for idx in xrange(train_step_per_epoch):
          images = binarize(next_train_batch(conf.batch_size)) \
            .reshape([conf.batch_size, height, width, channel])

          cost = network.test(images, with_update=True)
          total_train_costs.append(cost)

        # 2. test
        total_test_costs = []
        for idx in xrange(test_step_per_epoch):
          images = binarize(next_test_batch(conf.batch_size)) \
            .reshape([conf.batch_size, height, width, channel])

          cost = network.test(images, with_update=False)
          total_test_costs.append(cost)

        avg_train_cost, avg_test_cost = np.mean(total_train_costs), np.mean(total_test_costs)

        stat.on_step(avg_train_cost, avg_test_cost)

        # 3. generate samples
        samples = network.generate()
        save_images(samples, height, width, 10, 10,
            directory=SAMPLE_DIR, prefix="epoch_%s" % epoch)

        iterator.set_description("train l: %.3f, test l: %.3f" % (avg_train_cost, avg_test_cost))
        print
    else:
      logger.info("Image generation starts!")

      samples = network.generate()
      save_images(samples, height, width, 10, 10, directory=SAMPLE_DIR)
开发者ID:carpedm20,项目名称:pixel-rnn-tensorflow,代码行数:82,代码来源:main.py


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