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

Python optimization.assert_next函数代码示例

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

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



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

示例1: testOptimizationNonSerializable

 def testOptimizationNonSerializable(self):
   dataset = dataset_ops.Dataset.from_tensors(0)
   dataset = dataset.apply(optimization.assert_next(["FiniteSkip"]))
   dataset = dataset.skip(0)  # Should not be removed by noop elimination
   dataset = dataset.apply(optimization.non_serializable())
   dataset = dataset.apply(optimization.assert_next(["MemoryCacheImpl"]))
   dataset = dataset.skip(0)  # Should be removed by noop elimination
   dataset = dataset.cache()
   dataset = dataset_ops._OptimizeDataset(dataset, ["noop_elimination"])
   self.assertDatasetProduces(dataset, expected_output=[0])
开发者ID:JonathanRaiman,项目名称:tensorflow,代码行数:10,代码来源:optimize_dataset_test.py


示例2: testOptimizationNonSerializable

 def testOptimizationNonSerializable(self):
   dataset = dataset_ops.Dataset.from_tensors(0)
   dataset = dataset.apply(optimization.assert_next(["FiniteSkip"]))
   dataset = dataset.skip(0)  # Should not be removed by noop elimination
   dataset = dataset.apply(optimization.non_serializable())
   dataset = dataset.apply(optimization.assert_next(["MemoryCacheImpl"]))
   dataset = dataset.skip(0)  # Should be removed by noop elimination
   dataset = dataset.cache()
   options = dataset_ops.Options()
   options.experimental_optimization.apply_default_optimizations = False
   options.experimental_optimization.noop_elimination = True
   dataset = dataset.with_options(options)
   self.assertDatasetProduces(dataset, expected_output=[0])
开发者ID:rmlarsen,项目名称:tensorflow,代码行数:13,代码来源:optimize_dataset_test.py


示例3: flat_map_fn

 def flat_map_fn(_):
   dataset = dataset_ops.Dataset.from_tensors(0)
   dataset = dataset.apply(optimization.assert_next(["MapAndBatch"]))
   # Should be fused by map and batch fusion
   dataset = dataset.map(lambda x: x)
   dataset = dataset.batch(1)
   return dataset
开发者ID:rmlarsen,项目名称:tensorflow,代码行数:7,代码来源:optimize_dataset_test.py


示例4: 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(
                 stats_ops.set_stats_aggregator(stats_aggregator))
    options = dataset_ops.Options()
    options.experimental_latency_all_edges = True
    dataset = dataset.with_options(options)
    iterator = dataset.make_initializable_iterator()
    get_next = iterator.get_next()
    summary_t = stats_aggregator.get_summary()

    with self.cached_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:ThunderQi,项目名称:tensorflow,代码行数:26,代码来源:latency_all_edges_test.py


示例5: testAssertNext

 def testAssertNext(self):
   dataset = dataset_ops.Dataset.from_tensors(0).apply(
       optimization.assert_next(["Map"])).map(lambda x: x)
   options = dataset_ops.Options()
   options.experimental_optimization.apply_default_optimizations = False
   dataset = dataset.with_options(options)
   self.assertDatasetProduces(dataset, expected_output=[0])
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:7,代码来源:assert_next_dataset_test.py


示例6: 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)
    options = dataset_ops.Options()
    options.experimental_noop_elimination = True
    dataset = dataset.with_options(options)

    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:ThunderQi,项目名称:tensorflow,代码行数:25,代码来源:noop_elimination_test.py


示例7: testFilterFusion

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

    dataset = dataset.cache()
    options = dataset_ops.Options()
    options.experimental_filter_fusion = True
    dataset = dataset.with_options(options)
    iterator = dataset.make_one_shot_iterator()
    get_next = iterator.get_next()
    with self.cached_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:becster,项目名称:tensorflow,代码行数:31,代码来源:filter_fusion_test.py


示例8: testMapFusion

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

    dataset = dataset.cache()
    options = dataset_ops.Options()
    options.experimental_map_fusion = True
    dataset = dataset.with_options(options)
    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:becster,项目名称:tensorflow,代码行数:25,代码来源:map_fusion_test.py


示例9: testFilterFusion

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

    dataset = dataset.cache()
    options = dataset_ops.Options()
    options.experimental_optimization.apply_default_optimizations = False
    options.experimental_optimization.filter_fusion = True
    dataset = dataset.with_options(options)
    expected_output = []
    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 self.evaluate(b):
          filtered = True
          break

      if not filtered:
        expected_output.append(r)
    self.assertDatasetProduces(dataset, expected_output=expected_output)
