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


Python tensorflow.real方法代码示例

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


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

示例1: __init__

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import real [as 别名]
def __init__(self, layer, mask, temperature, **kwargs):
    """Constructs flow.

    Args:
      layer: Two-headed masked network taking the inputs and returning a
        real-valued Tensor of shape `[..., length, 2*vocab_size]`.
        Alternatively, `layer` may return a Tensor of shape
        `[..., length, vocab_size]` to be used as the location transform; the
        scale transform will be hard-coded to 1.
      mask: binary Tensor of shape `[length]` forming the bipartite assignment.
      temperature: Positive value determining bias of gradient estimator.
      **kwargs: kwargs of parent class.
    """
    super(DiscreteBipartiteFlow, self).__init__(**kwargs)
    self.layer = layer
    self.mask = mask
    self.temperature = temperature 
开发者ID:yyht,项目名称:BERT,代码行数:19,代码来源:reversible_layers.py

示例2: one_hot_add

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import real [as 别名]
def one_hot_add(inputs, shift):
  """Performs (inputs + shift) % vocab_size in the one-hot space.

  Args:
    inputs: Tensor of shape `[..., vocab_size]`. Typically a soft/hard one-hot
      Tensor.
    shift: Tensor of shape `[..., vocab_size]`. Typically a soft/hard one-hot
      Tensor specifying how much to shift the corresponding one-hot vector in
      inputs. Soft values perform a "weighted shift": for example,
      shift=[0.2, 0.3, 0.5] performs a linear combination of 0.2 * shifting by
      zero; 0.3 * shifting by one; and 0.5 * shifting by two.

  Returns:
    Tensor of same shape and dtype as inputs.
  """
  # Compute circular 1-D convolution with shift as the kernel.
  inputs = tf.cast(inputs, tf.complex64)
  shift = tf.cast(shift, tf.complex64)
  return tf.real(tf.signal.ifft(tf.signal.fft(inputs) * tf.signal.fft(shift))) 
开发者ID:yyht,项目名称:BERT,代码行数:21,代码来源:reversible_layers.py

示例3: trace_distance

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import real [as 别名]
def trace_distance(rho, sigma):
    r""" Trace distance :math:`\frac{1}{2}\tr \{ \sqrt{ (\rho - \sigma})^2  \}` between quantum states :math:`\rho` and :math:`\sigma`.

    The inputs and outputs are tensors of dtype float, and all computations support automatic differentiation.

    Args:
        rho (tf.Tensor): 2-dimensional Hermitian matrix representing state :math:`\rho`.
        sigma (tf.Tensor): 2-dimensional Hermitian matrix of the same dimensions and dtype as rho,
            representing state :math:`\sigma`.

    Returns:
        tf.Tensor: Returns the scalar trace distance.
    """

    if rho.shape != sigma.shape:
        raise ValueError("Cannot compute the trace distance if inputs have"
                         " different shapes {} and {}".format(rho.shape, sigma.shape))

    diff = rho - sigma
    eig = tf.self_adjoint_eigvals(diff)
    abs_eig = tf.abs(eig)
    return 0.5*tf.real(tf.reduce_sum(abs_eig)) 
开发者ID:XanaduAI,项目名称:QMLT,代码行数:24,代码来源:losses.py

示例4: expectation

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import real [as 别名]
def expectation(rho, operator):
    r""" Expectation value :math:`\tr\{ \rho O\}` of operator :math:`O` with respect to the quantum state :math:`\rho`.

    The inputs and outputs are tensors of dtype float, and all computations support automatic differentiation.


    Args:
        rho (tf.Tensor) : 2-dimensional Hermitian tensor representing state :math:`\rho`.
        operator (tf.Tensor):  2-dimensional Hermitian tensor of the same dimensions and dtype as rho.

    Returns:
        tf.Tensor: Returns the scalar expectation value.

    """
    if rho.shape != operator.shape:
        raise ValueError("Cannot compute expectation value if rho and operator have"
                         " different shapes {} and {}".format(rho.shape, operator.shape))
    if len(rho.shape) != 2:
        raise ValueError("Expectation loss expects a 2-d array representing a density matrix.")

    exp = tf.real(tf.trace(tf.matmul(rho, operator)))
    return exp 
开发者ID:XanaduAI,项目名称:QMLT,代码行数:24,代码来源:losses.py

