当前位置: 首页>>代码示例>>Python>>正文


Python tensorflow.expm1方法代码示例

本文整理汇总了Python中tensorflow.expm1方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow.expm1方法的具体用法?Python tensorflow.expm1怎么用?Python tensorflow.expm1使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorflow的用法示例。


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

示例1: bottleneck

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import expm1 [as 别名]
def bottleneck(self, x):
    hparams = self.hparams
    z_size = hparams.bottleneck_bits
    x_shape = common_layers.shape_list(x)
    with tf.variable_scope("vae"):
      mu = tf.layers.dense(x, z_size, name="mu")
      if hparams.mode != tf.estimator.ModeKeys.TRAIN:
        return mu, 0.0  # No sampling or kl loss on eval.
      log_sigma = tf.layers.dense(x, z_size, name="log_sigma")
      epsilon = tf.random_normal(x_shape[:-1] + [z_size])
      z = mu + tf.exp(log_sigma / 2) * epsilon
      kl = 0.5 * tf.reduce_mean(
          tf.expm1(log_sigma) + tf.square(mu) - log_sigma, axis=-1)
      free_bits = z_size // 4
      kl_loss = tf.reduce_mean(tf.maximum(kl - free_bits, 0.0))
    return z, kl_loss * hparams.kl_beta 
开发者ID:yyht,项目名称:BERT,代码行数:18,代码来源:autoencoders.py

示例2: vae

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import expm1 [as 别名]
def vae(x, z_size, name=None):
  """Simple variational autoencoder without discretization.

  Args:
    x: Input to the discretization bottleneck.
    z_size: Number of bits, where discrete codes range from 1 to 2**z_size.
    name: Name for the bottleneck scope.

  Returns:
    Embedding function, latent, loss, mu and log_simga.
  """
  with tf.variable_scope(name, default_name="vae"):
    mu = tf.layers.dense(x, z_size, name="mu")
    log_sigma = tf.layers.dense(x, z_size, name="log_sigma")
    shape = common_layers.shape_list(x)
    epsilon = tf.random_normal([shape[0], shape[1], 1, z_size])
    z = mu + tf.exp(log_sigma / 2) * epsilon
    kl = 0.5 * tf.reduce_mean(
        tf.expm1(log_sigma) + tf.square(mu) - log_sigma, axis=-1)
    free_bits = z_size // 4
    kl_loss = tf.reduce_mean(tf.maximum(kl - free_bits, 0.0))
    return z, kl_loss, mu, log_sigma 
开发者ID:yyht,项目名称:BERT,代码行数:24,代码来源:discretization.py

示例3: denorm

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import expm1 [as 别名]
def denorm(logmagnitude):
    return tf.expm1(logmagnitude) 
开发者ID:Veleslavia,项目名称:vimss,代码行数:4,代码来源:Input.py

示例4: denorm

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import expm1 [as 别名]
def denorm(logmagnitude):
    '''
    Exp(logmagnitude) - 1
    :param logmagnitude: Log-normalized magnitude spectrogram
    :return: Unnormalized magnitude spectrogram
    '''
    return tf.expm1(logmagnitude) 
开发者ID:f90,项目名称:AdversarialAudioSeparation,代码行数:9,代码来源:Input.py

示例5: signed_expm1

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import expm1 [as 别名]
def signed_expm1(inputs):
  return tf.multiply(tf.sign(inputs), tf.expm1(tf.abs(inputs))) 
开发者ID:DeepBlender,项目名称:DeepDenoiser,代码行数:4,代码来源:Utilities.py

示例6: sonify

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import expm1 [as 别名]
def sonify(spectrogram, samples, transform_op_fn, logscaled=True):
    graph = tf.Graph()
    with graph.as_default():

        noise = tf.Variable(tf.random_normal([samples], stddev=1e-6))

        x = transform_op_fn(noise)
        y = spectrogram

        if logscaled:
            x = tf.expm1(x)
            y = tf.expm1(y)

        x = tf.nn.l2_normalize(x)
        y = tf.nn.l2_normalize(y)
        tf.losses.mean_squared_error(x, y[-tf.shape(x)[0]:])

        optimizer = tf.contrib.opt.ScipyOptimizerInterface(
            loss=tf.losses.get_total_loss(),
            var_list=[noise],
            tol=1e-16,
            method='L-BFGS-B',
            options={
                'maxiter': 1000,
                'disp': True
            })

    with tf.Session(graph=graph) as session:
        session.run(tf.global_variables_initializer())
        optimizer.minimize(session)
        waveform = session.run(noise)

    return waveform 
开发者ID:kastnerkyle,项目名称:representation_mixing,代码行数:35,代码来源:magrecnp.py

示例7: sonify

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import expm1 [as 别名]
def sonify(spectrogram, samples, transform_op_fn, logscaled=True):
    graph = tf.Graph()
    with graph.as_default():

        noise = tf.Variable(tf.random_normal([samples], stddev=1e-6))

        x = transform_op_fn(noise)
        y = spectrogram

        if logscaled:
            x = tf.expm1(x)
            y = tf.expm1(y)

        # tf.nn.normalize arguments changed between versions...
        def normalize(a):
            return a / tf.sqrt(tf.maximum(tf.reduce_sum(a ** 2, axis=0), 1E-12))

        x = normalize(x)
        y = normalize(y)
        tf.losses.mean_squared_error(x, y[-tf.shape(x)[0]:])

        optimizer = tf.contrib.opt.ScipyOptimizerInterface(
            loss=tf.losses.get_total_loss(),
            var_list=[noise],
            tol=1e-16,
            method='L-BFGS-B',
            options={
                'maxiter': sonify_steps,
                'disp': True
            })

    # THIS REALLY SHOULDN'T RUN ON GPU BUT SEEMS TO?
    config = tf.ConfigProto(
        device_count={'CPU' : 1, 'GPU' : 0},
        allow_soft_placement=True,
        log_device_placement=False
        )
    with tf.Session(config=config, graph=graph) as session:
        session.run(tf.global_variables_initializer())
        optimizer.minimize(session)
        waveform = session.run(noise)
    return waveform 
开发者ID:kastnerkyle,项目名称:representation_mixing,代码行数:44,代码来源:sample_rnn_unaligned_speech_ljspeech.py


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