开发者ID:Wajih-O,项目名称:tensorflow,代码行数:28,代码来源:filter_fusion_test.py


示例10: testMapFilterFusion

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


示例11: 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:becster,项目名称:tensorflow,代码行数:8,代码来源:assert_next_dataset_test.py


示例12: testMakeNumaAware

 def testMakeNumaAware(self):
   dataset = dataset_ops.Dataset.range(10).apply(
       optimization.assert_next(["NumaMapAndBatch"])).apply(
           batching.map_and_batch(lambda x: x * x, 10))
   options = dataset_ops.Options()
   options.experimental_numa_aware = True
   dataset = dataset.with_options(options)
   self.assertDatasetProduces(
       dataset, expected_output=[[x * x for x in range(10)]])
开发者ID:JonathanRaiman,项目名称:tensorflow,代码行数:9,代码来源:make_numa_aware_test.py


示例13: testMapAndBatchFusion

 def testMapAndBatchFusion(self):
   dataset = dataset_ops.Dataset.range(10).apply(
       optimization.assert_next(
           ["MapAndBatch"])).map(lambda x: x * x).batch(10)
   options = dataset_ops.Options()
   options.experimental_map_and_batch_fusion = True
   dataset = dataset.with_options(options)
   self.assertDatasetProduces(
       dataset, expected_output=[[x * x for x in range(10)]])
开发者ID:JonathanRaiman,项目名称:tensorflow,代码行数:9,代码来源:map_and_batch_fusion_test.py


示例14: _make_dataset

 def _make_dataset(node_names):
   dataset = base_dataset.apply(optimization.assert_next(node_names))
   dataset = dataset.map(map_fn, num_parallel_calls)
   dataset = dataset.batch(100)
   options = dataset_ops.Options()
   options.experimental_optimization.apply_default_optimizations = False
   options.experimental_optimization.map_and_batch_fusion = False
   dataset = dataset.with_options(options)
   return dataset
开发者ID:kylin9872,项目名称:tensorflow,代码行数:9,代码来源:map_vectorization_test.py


示例15: 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)

    options = dataset_ops.Options()
    options.experimental_hoist_random_uniform = True
    dataset = dataset.with_options(options)
    self._testDataset(dataset)
开发者ID:ThunderQi,项目名称:tensorflow,代码行数:9,代码来源:hoist_random_uniform_test.py


示例16: testAssertNextInvalid

 def testAssertNextInvalid(self):
   dataset = dataset_ops.Dataset.from_tensors(0).apply(
       optimization.assert_next(["Whoops"])).map(lambda x: x)
   self.assertDatasetProduces(
       dataset,
       expected_error=(
           errors.InvalidArgumentError,
           "Asserted Whoops transformation at offset 0 but encountered "
           "Map transformation instead."))
开发者ID:JonathanRaiman,项目名称:tensorflow,代码行数:9,代码来源:assert_next_dataset_test.py


示例17: 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)
   options = dataset_ops.Options()
   options.experimental_map_parallelization = True
   dataset = dataset.with_options(options)
   if should_optimize:
     self.assertDatasetProduces(
         dataset, expected_output=[function(x) for x in range(5)])
开发者ID:JonathanRaiman,项目名称:tensorflow,代码行数:10,代码来源:map_parallelization_test.py


示例18: 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:becster,项目名称:tensorflow,代码行数:11,代码来源:assert_next_dataset_test.py


示例19: testAssertNextShort

 def testAssertNextShort(self):
   dataset = dataset_ops.Dataset.from_tensors(0).apply(
       optimization.assert_next(["Map", "Whoops"])).map(lambda x: x)
   options = dataset_ops.Options()
   options.experimental_autotune = False
   dataset = dataset.with_options(options)
   self.assertDatasetProduces(
       dataset,
       expected_error=(
           errors.InvalidArgumentError,
           "Asserted next 2 transformations but encountered only 1."))
开发者ID:JonathanRaiman,项目名称:tensorflow,代码行数:11,代码来源:assert_next_dataset_test.py


示例20: testOptimizationDefault

  def testOptimizationDefault(self):
    dataset = dataset_ops.Dataset.range(10).apply(
        optimization.assert_next(["Map",
                                  "Batch"])).map(lambda x: x * x).batch(10)
    iterator = dataset.with_options(
        dataset_ops.Options()).make_one_shot_iterator()
    get_next = iterator.get_next()

    with self.cached_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:gunan,项目名称:tensorflow,代码行数:12,代码来源:optimize_dataset_op_test.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python prefetching_ops.copy_to_device函数代码示例发布时间:2022-05-27
下一篇:
Python map_defun.map_defun函数代码示例发布时间: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