• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python optimization.assert_next函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tensorflow.contrib.data.python.ops.optimization.assert_next函数的典型用法代码示例。如果您正苦于以下问题:Python assert_next函数的具体用法?Python assert_next怎么用?Python assert_next使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: testFilterFusion

  def testFilterFusion(self, map_function, predicates):
    dataset = dataset_ops.Dataset.range(5).apply(
        optimization.assert_next(["Map", "Filter",
                                  "Prefetch"])).map(map_function)
    for predicate in predicates:
      dataset = dataset.filter(predicate)

    dataset = dataset.prefetch(0).apply(
        optimization.optimize(["filter_fusion"]))
    iterator = dataset.make_one_shot_iterator()
    get_next = iterator.get_next()
    with self.test_session() as sess:
      for x in range(5):
        r = map_function(x)
        filtered = False
        for predicate in predicates:
          if isinstance(r, tuple):
            b = predicate(*r)  # Pass tuple as multiple arguments.
          else:
            b = predicate(r)
          if not sess.run(b):
            filtered = True
            break

        if not filtered:
          result = sess.run(get_next)
          self.assertAllEqual(r, result)
      with self.assertRaises(errors.OutOfRangeError):
        sess.run(get_next)
开发者ID:AnishShah,项目名称:tensorflow,代码行数:29,代码来源:map_and_filter_fusion_test.py


示例2: testMapFilterFusion

 def testMapFilterFusion(self, function, predicate):
   dataset = dataset_ops.Dataset.range(10).apply(
       optimization.assert_next(
           ["Map",
            "FilterByLastComponent"])).map(function).filter(predicate).apply(
                optimization.optimize(["map_and_filter_fusion"]))
   self._testMapAndFilter(dataset, function, predicate)
开发者ID:AnishShah,项目名称:tensorflow,代码行数:7,代码来源:map_and_filter_fusion_test.py


示例3: testLatencyStatsOptimization

  def testLatencyStatsOptimization(self):

    stats_aggregator = stats_ops.StatsAggregator()
    dataset = dataset_ops.Dataset.from_tensors(1).apply(
        optimization.assert_next(
            ["LatencyStats", "Map", "LatencyStats", "Prefetch",
             "LatencyStats"])).map(lambda x: x * x).prefetch(1).apply(
                 optimization.optimize(["latency_all_edges"])).apply(
                     stats_ops.set_stats_aggregator(stats_aggregator))
    iterator = dataset.make_initializable_iterator()
    get_next = iterator.get_next()
    summary_t = stats_aggregator.get_summary()

    with self.test_session() as sess:
      sess.run(iterator.initializer)
      self.assertEqual(1 * 1, sess.run(get_next))
      with self.assertRaises(errors.OutOfRangeError):
        sess.run(get_next)
      summary_str = sess.run(summary_t)
      self._assertSummaryHasCount(summary_str,
                                  "record_latency_TensorDataset/_1", 1)
      self._assertSummaryHasCount(summary_str, "record_latency_MapDataset/_4",
                                  1)
      self._assertSummaryHasCount(summary_str,
                                  "record_latency_PrefetchDataset/_6", 1)
开发者ID:ZhangXinNan,项目名称:tensorflow,代码行数:25,代码来源:optimize_dataset_op_test.py


示例4: testHoisting

  def testHoisting(self, function, will_optimize):
    dataset = dataset_ops.Dataset.range(5).apply(
        optimization.assert_next(
            ["Zip[0]", "Map"] if will_optimize else ["Map"])).map(function)

    dataset = dataset.apply(optimization.optimize(["hoist_random_uniform"]))
    self._testDataset(dataset)
开发者ID:baojianzhou,项目名称:tensorflow,代码行数:7,代码来源:hoist_random_uniform_test.py


示例5: testAssertNext

  def testAssertNext(self):
    dataset = dataset_ops.Dataset.from_tensors(0).apply(
        optimization.assert_next(["Map"])).map(lambda x: x)
    iterator = dataset.make_one_shot_iterator()
    get_next = iterator.get_next()

    with self.cached_session() as sess:
      self.assertEqual(0, sess.run(get_next))
