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


Python tensorflow.complex64方法代码示例

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


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

示例1: one_hot_add

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

示例2: call

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

示例3: invert_spectra_griffin_lim

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import complex64 [as 别名]
def invert_spectra_griffin_lim(X_mag, nfft, nhop, ngl):
    X = tf.complex(X_mag, tf.zeros_like(X_mag))

    def b(i, X_best):
        x = tf.contrib.signal.inverse_stft(X_best, nfft, nhop)
        X_est = tf.contrib.signal.stft(x, nfft, nhop)
        phase = X_est / tf.cast(tf.maximum(1e-8, tf.abs(X_est)), tf.complex64)
        X_best = X * phase
        return i + 1, X_best

    i = tf.constant(0)
    c = lambda i, _: tf.less(i, ngl)
    _, X = tf.while_loop(c, b, [i, X], back_prop=False)

    x = tf.contrib.signal.inverse_stft(X, nfft, nhop)
    x = x[:, :_SLICE_LEN]

    return x 
开发者ID:chrisdonahue,项目名称:wavegan,代码行数:20,代码来源:train_specgan.py

示例4: _compareBCast

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import complex64 [as 别名]
def _compareBCast(self, xs, ys, dtype, np_func, tf_func):
    if dtype in (np.complex64, np.complex128):
      x = (1 + np.linspace(0, 2 + 3j, np.prod(xs))).astype(dtype).reshape(xs)
      y = (1 + np.linspace(0, 2 - 2j, np.prod(ys))).astype(dtype).reshape(ys)
    else:
      x = (1 + np.linspace(0, 5, np.prod(xs))).astype(dtype).reshape(xs)
      y = (1 + np.linspace(0, 5, np.prod(ys))).astype(dtype).reshape(ys)
    self._compareCpu(x, y, np_func, tf_func)
    if x.dtype in (np.float16, np.float32, np.float64, np.complex64,
                   np.complex128):
      if tf_func not in (_FLOORDIV, tf.floordiv):
        if x.dtype == np.float16:
          # Compare fp16 theoretical gradients to fp32 numerical gradients,
          # since fp16 numerical gradients are too imprecise unless great
          # care is taken with choosing the inputs and the delta. This is
          # a weaker check (in particular, it does not test the op itself,
          # only its gradient), but it's much better than nothing.
          self._compareGradientX(x, y, np_func, tf_func, np.float)
          self._compareGradientY(x, y, np_func, tf_func, np.float)
        else:
          self._compareGradientX(x, y, np_func, tf_func)
          self._compareGradientY(x, y, np_func, tf_func)
      self._compareGpu(x, y, np_func, tf_func)

  # TODO(josh11b,vrv): Refactor this to use parameterized tests. 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:27,代码来源:cwise_ops_test.py

示例5: _testBCastByFunc

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import complex64 [as 别名]
def _testBCastByFunc(self, funcs, xs, ys):
    dtypes = [
        np.float16,
        np.float32,
        np.float64,
        np.int32,
        np.int64,
        np.complex64,
        np.complex128,
    ]
    for dtype in dtypes:
      for (np_func, tf_func) in funcs:
        if (dtype in (np.complex64, np.complex128) and
              tf_func in (_FLOORDIV, tf.floordiv)):
          continue  # floordiv makes no sense for complex numbers
        self._compareBCast(xs, ys, dtype, np_func, tf_func)
        self._compareBCast(ys, xs, dtype, np_func, tf_func) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:19,代码来源:cwise_ops_test.py

示例6: testTensorCompareTensor

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import complex64 [as 别名]
def testTensorCompareTensor(self):
    x = np.linspace(-15, 15, 6).reshape(1, 3, 2)
    y = np.linspace(20, -10, 6).reshape(1, 3, 2)
    for t in [np.float16, np.float32, np.float64, np.int32, np.int64]:
      xt = x.astype(t)
      yt = y.astype(t)
      self._compareBoth(xt, yt, np.less, tf.less)
      self._compareBoth(xt, yt, np.less_equal, tf.less_equal)
      self._compareBoth(xt, yt, np.greater, tf.greater)
      self._compareBoth(xt, yt, np.greater_equal, tf.greater_equal)
      self._compareBoth(xt, yt, np.equal, tf.equal)
      self._compareBoth(xt, yt, np.not_equal, tf.not_equal)
    # TODO(zhifengc): complex64 doesn't work on GPU yet.
    for t in [np.complex64, np.complex128]:
      self._compareCpu(x.astype(t), y.astype(t), np.equal, tf.equal)
      self._compareCpu(x.astype(t), y.astype(t), np.not_equal, tf.not_equal) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:18,代码来源:cwise_ops_test.py