示例5: _compareGradient

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import real [as 别名]
def _compareGradient(self, x):
    # x[:, 0] is real, x[:, 1] is imag.  We combine real and imag into
    # complex numbers. Then, we extract real and imag parts and
    # computes the squared sum. This is obviously the same as sum(real
    # * real) + sum(imag * imag). We just want to make sure the
    # gradient function is checked.
    with self.test_session():
      inx = tf.convert_to_tensor(x)
      real, imag = tf.split(1, 2, inx)
      real, imag = tf.reshape(real, [-1]), tf.reshape(imag, [-1])
      cplx = tf.complex(real, imag)
      cplx = tf.conj(cplx)
      loss = tf.reduce_sum(
          tf.square(tf.real(cplx))) + tf.reduce_sum(
              tf.square(tf.imag(cplx)))
      epsilon = 1e-3
      jacob_t, jacob_n = tf.test.compute_gradient(inx,
                                                  list(x.shape),
                                                  loss,
                                                  [1],
                                                  x_init_value=x,
                                                  delta=epsilon)
    self.assertAllClose(jacob_t, jacob_n, rtol=epsilon, atol=epsilon) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:25,代码来源:cwise_ops_test.py

示例6: compute_log_mel_spectrograms

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import real [as 别名]
def compute_log_mel_spectrograms(stfts, hparams):
    # power_spectrograms = tf.real(stfts * tf.conj(stfts))
    magnitude_spectrograms = tf.abs(stfts)

    num_spectrogram_bins = magnitude_spectrograms.shape[-1].value

    linear_to_mel_weight_matrix = signal.linear_to_mel_weight_matrix(
        hparams.num_mel_bins, num_spectrogram_bins, hparams.sample_rate, hparams.mel_lower_edge_hz,
        hparams.mel_upper_edge_hz)

    mel_spectrograms = tf.tensordot(
        magnitude_spectrograms, linear_to_mel_weight_matrix, 1)

    # Note: Shape inference for `tf.tensordot` does not currently handle this case.
    mel_spectrograms.set_shape(magnitude_spectrograms.shape[:-1].concatenate(
        linear_to_mel_weight_matrix.shape[-1:]))

    log_offset = 1e-6
    log_mel_spectrograms = tf.log(mel_spectrograms + log_offset)

    return log_mel_spectrograms 
开发者ID:georgesterpu,项目名称:avsr-tf1,代码行数:23,代码来源:audio.py

示例7: hdrplus_merge

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import real [as 别名]
def hdrplus_merge(imgs, N, c, sig):
    ccast_tf = lambda x : tf.complex(x, tf.zeros_like(x))

    # imgs is [batch, h, w, ch]
    rcw = tf.expand_dims(rcwindow(N), axis=-1)
    imgs = imgs * rcw
    imgs = tf.transpose(imgs, [0, 3, 1, 2])
    imgs_f = tf.fft2d(ccast_tf(imgs))
    imgs_f = tf.transpose(imgs_f, [0, 2, 3, 1])
    Dz2 = tf.square(tf.abs(imgs_f[...,0:1] - imgs_f))
    Az = Dz2 / (Dz2 + c*sig**2)
    filt0 = 1 + tf.expand_dims(tf.reduce_sum(Az[...,1:], axis=-1), axis=-1)
    filts = tf.concat([filt0, 1 - Az[...,1:]], axis=-1)
    output_f = tf.reduce_mean(imgs_f * ccast_tf(filts), axis=-1)
    output_f = tf.real(tf.ifft2d(output_f))

    return output_f 
开发者ID:google,项目名称:burst-denoising,代码行数:19,代码来源:tf_image.py

示例8: griffin_lim

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import real [as 别名]
def griffin_lim(spec, 
                frame_length,
                frame_step,
                num_fft,
                num_iters = 1):
                #num_iters = 20):
                #num_iters = 10):
  invert_spec = lambda spec : tf.contrib.signal.inverse_stft(spec, frame_length, frame_step, num_fft)

  spec_mag = tf.cast(tf.abs(spec), dtype=tf.complex64)
  best = tf.identity(spec)
  for i in range(num_iters):
    samples = invert_spec(best)
    est = tf.contrib.signal.stft(samples, frame_length, frame_step, num_fft, pad_end = False)  # (1, T, n_fft/2+1)
    phase = est / tf.cast(tf.maximum(1e-8, tf.abs(est)), tf.complex64) 
    best = spec_mag * phase
  X_t = invert_spec(best)
  y = tf.real(X_t)
  y = cast_float(y)
  return y 
开发者ID:andrewowens,项目名称:multisensory,代码行数:22,代码来源:soundrep.py

示例9: compute_fft

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import real [as 别名]
def compute_fft(x, direction="C2C", inverse=False):

    if direction == 'C2R':
        inverse = True

    x_shape = x.get_shape().as_list()
    h, w = x_shape[-2], x_shape[-3]

    x_complex = tf.complex(x[..., 0], x[..., 1])

    if direction == 'C2R':
        out = tf.real(tf.ifft2d(x_complex)) * h * w
        return out

    else:
        if inverse:
            out = stack_real_imag(tf.ifft2d(x_complex)) * h * w
        else:
            out = stack_real_imag(tf.fft2d(x_complex))
        return out 
开发者ID:tdeboissiere,项目名称:DeepLearningImplementations,代码行数:22,代码来源:scattering.py

