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

Python api.converted_call函数代码示例

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

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



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

示例1: test_fn

    def test_fn():
      res = TestResource()

      def f(y):
        return res.x + y

      opts = converter.ConversionOptions(recursive=True)
      api.converted_call(f, None, opts, (1,), {})
开发者ID:aritratony,项目名称:tensorflow,代码行数:8,代码来源:api_test.py


示例2: test_converted_call_builtin

  def test_converted_call_builtin(self):
    x = api.converted_call(range, None,
                           converter.ConversionOptions(recursive=True), (3,),
                           {})
    self.assertEqual((0, 1, 2), tuple(x))

    x = api.converted_call('compile', re,
                           converter.ConversionOptions(recursive=True),
                           ('mnas_v4_a.*\\/.*(weights|kernel):0$',), {})
    self.assertIsNotNone(x.match('mnas_v4_a/weights:0'))
开发者ID:aritratony,项目名称:tensorflow,代码行数:10,代码来源:api_test.py


示例3: test_fn

    def test_fn():
      res = TestResource()

      def f(y):

        def inner_f():
          return res.x + y

        return inner_f

      opts = converter.ConversionOptions()
      api.converted_call(f, None, opts, (1,), {})()
开发者ID:perfmjs,项目名称:tensorflow,代码行数:12,代码来源:api_test.py


示例4: test_converted_call_already_converted

  def test_converted_call_already_converted(self):

    def f(x):
      return x == 0

    x = api.converted_call(f, None, converter.ConversionOptions(),
                           (constant_op.constant(0),), {})
    self.assertTrue(self.evaluate(x))

    converted_f = api.to_graph(f)
    x = api.converted_call(converted_f, None, converter.ConversionOptions(),
                           (constant_op.constant(0),), {})
    self.assertTrue(self.evaluate(x))
开发者ID:kylin9872,项目名称:tensorflow,代码行数:13,代码来源:api_test.py


示例5: test_converted_call_already_converted

  def test_converted_call_already_converted(self):

    def f(x):
      return x == 0

    with self.test_session() as sess:
      x = api.converted_call(f, False, False, False, {},
                             constant_op.constant(0))
      self.assertTrue(sess.run(x))

      converted_f = api.to_graph(f)
      x = api.converted_call(converted_f, False, False, False, {},
                             constant_op.constant(0))
      self.assertTrue(sess.run(x))
开发者ID:AnishShah,项目名称:tensorflow,代码行数:14,代码来源:api_test.py


示例6: test_converted_call_already_converted

  def test_converted_call_already_converted(self):

    def f(x):
      return x == 0

    with self.cached_session() as sess:
      x = api.converted_call(f, None, converter.ConversionOptions(),
                             constant_op.constant(0))
      self.assertTrue(sess.run(x))

      converted_f = api.to_graph(f)
      x = api.converted_call(converted_f, None, converter.ConversionOptions(),
                             constant_op.constant(0))
      self.assertTrue(sess.run(x))
开发者ID:abhinav-upadhyay,项目名称:tensorflow,代码行数:14,代码来源:api_test.py


示例7: test_converted_call_already_converted

  def test_converted_call_already_converted(self):

    def f(x):
      return x == 0

    x = api.converted_call(f, None, converter.ConversionOptions(recursive=True),
                           (constant_op.constant(0),), {})
    self.assertTrue(self.evaluate(x))

    converted_f = api.to_graph(
        f, experimental_optional_features=converter.Feature.ALL)
    x = api.converted_call(converted_f, None,
                           converter.ConversionOptions(recursive=True),
                           (constant_op.constant(0),), {})
    self.assertTrue(self.evaluate(x))
开发者ID:aritratony,项目名称:tensorflow,代码行数:15,代码来源:api_test.py


示例8: test_converted_call_numpy

  def test_converted_call_numpy(self):

    opts = converter.ConversionOptions(recursive=True)

    x = api.converted_call(np.arange, None, opts, (5,), {})

    self.assertAllEqual(x, list(range(5)))
开发者ID:aritratony,项目名称:tensorflow,代码行数:7,代码来源:api_test.py


示例9: test_converted_call_no_user_code

  def test_converted_call_no_user_code(self):

    def f(x):
      return len(x)

    opts = converter.ConversionOptions(internal_convert_user_code=False)

    # f should not be converted, causing len to error out.
    with self.assertRaisesRegexp(Exception,
                                 'object of type \'Tensor\' has no len()'):
      api.converted_call(f, None, opts, constant_op.constant([0]))

    # len on the other hand should work fine.
    x = api.converted_call(len, None, opts, constant_op.constant([0]))
    # The constant has static shape so the result is a primitive not a Tensor.
    self.assertEqual(x, 1)
开发者ID:abhinav-upadhyay,项目名称:tensorflow,代码行数:16,代码来源:api_test.py


示例10: test_converted_call_namedtuple

  def test_converted_call_namedtuple(self):

    opts = converter.ConversionOptions()

    x = api.converted_call(collections.namedtuple, None, opts,
                           ('TestNamedtuple', ('a', 'b')), {})

    self.assertTrue(inspect_utils.isnamedtuple(x))
