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


Python variable_scope._get_default_variable_store方法代碼示例

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


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

示例1: load_from_pytorch_checkpoint

# 需要導入模塊: from tensorflow.python.ops import variable_scope [as 別名]
# 或者: from tensorflow.python.ops.variable_scope import _get_default_variable_store [as 別名]
def load_from_pytorch_checkpoint(checkpoint, assignment_map):
    pytorch_model = torch.load(checkpoint, map_location='cpu')
    pt_model_with_tf_keys = my_convert_keys(pytorch_model)
    for _, name in assignment_map.items():
        store_vars = vs._get_default_variable_store()._vars
        var = store_vars.get(name, None)
        assert var is not None
        if name not in pt_model_with_tf_keys:
            print('WARNING:', name, 'not found in original model.')
            continue
        array = pt_model_with_tf_keys[name].cpu().numpy()
        if any([x in name for x in tensors_to_transpose]):
            array = array.transpose()
        assert tuple(var.get_shape().as_list()) == tuple(array.shape)
        init_value = ops.convert_to_tensor(array, dtype=np.float32)
        var._initial_value = init_value
        var._initializer_op = var.assign(init_value) 
開發者ID:mandarjoshi90,項目名稱:coref,代碼行數:19,代碼來源:pytorch_to_tf.py

示例2: getvar

# 需要導入模塊: from tensorflow.python.ops import variable_scope [as 別名]
# 或者: from tensorflow.python.ops.variable_scope import _get_default_variable_store [as 別名]
def getvar(
      self,
      getter,
      name,
      shape=None,
      dtype=None,
      initializer=None,
      reuse=None,
      trainable=True,
      collections=None,  # pylint: disable=redefined-outer-name
      use_resource=None,
      **kwargs):
    """A custom variable getter."""
    # Here, we switch the default graph to the outer graph and ask the
    # variable scope in which the function is defined to give us the
    # variable. The variable is stashed in extra_vars and returned to
    # the caller.
    #
    # We capture these variables so that the variable definition is
    # hoisted upward to the outer most graph.
    with self._outer_graph.as_default():
      # pylint: disable=protected-access
      var = self._vscope.get_variable(
          vs._get_default_variable_store(),
          name,
          shape=shape,
          dtype=dtype,
          initializer=initializer,
          reuse=reuse,
          trainable=trainable,
          collections=collections,
          use_resource=use_resource)
      self.extra_vars.append(var)
      if isinstance(var, resource_variable_ops.ResourceVariable):
        # For resource-based variables read the variable outside the function
        # and pass in the value. This ensures that the function is pure and
        # differentiable. TODO(apassos) this may have performance problems if
        # the function will only do embedding lookups on the variable.
        return var.value()
      return var 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:42,代碼來源:function.py

示例3: getvar

# 需要導入模塊: from tensorflow.python.ops import variable_scope [as 別名]
# 或者: from tensorflow.python.ops.variable_scope import _get_default_variable_store [as 別名]
def getvar(self,
             getter,
             name,
             shape=None,
             dtype=None,
             initializer=None,
             trainable=True,
             collections=None,
             **kwargs):
    """A custom variable getter."""
    # Here, we switch the default graph to the outer graph and ask the
    # variable scope in which the function is defined to give us the
    # variable. The variable is stashed in extra_vars and returned to
    # the caller.
    #
    # We capture these variables so that the variable definition is
    # hoisted upward to the outer most graph.
    with self._outer_graph.as_default():
      # pylint: disable=protected-access
      var = self._vscope.get_variable(
          vs._get_default_variable_store(),
          name,
          shape=shape,
          dtype=dtype,
          initializer=initializer,
          trainable=trainable,
          collections=collections)
      self.extra_vars.append(var)
      return var 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:31,代碼來源:function.py

示例4: testGetVar

# 需要導入模塊: from tensorflow.python.ops import variable_scope [as 別名]
# 或者: from tensorflow.python.ops.variable_scope import _get_default_variable_store [as 別名]
def testGetVar(self):
    vs = variable_scope._get_default_variable_store()
    v = vs.get_variable("v", [1])
    v1 = vs.get_variable("v", [1])
    assert v == v1 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:7,代碼來源:variable_scope_test.py

示例5: testNameExists

# 需要導入模塊: from tensorflow.python.ops import variable_scope [as 別名]
# 或者: from tensorflow.python.ops.variable_scope import _get_default_variable_store [as 別名]
def testNameExists(self):
    vs = variable_scope._get_default_variable_store()
    # No check by default, so we can both create and get existing names.
    v = vs.get_variable("v", [1])
    v1 = vs.get_variable("v", [1])
    assert v == v1
    # When reuse is False, we fail when variables are already there.
    vs.get_variable("w", [1], reuse=False)  # That's ok.
    with self.assertRaises(ValueError):
      vs.get_variable("v", [1], reuse=False)  # That fails.
    # When reuse is True, we fail when variables are new.
    vs.get_variable("v", [1], reuse=True)  # That's ok.
    with self.assertRaises(ValueError):
      vs.get_variable("u", [1], reuse=True)  # That fails. 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:16,代碼來源:variable_scope_test.py

示例6: testNamelessStore

# 需要導入模塊: from tensorflow.python.ops import variable_scope [as 別名]
# 或者: from tensorflow.python.ops.variable_scope import _get_default_variable_store [as 別名]
def testNamelessStore(self):
    vs = variable_scope._get_default_variable_store()
    vs.get_variable("v1", [2])
    vs.get_variable("v2", [2])
    expected_names = ["%s:0" % name for name in ["v1", "v2"]]
    self.assertEqual(set(expected_names),
                     set([v.name for v in vs._vars.values()])) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:9,代碼來源:variable_scope_test.py

示例7: getvar

# 需要導入模塊: from tensorflow.python.ops import variable_scope [as 別名]
# 或者: from tensorflow.python.ops.variable_scope import _get_default_variable_store [as 別名]
def getvar(self,
             name,
             shape=None,
             dtype=None,
             initializer=None,
             trainable=True,
             collections=None,
             **kwargs):
    """A custom variable getter."""
    # Here, we switch the default graph to the outer graph and ask the
    # variable scope in which the function is defined to give us the
    # variable. The variable is stashed in extra_vars and returned to
    # the caller.
    #
    # We capture these variables so that the variable definition is
    # hoisted upward to the outer most graph.
    with self._outer_graph.as_default():
      # pylint: disable=protected-access
      var = self._vscope.get_variable(
          vs._get_default_variable_store(),
          name,
          shape=shape,
          dtype=dtype,
          initializer=initializer,
          trainable=trainable,
          collections=collections)
      self.extra_vars.append(var)
      return var 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:30,代碼來源:function.py

示例8: _default_initializer

# 需要導入模塊: from tensorflow.python.ops import variable_scope [as 別名]
# 或者: from tensorflow.python.ops.variable_scope import _get_default_variable_store [as 別名]
def _default_initializer(name, shape, dtype):
  """The default initializer for variables."""
  # pylint: disable=protected-access
  store = variable_scope._get_default_variable_store()
  initializer = store._get_default_initializer(name, shape=shape, dtype=dtype)
  # pylint: enable=protected-access
  return initializer[0] 
開發者ID:PacktPublishing,項目名稱:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代碼行數:9,代碼來源:graph_callable.py


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