<i id='u1H52'><tr id='u1H52'><dt id='u1H52'><q id='u1H52'><span id='u1H52'><b id='u1H52'><form id='u1H52'><ins id='u1H52'></ins><ul id='u1H52'></ul><sub id='u1H52'></sub></form><legend id='u1H52'></legend><bdo id='u1H52'><pre id='u1H52'><center id='u1H52'></center></pre></bdo></b><th id='u1H52'></th></span></q></dt></tr></i><div id='u1H52'><tfoot id='u1H52'></tfoot><dl id='u1H52'><fieldset id='u1H52'></fieldset></dl></div>

    • <bdo id='u1H52'></bdo><ul id='u1H52'></ul>
    <tfoot id='u1H52'></tfoot>
    <legend id='u1H52'><style id='u1H52'><dir id='u1H52'><q id='u1H52'></q></dir></style></legend>
  • <small id='u1H52'></small><noframes id='u1H52'>

        具有渴望模式的 TF.data.dataset.map(map_func)

        TF.data.dataset.map(map_func) with Eager Mode(具有渴望模式的 TF.data.dataset.map(map_func))

        <small id='yWpc8'></small><noframes id='yWpc8'>

      1. <legend id='yWpc8'><style id='yWpc8'><dir id='yWpc8'><q id='yWpc8'></q></dir></style></legend>
          <tbody id='yWpc8'></tbody>
        <i id='yWpc8'><tr id='yWpc8'><dt id='yWpc8'><q id='yWpc8'><span id='yWpc8'><b id='yWpc8'><form id='yWpc8'><ins id='yWpc8'></ins><ul id='yWpc8'></ul><sub id='yWpc8'></sub></form><legend id='yWpc8'></legend><bdo id='yWpc8'><pre id='yWpc8'><center id='yWpc8'></center></pre></bdo></b><th id='yWpc8'></th></span></q></dt></tr></i><div id='yWpc8'><tfoot id='yWpc8'></tfoot><dl id='yWpc8'><fieldset id='yWpc8'></fieldset></dl></div>

          • <bdo id='yWpc8'></bdo><ul id='yWpc8'></ul>

              <tfoot id='yWpc8'></tfoot>
                  本文介绍了具有渴望模式的 TF.data.dataset.map(map_func)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用启用了 Eager 模式的 TF 1.8.

                  I am using TF 1.8 with eager mode enabled.

                  我无法在 mapfunc 中打印示例.当我从 mapfunc 中运行 tf.executing_eagerly() 时,我得到False"

                  I cannot print the example inside the mapfunc. It when I run tf.executing_eagerly() from within the mapfunc I get "False"

                  import os
                  import tensorflow as tf
                  tf.logging.set_verbosity(tf.logging.ERROR)
                  
                  tfe = tf.contrib.eager
                  tf.enable_eager_execution()
                  x = tf.random_uniform([16,10], -10, 0, tf.int64)
                  print(x)
                  DS = tf.data.Dataset.from_tensor_slices((x))
                  
                  
                  def mapfunc(ex, con):
                      import pdb; pdb.set_trace()
                      new_ex = ex + con
                      print(new_ex) 
                      return new_ex
                  
                  DS = DS.map(lambda x: mapfunc(x, [7]))
                  DS = DS.make_one_shot_iterator()
                  
                  print(DS.next())
                  

                  print(new_ex) 输出:

                  print(new_ex) outputs:

                  Tensor("add:0", shape=(10,), dtype=int64)
                  

                  在 mapfunc 之外,它工作正常.但在其中,传递的示例没有值,也没有 .numpy() 属性.

                  Outside mapfunc, it works fine. But inside it, the passed example does not have a value, nor .numpy() attribute.

                  推荐答案

                  tf.data 转换实际上是作为图形执行的,因此 map 函数本身并不会急切地执行.有关此问题的更多讨论,请参阅 #14732.

                  The tf.data transformations actually execute as a graph, so the body of the map function itself isn't executed eagerly. See #14732 for some more discussion on this.

                  如果你真的需要 map 函数的急切执行,你可以使用 tf.contrib.eager.py_func,比如:

                  If you really need eager execution for the map function, you could use tf.contrib.eager.py_func, so something like:

                  DS = DS.map(lambda x: tf.contrib.eager.py_func(
                    mapfunc,
                    [x, tf.constant(7, dtype=tf.int64)], tf.int64)
                  # In TF 1.9+, the next line can be print(next(DS))
                  print(DS.make_one_shot_iterator().next())
                  

                  希望对您有所帮助.

                  请注意,通过将 py_func 添加到数据集,单线程 Python 解释器将在生成的每个元素的循环中.

                  Note that by adding a py_func to the dataset, the single-threaded Python interpreter will be in the loop for every element produced.

                  这篇关于具有渴望模式的 TF.data.dataset.map(map_func)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Adding config modes to Plotly.Py offline - modebar(将配置模式添加到 Plotly.Py 离线 - 模式栏)
                  Plotly: How to style a plotly figure so that it doesn#39;t display gaps for missing dates?(Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙?)
                  python save plotly plot to local file and insert into html(python将绘图保存到本地文件并插入到html中)
                  Plotly: What color cycle does plotly express follow?(情节:情节表达遵循什么颜色循环?)
                  How to save plotly express plot into a html or static image file?(如何将情节表达图保存到 html 或静态图像文件中?)
                  Plotly: How to make a line plot from a pandas dataframe with a long or wide format?(Plotly:如何使用长格式或宽格式的 pandas 数据框制作线图?)

                    <small id='NANRw'></small><noframes id='NANRw'>

                      • <legend id='NANRw'><style id='NANRw'><dir id='NANRw'><q id='NANRw'></q></dir></style></legend>
                      • <i id='NANRw'><tr id='NANRw'><dt id='NANRw'><q id='NANRw'><span id='NANRw'><b id='NANRw'><form id='NANRw'><ins id='NANRw'></ins><ul id='NANRw'></ul><sub id='NANRw'></sub></form><legend id='NANRw'></legend><bdo id='NANRw'><pre id='NANRw'><center id='NANRw'></center></pre></bdo></b><th id='NANRw'></th></span></q></dt></tr></i><div id='NANRw'><tfoot id='NANRw'></tfoot><dl id='NANRw'><fieldset id='NANRw'></fieldset></dl></div>
                          <tbody id='NANRw'></tbody>

                            <bdo id='NANRw'></bdo><ul id='NANRw'></ul>
                            <tfoot id='NANRw'></tfoot>