當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。