當前位置: 首頁>>代碼示例>>Python>>正文


Python sonnet.AbstractModule方法代碼示例

本文整理匯總了Python中sonnet.AbstractModule方法的典型用法代碼示例。如果您正苦於以下問題:Python sonnet.AbstractModule方法的具體用法?Python sonnet.AbstractModule怎麽用?Python sonnet.AbstractModule使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sonnet的用法示例。


在下文中一共展示了sonnet.AbstractModule方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __str__

# 需要導入模塊: import sonnet [as 別名]
# 或者: from sonnet import AbstractModule [as 別名]
def __str__(self):
    if isinstance(self._module, tf.Tensor):
      return str(self._module)
    if isinstance(self._module, types.LambdaType):
      return self._module.__name__
    if isinstance(self._module, snt.AbstractModule):
      return self._module.module_name
    if hasattr(self._module, '__class__'):
      return self._module.__class__.__name__
    return str(self._module) 
開發者ID:deepmind,項目名稱:interval-bound-propagation,代碼行數:12,代碼來源:verifiable_wrapper.py

示例2: __init__

# 需要導入模塊: import sonnet [as 別名]
# 或者: from sonnet import AbstractModule [as 別名]
def __init__(self, *args, **kwargs):
      super(AbstractModule, self).__init__(*args, **kwargs)
      self.__call__.__func__.__doc__ = self._build.__doc__

    # In snt2 calls to `_enter_variable_scope` are ignored. 
開發者ID:deepmind,項目名稱:graph_nets,代碼行數:7,代碼來源:_base.py

示例3: create_variables_in_class_scope

# 需要導入模塊: import sonnet [as 別名]
# 或者: from sonnet import AbstractModule [as 別名]
def create_variables_in_class_scope(method):
  """Force the variables constructed in this class to live in the sonnet module.
  Wraps a method on a sonnet module.

  For example the following will create two different variables.
  ```
  class Mod(snt.AbstractModule):
    @create_variables_in_class_scope
    def dynamic_thing(self, input, name):
      return snt.Linear(name)(input)
  mod.dynamic_thing(x, name="module_nameA")
  mod.dynamic_thing(x, name="module_nameB")
  # reuse
  mod.dynamic_thing(y, name="module_nameA")
  ```
  """
  @functools.wraps(method)
  def wrapper(obj, *args, **kwargs):
    def default_context_manager(reuse=None):
      variable_scope = obj.variable_scope
      return tf.variable_scope(variable_scope, reuse=reuse)

    variable_scope_context_manager = getattr(obj, "_enter_variable_scope",
                                             default_context_manager)
    graph = tf.get_default_graph()

    # Temporarily enter the variable scope to capture it
    with variable_scope_context_manager() as tmp_variable_scope:
      variable_scope = tmp_variable_scope

    with variable_scope_ops._pure_variable_scope(
        variable_scope, reuse=tf.AUTO_REUSE) as pure_variable_scope:

      name_scope = variable_scope.original_name_scope
      if name_scope[-1] != "/":
        name_scope += "/"

      with tf.name_scope(name_scope):
        sub_scope = snt_util.to_snake_case(method.__name__)
        with tf.name_scope(sub_scope) as scope:
          out_ops = method(obj, *args, **kwargs)
          return out_ops

  return wrapper 
開發者ID:itsamitgoel,項目名稱:Gun-Detector,代碼行數:46,代碼來源:utils.py


注:本文中的sonnet.AbstractModule方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。