开发者ID:HughKu,项目名称:tensorflow,代码行数:8,代码来源:assert_next_dataset_op_test.py


示例6: testAssertNextShort

  def testAssertNextShort(self):
    dataset = dataset_ops.Dataset.from_tensors(0).apply(
        optimization.assert_next(["Map", "Whoops"])).map(lambda x: x)
    iterator = dataset.make_one_shot_iterator()
    get_next = iterator.get_next()

    with self.cached_session() as sess:
      with self.assertRaisesRegexp(
          errors.InvalidArgumentError,
          "Asserted next 2 transformations but encountered only 1."):
        sess.run(get_next)
开发者ID:HughKu,项目名称:tensorflow,代码行数:11,代码来源:assert_next_dataset_op_test.py


示例7: testStatefulFunctionOptimization

  def testStatefulFunctionOptimization(self):
    dataset = dataset_ops.Dataset.range(10).apply(
        optimization.assert_next([
            "MapAndBatch"
        ])).map(lambda _: random_ops.random_uniform([])).batch(10).apply(
            optimization.optimize(["map_and_batch_fusion"]))
    iterator = dataset.make_one_shot_iterator()
    get_next = iterator.get_next()

    with self.test_session() as sess:
      sess.run(get_next)
开发者ID:mbrukman,项目名称:tensorflow,代码行数:11,代码来源:optimize_dataset_op_test.py


示例8: testOptimization

  def testOptimization(self):
    dataset = dataset_ops.Dataset.range(10).apply(
        optimization.assert_next(
            ["MapAndBatch"])).map(lambda x: x * x).batch(10).apply(
                optimization.optimize(["map_and_batch_fusion"]))
    iterator = dataset.make_one_shot_iterator()
    get_next = iterator.get_next()

    with self.test_session() as sess:
      self.assertAllEqual([x * x for x in range(10)], sess.run(get_next))
      with self.assertRaises(errors.OutOfRangeError):
        sess.run(get_next)
开发者ID:StephenOman,项目名称:tensorflow,代码行数:12,代码来源:optimize_dataset_op_test.py


示例9: testAssertSuffixInvalid

  def testAssertSuffixInvalid(self):
    dataset = dataset_ops.Dataset.from_tensors(0).apply(
        optimization.assert_next(["Whoops"])).map(lambda x: x)
    iterator = dataset.make_one_shot_iterator()
    get_next = iterator.get_next()

    with self.test_session() as sess:
      with self.assertRaisesRegexp(
          errors.InvalidArgumentError,
          "Asserted Whoops transformation at offset 0 but encountered "
          "Map transformation instead."):
        sess.run(get_next)
开发者ID:ZhangXinNan,项目名称:tensorflow,代码行数:12,代码来源:optimize_dataset_op_test.py


示例10: testAdditionalInputs

  def testAdditionalInputs(self):
    a = constant_op.constant(1, dtype=dtypes.float32)
    b = constant_op.constant(0, dtype=dtypes.float32)
    some_tensor = math_ops.mul(a, b)

    def random_with_capture(_):
      return some_tensor + random_ops.random_uniform(
          [], minval=1, maxval=10, dtype=dtypes.float32, seed=42)

    dataset = dataset_ops.Dataset.range(5).apply(
        optimization.assert_next(
            ["Zip[0]", "Map"])).map(random_with_capture).apply(
                optimization.optimize(["hoist_random_uniform"]))
    self._testDataset(dataset)
开发者ID:baojianzhou,项目名称:tensorflow,代码行数:14,代码来源:hoist_random_uniform_test.py


