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


Python tensorflow.variable_op_scope方法代碼示例

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


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

示例1: join

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import variable_op_scope [as 別名]
def join(columns,
         coin):
  """Takes mean of the columns, applies drop path if
     `tflearn.get_training_mode()` is True.

  Args:
    columns: columns of fractal block.
    is_training: boolean in tensor form. Determines whether drop path
      should be used.
    coin: boolean in tensor form. Determines whether drop path is
     local or global.
  """
  if len(columns)==1:
    return columns[0]
  with tf.variable_op_scope(columns, None, "Join"):
    columns = tf.convert_to_tensor(columns)
    columns = tf.cond(tflearn.get_training_mode(),
                      lambda: drop_path(columns, coin),
                      lambda: columns)
    out = tf.reduce_mean(columns, 0)
  return out 
開發者ID:tensorpro,項目名稱:FractalNet,代碼行數:23,代碼來源:fractal_block.py

示例2: repeat_op

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import variable_op_scope [as 別名]
def repeat_op(repetitions, inputs, op, *args, **kwargs):
  """Build a sequential Tower starting from inputs by using an op repeatedly.

  It creates new scopes for each operation by increasing the counter.
  Example: given repeat_op(3, _, ops.conv2d, 64, [3, 3], scope='conv1')
    it will repeat the given op under the following variable_scopes:
      conv1/Conv
      conv1/Conv_1
      conv1/Conv_2

  Args:
    repetitions: number or repetitions.
    inputs: a tensor of size [batch_size, height, width, channels].
    op: an operation.
    *args: args for the op.
    **kwargs: kwargs for the op.

  Returns:
    a tensor result of applying the operation op, num times.
  Raises:
    ValueError: if the op is unknown or wrong.
  """
  scope = kwargs.pop('scope', None)
  with tf.variable_op_scope([inputs], scope, 'RepeatOp'):
    tower = inputs
    for _ in range(repetitions):
      tower = op(tower, *args, **kwargs)
    return tower 
開發者ID:Cyber-Neuron,項目名稱:inception_v3,代碼行數:30,代碼來源:ops.py

示例3: coin_flip

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import variable_op_scope [as 別名]
def coin_flip(prob=.5):
  """Random boolean variable, with `prob` chance of being true.

  Used to choose between local and global drop path.

  Args:
    prob:float, probability of being True.
  """
  with tf.variable_op_scope([],None,"CoinFlip"):
    coin = tf.random_uniform([1])[0]>prob
  return coin 
開發者ID:tensorpro,項目名稱:FractalNet,代碼行數:13,代碼來源:fractal_block.py

示例4: drop_path

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import variable_op_scope [as 別名]
def drop_path(columns,
              coin):
  with tf.variable_op_scope([columns], None, "DropPath"):
    out = tf.cond(coin,
                  lambda : drop_some(columns),
                  lambda : random_column(columns))
  return out 
開發者ID:tensorpro,項目名稱:FractalNet,代碼行數:9,代碼來源:fractal_block.py

示例5: policy

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import variable_op_scope [as 別名]
def policy(obs, theta, name='policy'):
    with tf.variable_op_scope([obs], name, name):
        h0 = tf.identity(obs, name='h0-obs')
        h1 = tf.nn.relu(tf.matmul(h0, theta[0]) + theta[1], name='h1')
        h2 = tf.nn.relu(tf.matmul(h1, theta[2]) + theta[3], name='h2')
        h3 = tf.identity(tf.matmul(h2, theta[4]) + theta[5], name='h3')
        action = tf.nn.tanh(h3, name='h4-action')
        return action 
開發者ID:locuslab,項目名稱:icnn,代碼行數:10,代碼來源:ddpg_nets_dm.py

示例6: qfunction

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import variable_op_scope [as 別名]
def qfunction(obs, act, theta, name="qfunction"):
    with tf.variable_op_scope([obs, act], name, name):
        h0 = tf.identity(obs, name='h0-obs')
        h0a = tf.identity(act, name='h0-act')
        h1 = tf.nn.relu(tf.matmul(h0, theta[0]) + theta[1], name='h1')
        h1a = tf.concat(1, [h1, act])
        h2 = tf.nn.relu(tf.matmul(h1a, theta[2]) + theta[3], name='h2')
        qs = tf.matmul(h2, theta[4]) + theta[5]
        q = tf.squeeze(qs, [1], name='h3-q')
        return q 
開發者ID:locuslab,項目名稱:icnn,代碼行數:12,代碼來源:ddpg_nets_dm.py

示例7: fractal_template

# 需要導入模塊: import tensorflow [as 別名]
# 或者: from tensorflow import variable_op_scope [as 別名]
def fractal_template(inputs,
                     num_columns,
                     block_fn,
                     block_asc,
                     joined=True,
                     is_training=True,
                     reuse=False,
                     scope=None):
  """Template for making fractal blocks.

  Given a function and a corresponding arg_scope `fractal_template`
  will build a truncated fractal with `num_columns` columns.

  Args:
    inputs: a 4-D tensor  `[batch_size, height, width, channels]`.
    num_columns: integer, the columns in the fractal.
    block_fn: function to be called within each fractal.
    block_as: A function that returns argscope for `block_fn`.
    joined: boolean, whether the output columns should be joined.
    reuse: whether or not the layer and its variables should be reused. To be
      able to reuse the layer scope must be given.
    scope: Optional scope for `variable_scope`.
  """

  def fractal_expand(inputs, num_columns, joined):
    '''Recursive Helper Function for making fractal'''
    with block_asc():
      output = lambda cols: join(cols, coin) if joined else cols
      if num_columns == 1:
        return output([block_fn(inputs)])
      left = block_fn(inputs)
      right = fractal_expand(inputs, num_columns-1, joined=True)
      right = fractal_expand(right, num_columns-1, joined=False)
      cols=[left]+right
    return output(cols)

  with tf.variable_op_scope([inputs], scope, 'Fractal',
                            reuse=reuse) as scope:
    coin = coin_flip()
    net=fractal_expand(inputs, num_columns, joined)

  return net 
開發者ID:tensorpro,項目名稱:FractalNet,代碼行數:44,代碼來源:fractal_block.py


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