开发者ID:perfmjs,项目名称:tensorflow,代码行数:8,代码来源:api_test.py


示例11: test_converted_call_functools_partial

  def test_converted_call_functools_partial(self):

    def test_fn(x, y, z):
      if x < 0:
        return -x, -y, -z
      return x, y, z

    x = api.converted_call(
        functools.partial(test_fn, constant_op.constant(-1), z=-3), None,
        converter.ConversionOptions(), (constant_op.constant(-2),), {})
    self.assertEqual((1, 2, 3), self.evaluate(x))

    x = api.converted_call(
        functools.partial(
            functools.partial(test_fn, constant_op.constant(-1)), z=-3), None,
        converter.ConversionOptions(), (constant_op.constant(-2),), {})
    self.assertEqual((1, 2, 3), self.evaluate(x))
开发者ID:perfmjs,项目名称:tensorflow,代码行数:17,代码来源:api_test.py


示例12: test_converted_call_namedtuple_via_collections

  def test_converted_call_namedtuple_via_collections(self):

    opts = converter.ConversionOptions(recursive=True)

    x = api.converted_call('namedtuple', collections, opts, ('TestNamedtuple',
                                                             ('a', 'b')), {})

    self.assertTrue(inspect_utils.isnamedtuple(x))
开发者ID:aritratony,项目名称:tensorflow,代码行数:8,代码来源:api_test.py


示例13: test_converted_call_tf_op_forced

  def test_converted_call_tf_op_forced(self):

    # TODO(mdan): Add the missing level of support to LOGICAL_EXPRESSIONS.
    opts = converter.ConversionOptions(
        force_conversion=True, optional_features=None)

    x = api.converted_call(gen_math_ops.add, None, opts, (1, 1), {})

    self.assertAllEqual(self.evaluate(x), 2)
开发者ID:aritratony,项目名称:tensorflow,代码行数:9,代码来源:api_test.py


示例14: test_converted_call_no_kwargs_allowed

  def test_converted_call_no_kwargs_allowed(self):

    def f(*args):
      # Note: np.broadcast rejects any **kwargs, even *{}
      return np.broadcast(args[:1])

    opts = converter.ConversionOptions(internal_convert_user_code=False)

    self.assertIsNotNone(api.converted_call(f, None, opts, (1, 2, 3, 4), None))
开发者ID:aritratony,项目名称:tensorflow,代码行数:9,代码来源:api_test.py


示例15: test_converted_call_function

  def test_converted_call_function(self):

    def test_fn(x):
      if x < 0:
        return -x
      return x

    x = api.converted_call(test_fn, None, converter.ConversionOptions(),
                           (constant_op.constant(-1),), {})
    self.assertEqual(1, self.evaluate(x))
开发者ID:perfmjs,项目名称:tensorflow,代码行数:10,代码来源:api_test.py


示例16: test_converted_call_lambda

  def test_converted_call_lambda(self):

    opts = converter.ConversionOptions(recursive=True)

    l = lambda x: x == 0

    x = api.converted_call(l, None, opts, (constant_op.constant(0),), {})

    self.evaluate(variables.global_variables_initializer())
    self.assertAllEqual(True, self.evaluate(x))
开发者ID:aritratony,项目名称:tensorflow,代码行数:10,代码来源:api_test.py


示例17: test_converted_call_lambda

  def test_converted_call_lambda(self):

    opts = converter.ConversionOptions()

    l = lambda x: x == 0

    x = api.converted_call(l, None, opts, constant_op.constant(0))

    with self.cached_session() as sess:
      sess.run(variables.global_variables_initializer())
      self.assertAllEqual(True, sess.run(x))
开发者ID:abhinav-upadhyay,项目名称:tensorflow,代码行数:11,代码来源:api_test.py


示例18: test_converted_call_function

  def test_converted_call_function(self):

    def test_fn(x):
      if x < 0:
        return -x
      return x

    with self.cached_session() as sess:
      x = api.converted_call(test_fn, None, converter.ConversionOptions(),
                             constant_op.constant(-1))
      self.assertEqual(1, sess.run(x))
开发者ID:abhinav-upadhyay,项目名称:tensorflow,代码行数:11,代码来源:api_test.py


示例19: test_converted_call_function

  def test_converted_call_function(self):

    def test_fn(x):
      if x < 0:
        return -x
      return x

    with self.test_session() as sess:
      x = api.converted_call(test_fn, False, False, False, {},
                             constant_op.constant(-1))
      self.assertEqual(1, sess.run(x))
开发者ID:AnishShah,项目名称:tensorflow,代码行数:11,代码来源:api_test.py


示例20: test_converted_call_exec_generated_code

  def test_converted_call_exec_generated_code(self):

    temp_mod = imp.new_module('test_module')
    dynamic_code = '''
      def foo(x):
        return x + 1
    '''
    exec(textwrap.dedent(dynamic_code), temp_mod.__dict__)  # pylint:disable=exec-used
    opts = converter.ConversionOptions(optional_features=None)

    x = api.converted_call(temp_mod.foo, None, opts, (1,), {})

    self.assertAllEqual(x, 2)
开发者ID:aritratony,项目名称:tensorflow,代码行数:13,代码来源:api_test.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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