示例11: testAdditionalInputs

  def testAdditionalInputs(self):
    a = constant_op.constant(3, dtype=dtypes.int64)
    b = constant_op.constant(4, dtype=dtypes.int64)
    some_tensor = math_ops.mul(a, b)
    function = lambda x: x * x

    def predicate(y):
      return math_ops.less(math_ops.cast(y, dtypes.int64), some_tensor)

    # We are currently not supporting functions with additional inputs.
    dataset = dataset_ops.Dataset.range(10).apply(
        optimization.assert_next(
            ["Map", "Filter"])).map(function).filter(predicate).apply(
                optimization.optimize(["map_and_filter_fusion"]))

    self._testMapAndFilter(dataset, function, predicate)
开发者ID:AnishShah,项目名称:tensorflow,代码行数:16,代码来源:map_and_filter_fusion_test.py


示例12: testMapParallelization

  def testMapParallelization(self, function, should_optimize):
    next_nodes = ["ParallelMap"] if should_optimize else ["Map"]
    dataset = dataset_ops.Dataset.range(5).apply(
        optimization.assert_next(next_nodes)).map(function).apply(
            optimization.optimize(["map_parallelization"]))
    iterator = dataset.make_one_shot_iterator()
    get_next = iterator.get_next()

    with self.test_session() as sess:
      for x in range(5):
        result = sess.run(get_next)
        # No need to run the pipeline if it was not optimized.  Also the results
        # might be hard to check because of random.
        if not should_optimize:
          return
        r = function(x)
        self.assertAllEqual(r, result)

      with self.assertRaises(errors.OutOfRangeError):
        sess.run(get_next)
开发者ID:Jordan1237,项目名称:tensorflow,代码行数:20,代码来源:map_parallelization_test.py


示例13: testMapFusion

  def testMapFusion(self, functions):
    dataset = dataset_ops.Dataset.range(5).apply(
        optimization.assert_next(["Map", "Prefetch"]))
    for function in functions:
      dataset = dataset.map(function)

    dataset = dataset.prefetch(0).apply(optimization.optimize(["map_fusion"]))
    iterator = dataset.make_one_shot_iterator()
    get_next = iterator.get_next()
    with self.cached_session() as sess:
      for x in range(5):
        result = sess.run(get_next)
        r = x
        for function in functions:
          if isinstance(r, tuple):
            r = function(*r)  # Pass tuple as multiple arguments.
          else:
            r = function(r)
        self.assertAllEqual(r, result)

      with self.assertRaises(errors.OutOfRangeError):
        sess.run(get_next)
开发者ID:AnishShah,项目名称:tensorflow,代码行数:22,代码来源:map_and_filter_fusion_test.py


示例14: testNoopElimination

  def testNoopElimination(self):
    a = constant_op.constant(1, dtype=dtypes.int64)
    b = constant_op.constant(2, dtype=dtypes.int64)
    some_tensor = math_ops.mul(a, b)

    dataset = dataset_ops.Dataset.range(5)
    dataset = dataset.apply(
        optimization.assert_next(
            ["FiniteRepeat", "FiniteSkip", "Prefetch", "Prefetch"]))
    dataset = dataset.repeat(some_tensor).skip(5).prefetch(0).take(-1).skip(
        0).repeat(1).prefetch(0)
    dataset = dataset.apply(optimization.optimize(["noop_elimination"]))

    iterator = dataset.make_one_shot_iterator()
    get_next = iterator.get_next()

    with self.test_session() as sess:
      for x in range(5):
        result = sess.run(get_next)
        self.assertAllEqual(result, x)

      with self.assertRaises(errors.OutOfRangeError):
        sess.run(get_next)
开发者ID:baojianzhou,项目名称:tensorflow,代码行数:23,代码来源:noop_elimination_test.py


示例15: _make_dataset

 def _make_dataset(node_names):
   return base_dataset.apply(optimization.assert_next(node_names)).map(
       map_fn, num_parallel_calls=num_parallel_calls).batch(batch_size)
开发者ID:AnishShah,项目名称:tensorflow,代码行数:3,代码来源:map_vectorization_test.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python optimization.optimize函数代码示例发布时间:2022-05-27
下一篇:
Python interleave_ops.parallel_interleave函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap