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


Python tensorflow.imag方法代码示例

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


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

示例1: call

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import imag [as 别名]
def call(self, inputx):
        
        if not inputx.dtype in [tf.complex64, tf.complex128]:
            print('Warning: inputx is not complex. Converting.', file=sys.stderr)
        
            # if inputx is float, this will assume 0 imag channel
            inputx = tf.cast(inputx, tf.complex64)

        # get the right fft
        if self.ndims == 1:
            fft = tf.fft
        elif self.ndims == 2:
            fft = tf.fft2d
        else:
            fft = tf.fft3d

        perm_dims = [0, self.ndims + 1] + list(range(1, self.ndims + 1))
        invert_perm_ndims = [0] + list(range(2, self.ndims + 2)) + [1]
        
        perm_inputx = K.permute_dimensions(inputx, perm_dims)  # [batch_size, nb_features, *vol_size]
        fft_inputx = fft(perm_inputx)
        return K.permute_dimensions(fft_inputx, invert_perm_ndims) 
开发者ID:adalca,项目名称:neuron,代码行数:24,代码来源:layers.py

示例2: _compareGradient

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import imag [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

示例3: get_mu_tensor

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import imag [as 别名]
def get_mu_tensor(self):
    const_fact = self._dist_to_opt_avg**2 * self._h_min**2 / 2 / self._grad_var
    coef = tf.Variable([-1.0, 3.0, 0.0, 1.0], dtype=tf.float32, name="cubic_solver_coef")
    coef = tf.scatter_update(coef, tf.constant(2), -(3 + const_fact) )        
    roots = tf.py_func(np.roots, [coef], Tout=tf.complex64, stateful=False)
    
    # filter out the correct root
    root_idx = tf.logical_and(tf.logical_and(tf.greater(tf.real(roots), tf.constant(0.0) ),
      tf.less(tf.real(roots), tf.constant(1.0) ) ), tf.less(tf.abs(tf.imag(roots) ), 1e-5) )
    # in case there are two duplicated roots satisfying the above condition
    root = tf.reshape(tf.gather(tf.gather(roots, tf.where(root_idx) ), tf.constant(0) ), shape=[] )
    tf.assert_equal(tf.size(root), tf.constant(1) )

    dr = self._h_max / self._h_min
    mu = tf.maximum(tf.real(root)**2, ( (tf.sqrt(dr) - 1)/(tf.sqrt(dr) + 1) )**2)    
    return mu 
开发者ID:Zehaos,项目名称:MobileNet,代码行数:18,代码来源:yellowfin.py

示例4: test_Imag

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import imag [as 别名]
def test_Imag(self):
        t = tf.imag(tf.Variable(self.random(3, 4, complex=True)))
        self.check(t) 
开发者ID:riga,项目名称:tfdeploy,代码行数:5,代码来源:ops.py

示例5: _compareMake

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import imag [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

示例6: testMake

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import imag [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

示例7: _compareRealImag

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import imag [as 别名]
def _compareRealImag(self, cplx, use_gpu):
    np_real, np_imag = np.real(cplx), np.imag(cplx)
    with self.test_session(use_gpu=use_gpu) as sess:
      inx = tf.convert_to_tensor(cplx)
      tf_real = tf.real(inx)
      tf_imag = tf.imag(inx)
      tf_real_val, tf_imag_val = sess.run([tf_real, tf_imag])
    self.assertAllEqual(np_real, tf_real_val)
    self.assertAllEqual(np_imag, tf_imag_val)
    self.assertShapeEqual(np_real, tf_real)
    self.assertShapeEqual(np_imag, tf_imag) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:13,代码来源:cwise_ops_test.py

示例8: testRealImag64

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import imag [as 别名]
def testRealImag64(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)
    cplx = real + 1j * imag
    self._compareRealImag(cplx, use_gpu=False)
    self._compareRealImag(cplx, use_gpu=True) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:8,代码来源:cwise_ops_test.py

示例9: testRealImag128

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import imag [as 别名]
def testRealImag128(self):
    real = (np.arange(-3, 3) / 4.).reshape([1, 3, 2]).astype(np.float64)
    imag = (np.arange(-3, 3) / 5.).reshape([1, 3, 2]).astype(np.float64)
    cplx = real + 1j * imag
    self._compareRealImag(cplx, use_gpu=False)
    self._compareRealImag(cplx, use_gpu=True) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:8,代码来源:cwise_ops_test.py

示例10: testConj128

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import imag [as 别名]
def testConj128(self):
    real = (np.arange(-3, 3) / 4.).reshape([1, 3, 2]).astype(np.float64)
    imag = (np.arange(-3, 3) / 5.).reshape([1, 3, 2]).astype(np.float64)
    cplx = real + 1j * imag
    self._compareConj(cplx, use_gpu=False)
    self._compareConj(cplx, use_gpu=True) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:8,代码来源:cwise_ops_test.py

示例11: _compareMulGradient

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import imag [as 别名]
def _compareMulGradient(self, data):
    # data is a float matrix of shape [n, 4].  data[:, 0], data[:, 1],
    # data[:, 2], data[:, 3] are real parts of x, imaginary parts of
    # x, real parts of y and imaginary parts of y.
    with self.test_session():
      inp = tf.convert_to_tensor(data)
      xr, xi, yr, yi = tf.split(1, 4, inp)

      def vec(x):  # Reshape to a vector
        return tf.reshape(x, [-1])
      xr, xi, yr, yi = vec(xr), vec(xi), vec(yr), vec(yi)

      def cplx(r, i):  # Combine to a complex vector
        return tf.complex(r, i)
      x, y = cplx(xr, xi), cplx(yr, yi)
      # z is x times y in complex plane.
      z = x * y
      # Defines the loss function as the sum of all coefficients of z.
      loss = tf.reduce_sum(tf.real(z) + tf.imag(z))
      epsilon = 0.005
      jacob_t, jacob_n = tf.test.compute_gradient(inp,
                                                  list(data.shape),
                                                  loss,
                                                  [1],
                                                  x_init_value=data,
                                                  delta=epsilon)
    self.assertAllClose(jacob_t, jacob_n, rtol=epsilon, atol=epsilon) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:29,代码来源:cwise_ops_test.py

示例12: mriForwardOpWithOS

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import imag [as 别名]
def mriForwardOpWithOS(self, u, coil_sens, sampling_mask):
        with tf.variable_scope('mriForwardOp'):
            # add frequency encoding oversampling
            pad_u = tf.cast(tf.multiply(tf.cast(tf.shape(sampling_mask)[1], tf.float32), 0.25) + 1, tf.int32)
            pad_l = tf.cast(tf.multiply(tf.cast(tf.shape(sampling_mask)[1], tf.float32), 0.25) - 1, tf.int32)
            u_pad = tf.pad(u, [[0, 0], [pad_u, pad_l], [0, 0]])
            u_pad = tf.expand_dims(u_pad, axis=1)
            # apply sensitivites
            coil_imgs = u_pad * coil_sens
            # centered Fourier transform
            Fu = tf.contrib.icg.fftc2d(coil_imgs)
            # apply sampling mask
            mask = tf.expand_dims(sampling_mask, axis=1)
            kspace = tf.complex(tf.real(Fu) * mask, tf.imag(Fu) * mask)
        return kspace 
开发者ID:VLOGroup,项目名称:mri-variationalnetwork,代码行数:17,代码来源:train_mri_vn.py

示例13: mriAdjointOpWithOS

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import imag [as 别名]
def mriAdjointOpWithOS(self, f, coil_sens, sampling_mask):
        with tf.variable_scope('mriAdjointOp'):
            # variables to remove frequency encoding oversampling
            pad_u = tf.cast(tf.multiply(tf.cast(tf.shape(sampling_mask)[1], tf.float32), 0.25) + 1, tf.int32)
            pad_l = tf.cast(tf.multiply(tf.cast(tf.shape(sampling_mask)[1], tf.float32), 0.25) - 1, tf.int32)
            # apply mask and perform inverse centered Fourier transform
            mask = tf.expand_dims(sampling_mask, axis=1)
            Finv = tf.contrib.icg.ifftc2d(tf.complex(tf.real(f) * mask, tf.imag(f) * mask))
            # multiply coil images with sensitivities and sum up over channels
            img = tf.reduce_sum(Finv * tf.conj(coil_sens), 1)[:, pad_u:-pad_l, :]
        return img 
开发者ID:VLOGroup,项目名称:mri-variationalnetwork,代码行数:13,代码来源:train_mri_vn.py

示例14: mriForwardOp

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import imag [as 别名]
def mriForwardOp(self, u, coil_sens, sampling_mask):
        with tf.variable_scope('mriForwardOp'):
            # apply sensitivites
            coil_imgs = tf.expand_dims(u, axis=1) * coil_sens
            # centered Fourier transform
            Fu = tf.contrib.icg.fftc2d(coil_imgs)
            # apply sampling mask
            mask = tf.expand_dims(sampling_mask, axis=1)
            kspace = tf.complex(tf.real(Fu) * mask, tf.imag(Fu) * mask)
        return kspace 
开发者ID:VLOGroup,项目名称:mri-variationalnetwork,代码行数:12,代码来源:train_mri_vn.py

示例15: test_complex_to_channels

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import imag [as 别名]
def test_complex_to_channels(self):
        data_r = tf.random_uniform([3, 10, 10, 2])
        data_i = tf.random_uniform([3, 10, 10, 2])
        data = tf.complex(data_r, data_i)
        data_out = tfmri.complex_to_channels(data)
        diff_r = data_r - tf.real(data)
        diff_i = data_i - tf.imag(data)
        diff = np.mean(diff_r ** 2 + diff_i ** 2)
        self.assertTrue(diff < eps)
        self.assertEqual(data_out.shape[-1], 4)

        data_out = tfmri.complex_to_channels(
            data, data_format='channels_first')
        diff_r = data_r - tf.real(data)
        diff_i = data_i - tf.imag(data)
        diff = np.mean(diff_r ** 2 + diff_i ** 2)
        self.assertTrue(diff < eps)
        self.assertEqual(data_out.shape[1], 20)

        with self.assertRaises(TypeError):
            # Input must be complex
            data_out = tfmri.complex_to_channels(data_r)
        with self.assertRaises(TypeError):
            # shape error
            data_r = tf.random_uniform([1, 3, 10, 10, 2])
            data_i = tf.random_uniform([1, 3, 10, 10, 2])
            data = tf.complex(data_r, data_i)
            data_out = tfmri.complex_to_channels(data)
        with self.assertRaises(TypeError):
            # shape error
            data_r = tf.random_uniform([10, 2])
            data_i = tf.random_uniform([10, 2])
            data = tf.complex(data_r, data_i)
            data_out = tfmri.complex_to_channels(data) 
开发者ID:MRSRL,项目名称:dl-cs,代码行数:36,代码来源:tfmri_test.py


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