示例10: spectrogram2wav

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import real [as 别名]
def spectrogram2wav(spectrogram, n_iter=hparams.griffin_lim_iters, n_fft=(hparams.num_freq - 1) * 2,
                    win_length=int(hparams.frame_length_ms / 1000 * hparams.sample_rate),
                    hop_length=int(hparams.frame_shift_ms / 1000 * hparams.sample_rate)):
    '''Converts spectrogram into a waveform using Griffin-lim's raw.
    '''

    def invert_spectrogram(spectrogram):
        '''
        spectrogram: [t, f]
        '''
        spectrogram = tf.expand_dims(spectrogram, 0)
        inversed = tf.contrib.signal.inverse_stft(spectrogram, win_length, hop_length, n_fft)
        squeezed = tf.squeeze(inversed, 0)
        return squeezed

    spectrogram = tf.transpose(spectrogram)

    spectrogram = tf.cast(spectrogram, dtype=tf.complex64)  # [t, f]
    X_best = tf.identity(spectrogram)
    for i in range(n_iter):
        X_t = invert_spectrogram(X_best)
        est = tf.contrib.signal.stft(X_t, win_length, hop_length, n_fft, pad_end=False)  # (1, T, n_fft/2+1)
        phase = est / tf.cast(tf.maximum(1e-8, tf.abs(est)), tf.complex64)  # [t, f]
        X_best = spectrogram * phase  # [t, t]
    X_t = invert_spectrogram(X_best)
    y = tf.real(X_t)

    return y 
开发者ID:candlewill,项目名称:Griffin_lim,代码行数:30,代码来源:griffin_lim.py

示例11: test_Real

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import real [as 别名]
def test_Real(self):
        t = tf.real(tf.Variable(self.random(3, 4, complex=True)))
        self.check(t)


    #
    # Fourier transform ops
    # 
开发者ID:riga,项目名称:tfdeploy,代码行数:10,代码来源:ops.py

示例12: call

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import real [as 别名]
def call(self, inputx):
        
        assert inputx.dtype in [tf.complex64, tf.complex128], 'inputx is not complex.'
        
        return tf.concat([tf.real(inputx), tf.imag(inputx)], -1) 
开发者ID:adalca,项目名称:neuron,代码行数:7,代码来源:layers.py

示例13: one_bp_iteration

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import real [as 别名]
def one_bp_iteration(self, xe_v2c_pre_iter, H_sumC_to_V, H_sumV_to_C, xe_0):
        xe_tanh = tf.tanh(tf.to_double(tf.truediv(xe_v2c_pre_iter, [2.0])))
        xe_tanh = tf.to_float(xe_tanh)
        xe_tanh_temp = tf.sign(xe_tanh)
        xe_sum_log_img = tf.matmul(H_sumC_to_V, tf.multiply(tf.truediv((1 - xe_tanh_temp), [2.0]), [3.1415926]))
        xe_sum_log_real = tf.matmul(H_sumC_to_V, tf.log(1e-8 + tf.abs(xe_tanh)))
        xe_sum_log_complex = tf.complex(xe_sum_log_real, xe_sum_log_img)
        xe_product = tf.real(tf.exp(xe_sum_log_complex))
        xe_product_temp = tf.multiply(tf.sign(xe_product), -2e-7)
        xe_pd_modified = tf.add(xe_product, xe_product_temp)
        xe_v_sumc = tf.multiply(self.atanh(xe_pd_modified), [2.0])
        xe_c_sumv = tf.add(xe_0, tf.matmul(H_sumV_to_C, xe_v_sumc))
        return xe_v_sumc, xe_c_sumv 
开发者ID:liangfei-info,项目名称:Iterative-BP-CNN,代码行数:15,代码来源:BP_Decoder.py

示例14: _compareMake

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import real [as 别名]
def _compareMake(self, real, imag, use_gpu):
    np_ans = real + (1j) * imag
    with self.test_session(use_gpu=use_gpu):
      real = tf.convert_to_tensor(real)
      imag = tf.convert_to_tensor(imag)
      tf_ans = tf.complex(real, imag)
      out = tf_ans.eval()
    self.assertAllEqual(np_ans, out)
    self.assertShapeEqual(np_ans, tf_ans) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:11,代码来源:cwise_ops_test.py

示例15: testMake

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import real [as 别名]
def testMake(self):
    real = (np.arange(-3, 3) / 4.).reshape([1, 3, 2]).astype(np.float32)
    imag = (np.arange(-3, 3) / 5.).reshape([1, 3, 2]).astype(np.float32)
    for use_gpu in [False, True]:
      self._compareMake(real, imag, use_gpu)
      self._compareMake(real, 12.0, use_gpu)
      self._compareMake(23.0, imag, use_gpu) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:9,代码来源:cwise_ops_test.py


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