示例7: _toDataType

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import complex64 [as 别名]
def _toDataType(self, dtype):
    """Returns TensorFlow data type for numpy type."""
    if dtype == np.float32:
      return tf.float32
    elif dtype == np.float64:
      return tf.float64
    elif dtype == np.int32:
      return tf.int32
    elif dtype == np.int64:
      return tf.int64
    elif dtype == np.bool:
      return tf.bool
    elif dtype == np.complex64:
      return tf.complex64
    elif dtype == np.complex128:
      return tf.complex128
    else:
      return None 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:20,代码来源:cast_op_test.py

示例8: _testTypes

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import complex64 [as 别名]
def _testTypes(self, x, use_gpu=False):
    """Tests cast(x) to different tf."""
    if use_gpu:
      type_list = [np.float32, np.float64, np.int64,
                   np.complex64, np.complex128]
    else:
      type_list = [np.float32, np.float64, np.int32,
                   np.int64, np.complex64, np.complex128]
    for from_type in type_list:
      for to_type in type_list:
        self._test(x.astype(from_type), to_type, use_gpu)

    self._test(x.astype(np.bool), np.float32, use_gpu)
    self._test(x.astype(np.uint8), np.float32, use_gpu)
    if not use_gpu:
      self._test(x.astype(np.bool), np.int32, use_gpu)
      self._test(x.astype(np.int32), np.int32, use_gpu) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:19,代码来源:cast_op_test.py

示例9: testDtype

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import complex64 [as 别名]
def testDtype(self):
    with self.test_session():
      d = tf.fill([2, 3], 12., name="fill")
      self.assertEqual(d.get_shape(), [2, 3])
      # Test default type for both constant size and dynamic size
      z = tf.zeros([2, 3])
      self.assertEqual(z.dtype, tf.float32)
      self.assertEqual([2, 3], z.get_shape())
      self.assertAllEqual(z.eval(), np.zeros([2, 3]))
      z = tf.zeros(tf.shape(d))
      self.assertEqual(z.dtype, tf.float32)
      self.assertEqual([2, 3], z.get_shape())
      self.assertAllEqual(z.eval(), np.zeros([2, 3]))
      # Test explicit type control
      for dtype in [tf.float32, tf.float64, tf.int32,
                    tf.uint8, tf.int16, tf.int8,
                    tf.complex64, tf.complex128, tf.int64, tf.bool]:
        z = tf.zeros([2, 3], dtype=dtype)
        self.assertEqual(z.dtype, dtype)
        self.assertEqual([2, 3], z.get_shape())
        self.assertAllEqual(z.eval(), np.zeros([2, 3]))
        z = tf.zeros(tf.shape(d), dtype=dtype)
        self.assertEqual(z.dtype, dtype)
        self.assertEqual([2, 3], z.get_shape())
        self.assertAllEqual(z.eval(), np.zeros([2, 3])) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:27,代码来源:constant_op_test.py

示例10: testOnesLike

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import complex64 [as 别名]
def testOnesLike(self):
    for dtype in [tf.float32, tf.float64, tf.int32,
                  tf.uint8, tf.int16, tf.int8,
                  tf.complex64, tf.complex128, tf.int64]:
      numpy_dtype = dtype.as_numpy_dtype
      with self.test_session():
        # Creates a tensor of non-zero values with shape 2 x 3.
        d = tf.constant(np.ones((2, 3), dtype=numpy_dtype), dtype=dtype)
        # Constructs a tensor of zeros of the same dimensions and type as "d".
        z_var = tf.ones_like(d)
        # Test that the type is correct
        self.assertEqual(z_var.dtype, dtype)
        z_value = z_var.eval()

      # Test that the value is correct
      self.assertTrue(np.array_equal(z_value, np.array([[1] * 3] * 2)))
      self.assertEqual([2, 3], z_var.get_shape()) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:19,代码来源:constant_op_test.py

