首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏JNing的专栏

    Tensor

      在 TF 中,一个张量如下表述: my_tensor = tf.constant(0., shape=[6,3,7]) print(my_tensor) # -> Tensor("Const_ 在 TensorFlow 中用 tensor 数据结构来代表所有的数据, 计算图中, 操作间传递的数据都是 tensor。    张量可以用我们所说的形状来描述:我们用列表(或元祖)来描述我们的张量的每个维度的大小 不同维度的Tensor 俗称 表示方法 n 维度的张量 多维数组 (D_0, D_1, D_2, …, D_n-1) ---- Tensor 种类 Annotation 常值张量(constant) 是不需要初始化的。 变量(Variable) 是维护图执行过程中的状态信息的.

    91520发布于 2018-09-28
  • 来自专栏GPUS开发者

    Tensor Core

    Tensor Core,也是Volta架构里面最重磅的特性。 Tensor Core实际上是一种矩阵乘累加的计算单元。 Tensor Core的矩阵乘累加运算是一种混合精度运算。我们前面提到的一个V100可以实现125 TLOPS的混合精度运算,指的就是Tensor Core的混合精度。 在Tensor Core中,这是需要大家注意的一个特性。 在具体实验过程中,Tensor Core以WARP为单元执行。一个WARP中执行的是一个16×16×16的矩阵乘累加运算。 关于如何利用Tensor Core实现矩阵乘法的加速,我们提供两种方式。第一种方式如右侧图中展示的代码,在CUDA编程里实现Tensor Core的调用。 Tensor Core的功能正在被集成到越来越多的深度学习框架里去,目前Tensor Core可以支持的深度学习框架有Caffe、Caffe2、MXNet、PyTorch、Theano、TensorFlow

    2.6K80发布于 2018-04-02
  • 来自专栏全栈程序员必看

    pytorch tensor操作:tensor与numpy转换

    tensor转numpy t = torch.ones(5) print(f"t: {t}") n = t.numpy() print(f"n: {n}") 输出: t: tensor([1., 1 ., 1., 1., 1.]) n: [1. 1. 1. 1. 1.] cpu上的tensor可以和numpy array共享内存地址,改变其中的一个另一个也会改变 t.add_(1) print(f"t : {t}") print(f"n: {n}") 输出: t: tensor([2., 2., 2., 2., 2.]) n: [2. 2. 2. 2. 2.] 可训练的tensor转numpy t = torch.ones(5) t_trained = t.clone().detach().requires_grad_(True) print(f"t_trained : {t_trained}") n = t_trained.detach().numpy() print(f"n: {n}") 输出: t_trained: tensor([1., 1., 1., 1.

    74260编辑于 2022-11-02
  • 来自专栏毛利学Python

    tensor张量

    14:0' shape=(4, 1) dtype=int32_ref>, <tf.Variable 'Variable_15:0' shape=(2, 2) dtype=int32_ref>, <tf.Tensor 并将维数降低 # 4维0矩阵my_image = tf.zeros([10, 299, 299, 3]) # batch x height x width x colormy_imageOUT:<tf.Tensor 299, 3) dtype=float32> 将维数降低 tf.rank 0 rank_of_my_image = tf.rank(my_image)rank_of_my_imageOUT:<tf.Tensor tensor 计算 有些方法2.0不支持 ? tf.constant([1.0, 2.0], name="a")b = tf.constant([2.0, 3.0], name="b")result = a + bprint(result)tf.Tensor

    1.1K20发布于 2019-11-04
  • 来自专栏全栈程序员必看

    tensor转换为图像_tensor转int

    tensor转换为numpy import tensor import numpy as np def tensor2img(tensor, out_type=np.uint8, min_max= , 'detach'): tensor = tensor.detach() tensor = tensor.squeeze().float().cpu().clamp_(*min_max) # clamp tensor = (tensor - min_max[0]) / (min_max[1] - min_max[0]) # to range [0,1] n_dim = tensor.dim() if n_dim == 4: n_img = len(tensor) img_np = make_grid(tensor, nrow=int(math.sqrt(n_img)), normalize=False () else: raise TypeError( 'Only support 4D, 3D and 2D tensor.

    21.5K20编辑于 2022-11-07
  • 来自专栏产品经理的人工智能学习库

    张量 – Tensor

    我们用点线面体的概念来比喻解释会更加容易理解: 点——标量(scalar) 线——向量(vector) 面——矩阵(matrix) 体——张量(tensor) ? 百度百科版本 张量(tensor)理论是数学的一个分支学科,在力学中有重要应用。张量这一术语起源于力学,它最初是用来表示弹性介质中各点应力状态的,后来张量理论发展成为力学和物理学的一个有力的数学工具。

    1.5K20发布于 2019-12-18
  • 来自专栏计算机视觉理论及其实现

    tf.Tensor

    Aliases: Class tf.compat.v1.Tensor Class tf.compat.v2.Tensor A Tensor is a symbolic handle to one of Args: tensor: An ops.Tensor object. slice_spec: The arguments to Tensor.getitem. var: In the case of Returns: A Tensor. Returns: A Tensor. is unhashable if Tensor equality is enabled. tensor_set = {x, y, z} tensor_dict = {x: 'five', y: 'ten

    1.6K40编辑于 2022-06-06
  • 来自专栏计算机视觉理论及其实现

    torch、(一) Tensor

    input (Tensor) – the input tensor. out (Tensor, optional) – the output tensor. out (Tensor, optional) – the output tensor. out (Tensor, optional) – the output tensor. input (Tensor) – the input tensor.

    3K40编辑于 2022-09-03
  • 来自专栏计算机视觉理论及其实现

    torch.as_tensor()

    torch.as_tensor(data, dtype=None,device=None)->Tensor : 为data生成tensor。 如果data已经是tensor,且dtype和device与参数相同,则生成的tensor会和data共享内存。如果data是ndarray,且dtype对应,devices为cpu,则同样共享内存。 import torchimport numpya = numpy.array([1, 2, 3])t = torch.as_tensor(a)

    1.6K20编辑于 2022-09-02
  • 来自专栏计算机视觉理论及其实现

    torch.Tensor

    : >>> x = torch.tensor([[1]]) >>> x tensor([[ 1]]) >>> x.item() 1 >>> x = torch.tensor(2.5) >>> x tensor , tensor1, tensor2) → Tensor In-place version of addcdiv() addcmul(value=1, tensor1, tensor2) → Tensor self tensor and the given tensor and stores the results in self tensor. self tensor and the given tensor on a Tensor tensor. type_as(tensor) → Tensor Returns this tensor cast to the type of the given tensor.

    2.2K30发布于 2019-09-25
  • 来自专栏Michael阿明学习之路

    Pytorch 张量tensor

    文章目录 1. tensor 张量 2. 运算 3. 切片、形状size()、改变形状view() 4. item() 只能读取一个元素 参考 http://pytorch123.com/ 1. tensor 张量 empty 不初始化 import torch x = torch.empty(5,3) # 不初始化 print(x) tensor([[1.0010e-38, 4.2246e-39, 1.0286e-38], [1.0653e x = x.new_ones(5,3,dtype=torch.double) tensor([[1., 1., 1.], [1., 1., 1.], [1., 1., 1.], [1., 1., 1.], [1., 1., 1.]], dtype=torch.float64) x = x.new_zeros(2,4) tensor([

    86910发布于 2021-02-19
  • 来自专栏hotarugaliの技术分享

    Torch中Tensor

    简介 tensor(张量)是 PyTorch 中的多维数组,类似与 Numpy 中的 ndarray 。 2. 基本功能 2.1 函数原型 torch.empty(*sizes, out=None) → tensor torch.rand(*sizes, out=None) → tensor torch.randn (*sizes, out=None) → tensor torch.randperm(n, out=None) → longtensor 2.2 举例 x = torch.empty(5,3) #

    43330编辑于 2022-03-10
  • 来自专栏wOw的Android小站

    Tensor维度理解

    Tensor维度理解 Tensor在Tensorflow中是N维矩阵,所以涉及到Tensor的方法,也都是对矩阵的处理。 由于是多维,在Tensorflow中Tensor的流动过程就涉及到升维降维,这篇就通过一些接口的使用,来体会Tensor的维度概念。以下是个人体会,有不准确的请指出。 reduction_indices=None ) 计算Tensor各个维度元素的均值。 这个方法根据输入参数axis的维度上减少输入input_tensor的维度。 对于axis参数的作用,文档的解释是 the rank of the tensor is reduced by 1 for each entry in axis 即Tensor在axis的每一个分量上的秩减少

    1.5K30发布于 2018-09-18
  • 来自专栏软件研发

    torch tensor入门

    Torch Tensor入门在深度学习中,Tensor是一种重要的数据结构,它可以用来存储和处理多维数组。在PyTorch中,Tensor是一种非常基础且常用的数据类型,它支持很多高效的操作。 创建Tensor使用torch库创建一个tensor非常简单。 Tensor的基本操作torch tensor支持很多基本的数学和逻辑操作。 改变Tensor的形状有时候我们需要改变一个tensor的形状。 总结本篇博客介绍了如何使用torch tensor。我们学习了如何创建tensor、执行基本的数学和逻辑操作、改变tensor的形状以及将tensor移动到GPU上。

    63430编辑于 2023-11-16
  • 来自专栏全栈程序员必看

    TypeError: can‘t convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory fi

    ,label='Fitting Line') plt.show() 这行报错:predict = predict.data.numpy() TypeError: can't convert CUDA tensor Use Tensor.cpu() to copy the tensor to host memory first. 意思是:如果想把CUDA tensor格式的数据改成numpy时,需要先将其转换成cpu float-tensor随后再转到numpy格式。 numpy不能读取CUDA tensor 需要将它转化为 CPU tensor 将predict.data.numpy() 改为predict.data.cpu().numpy()即可 版权声明:本文内容由互联网用户自发贡献

    1.2K40编辑于 2022-11-02
  • 来自专栏计算机视觉理论及其实现

    Use tensor.item() to convert a 0-dim tensor to a Pytho

    train_loss += loss.data[0] 是pytorch0.3.1版本代码,在0.4-0.5版本的pytorch会出现警告,不会报错,但是0.5版本以上的pytorch就会报错,总的来说是版本更新问题.

    80620编辑于 2022-09-02
  • 来自专栏计算机视觉

    PyTorch核心--tensor 张量 !!

    import torch # 创建一个标量 scalar_tensor = torch.tensor(3.14) # 创建一个向量 vector_tensor = torch.tensor([1, 2, 3]) # 创建一个矩阵 matrix_tensor = torch.tensor([[1, 2, 3], [4, 5, 6]]) # 创建一个3D张量 tensor_3d = torch.rand # 获取张量的形状 shape = tensor_3d.shape # 改变张量的形状 reshaped_tensor = tensor_3d.view(3, 8) # 将原始形状(2, 3, 4) 索引和切片 # 索引 element = tensor_3d[0, 1, 2] # 切片 sliced_tensor = tensor_3d[:, 1:3, :] 4. 形状操作 # 改变形状 reshaped_tensor = tensor_3d.view(3, 8) # 转置 transposed_tensor = tensor_3d.transpose(0, 2

    85300编辑于 2024-03-22
  • 来自专栏深度学习|机器学习|歌声合成|语音合成

    pytorch tensor 基础操作

    pytorch tensor 基础操作 # -*- coding:utf-8 -*- # /usr/bin/python ''' @Author : Errol @Describe: @Evn

    63810发布于 2021-01-14
  • 来自专栏全栈程序员必看

    Tensor 和Numpy转换

    1、Tensor 转Numpy import torch as t import numpy as np a = t.ones(5) a Out[23]: tensor([1., 1., 1., 1 b = a.numpy()# Tensor -> Numpy b Out[25]: array([1., 1., 1., 1., 1.], dtype=float32) 2、Numpy 转Tensor import torch as t import numpy as np a = np.ones(5) b = t.from_numpy(a) # Numpy->Tensor a Out[29]: b Out[30]: tensor([1., 1., 1., 1., 1.], dtype=torch.float64) 版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。

    59760编辑于 2022-11-02
  • 来自专栏计算机视觉理论及其实现

    tf.convert_to_tensor

    tf.convert_to_tensor( value, dtype=None, dtype_hint=None, name=None)该函数将各种类型的Python对象转换为张量对象 例:import numpy as npdef my_func(arg): arg = tf.convert_to_tensor(arg, dtype=tf.float32) return tf.matmul dtype.RuntimeError: If a registered conversion function returns an invalid value.ValueError: If the value is a tensor

    1.1K40编辑于 2022-09-03
领券