示例11: testValues

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import complex64 [as 别名]
def testValues(self):
    dtypes = [tf.float32,
              tf.float64,
              tf.int64,
              tf.int32,
              tf.complex64,
              tf.complex128]
    indices_flat = np.array([0, 4, 0, 8, 3, 8, 4, 7, 7, 3])
    num_segments = 12
    for indices in indices_flat, indices_flat.reshape(5, 2):
      shape = indices.shape + (2,)
      for dtype in dtypes:
        with self.test_session(use_gpu=self.use_gpu):
          tf_x, np_x = self._input(shape, dtype=dtype)
          np_ans = self._segmentReduce(indices,
                                       np_x,
                                       np.add,
                                       op2=None,
                                       num_out_rows=num_segments)
          s = tf.unsorted_segment_sum(data=tf_x,
                                      segment_ids=indices,
                                      num_segments=num_segments)
          tf_ans = s.eval()
        self._assertAllClose(indices, np_ans, tf_ans)
        self.assertShapeEqual(np_ans, s) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:27,代码来源:segment_reduction_ops_test.py

示例12: testTypes

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import complex64 [as 别名]
def testTypes(self):
    types_to_test = {
        "bool": (tf.bool, bool),
        "float32": (tf.float32, float),
        "float64": (tf.float64, float),
        "complex64": (tf.complex64, complex),
        "complex128": (tf.complex128, complex),
        "uint8": (tf.uint8, int),
        "int32": (tf.int32, int),
        "int64": (tf.int64, int),
        bytes: (tf.string, bytes)
    }
    for dtype_np, (dtype_tf, cast) in types_to_test.items():
      with self.test_session(use_gpu=True):
        inp = np.random.rand(4, 1).astype(dtype_np)
        a = tf.constant([cast(x) for x in inp.ravel(order="C")], shape=[4, 1],
                   dtype=dtype_tf)
        tiled = tf.tile(a, [1, 4])
        result = tiled.eval()
      self.assertEqual(result.shape, (4, 4))
      self.assertEqual([4, 4], tiled.get_shape())
      self.assertAllEqual(result, np.tile(inp, (1, 4))) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:24,代码来源:shape_ops_test.py

示例13: _testGrad

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import complex64 [as 别名]
def _testGrad(self, shape, dtype=None, max_error=None, bias=None, sigma=None):
    np.random.seed(7)
    if dtype in (tf.complex64, tf.complex128):
      value = tf.complex(self._biasedRandN(shape, bias=bias, sigma=sigma),
                         self._biasedRandN(shape, bias=bias, sigma=sigma))
    else:
      value = tf.convert_to_tensor(self._biasedRandN(shape, bias=bias),
                                   dtype=dtype)

    with self.test_session(use_gpu=True):
      if dtype in (tf.complex64, tf.complex128):
        output = tf.complex_abs(value)
      else:
        output = tf.abs(value)
      error = tf.test.compute_gradient_error(
          value, shape, output, output.get_shape().as_list())
    self.assertLess(error, max_error) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:19,代码来源:math_grad_test.py

示例14: testComplex64N

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import complex64 [as 别名]
def testComplex64N(self):
    t = tensor_util.make_tensor_proto([(1+2j), (3+4j), (5+6j)], shape=[1, 3],
                                      dtype=tf.complex64)
    self.assertProtoEquals("""
      dtype: DT_COMPLEX64
      tensor_shape { dim { size: 1 } dim { size: 3 } }
      scomplex_val: 1
      scomplex_val: 2
      scomplex_val: 3
      scomplex_val: 4
      scomplex_val: 5
      scomplex_val: 6
      """, t)
    a = tensor_util.MakeNdarray(t)
    self.assertEquals(np.complex64, a.dtype)
    self.assertAllEqual(np.array([[(1+2j), (3+4j), (5+6j)]]), a) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:18,代码来源:tensor_util_test.py

示例15: testComplex64NpArray

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import complex64 [as 别名]
def testComplex64NpArray(self):
    t = tensor_util.make_tensor_proto(
        np.array([[(1+2j), (3+4j)], [(5+6j), (7+8j)]]), dtype=tf.complex64)
    # scomplex_val are real_0, imag_0, real_1, imag_1, ...
    self.assertProtoEquals("""
      dtype: DT_COMPLEX64
      tensor_shape { dim { size: 2 } dim { size: 2 } }
      scomplex_val: 1
      scomplex_val: 2
      scomplex_val: 3
      scomplex_val: 4
      scomplex_val: 5
      scomplex_val: 6
      scomplex_val: 7
      scomplex_val: 8
      """, t)
    a = tensor_util.MakeNdarray(t)
    self.assertEquals(np.complex64, a.dtype)
    self.assertAllEqual(np.array([[(1+2j), (3+4j)], [(5+6j), (7+8j)]]), a) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:21,代码来源:tensor_util_test.py


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