ICode9

精准搜索请尝试: 精确搜索
  • 训练神经网络时报错:can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor2022-06-04 13:00:06

        在跑网络的时候,报错TypeError:can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host_memory first. 错误在于:train_loss.append(loss.data) 和 valid_loss.append(loss.data)这两行代码,将loss.data改为loss.data.cpu(),也就是将C

  • TENSOR CORE PERFORMANCE: THE ULTIMATE GUIDE2022-06-01 16:00:11

    TENSOR CORE PERFORMANCE: THE ULTIMATE GUIDE 1. 一个有意思的点,batch size / 108 整除的性能(TFLOPS)更好,因为A100的tensor core sm数为108. 见参考       参考: https://developer.download.nvidia.cn/video/gputechconf/gtc/2020/presentations/s21929-tensor-core-performa

  • torch.bmm()解读2022-05-27 09:35:04

    函数作用 计算两个tensor的矩阵乘法,torch.bmm(a,b),tensor a 的size为(b,h,w),tensor b的size为(b,w,m) 也就是说两个tensor的第一维是相等的,然后第一个数组的第三维和第二个数组的第二维度要求一样,对于剩下的则不做要求,输出维度 (b,h,m) 代码示例 >>> c=torch.randn((2,5)) >>> p

  • Tensor Core2022-05-26 13:02:41

    参考: https://forums.developer.nvidia.com/t/how-to-use-wmma-efficiently/157619/2 https://github.com/BigNerd95/CUDASamples/tree/master/samples/0_Simple/cudaTensorCoreGemm (配置WARPS_PER_BLOCK为4,即可达到接近100TFLOS,一般100TFLOPS性能已经比较好。80%peak )  

  • 1、PyTorch基本操作2022-05-25 21:04:30

    一、简介   简单介绍PyTorch框架,基本使用和安装方法。Torch是什么?一个火炬!其实跟Tensorflow中Tensor是一个意思,就是说,有一批数据,无论是图像数据还是文本数据或数值数据,都需要把数据转换成矩阵,接下来在建模操作过程中,都需要对当前数据即矩阵,做各种各样变换,做各种各样计算,一系列流

  • pytorch2022-05-23 22:04:26

    pytorch torch.Tensor - PyTorch中文文档 (pytorch-cn.readthedocs.io) 创建张量 torch.eye(n, m=None, out=None) torch.ones(*sizes, out=None) → Tensor torch.zeros(*sizes, out=None) → Tensor torch.rand(*sizes, out=None) → Tensor torch.linspace(start, end, steps=1

  • torch的基础学习2022-05-20 10:32:10

    1.能带来什么   GPU加速   自动求导 import torch from torch import autograd x = torch.tensor(1.) a = torch.tensor(1., requires_grad=True) b = torch.tensor(2., requires_grad=True) c = torch.tensor(3., requires_grad=True) y = a ** 2 * x + b * x + c print(

  • Deep Learning Week6 Notes2022-05-16 03:00:07

    1. Benefits of depth \(\text{Consider ReLU MLPs with a single Input/Output, there exists a network }f\) \(\text{ with }D^* \text{ layers, and }2D^* \text{ internal units, such that, for any network }g\text{ with }D\text{ layers of sizes }\{W^{(1

  • 关于torch中几种矩阵相乘的比较2022-05-15 01:31:07

      深度学习中免不了要用到torch,经常用到tensor的矩阵相乘,每次都会记错,所以这次把几种tensor的几种矩阵相乘的方法放到一起比较下:   import torcha = torch.tensor([[1,1],                           [2,2]])b = torch.tensor([[1,1],                 

  • 为了论文-Pytorch(2)-TensorBoard和Transforms的使用2022-05-14 18:02:00

    1.TensorBoard的使用   1.1代码及其解析 # 一般通过这个SummaryWriter来创建图像。这个类可以在训练过程中向文件中添加数据,常用的两个方法为add_scalar和add_image,使用方法如下: from torch.utils.tensorboard import SummaryWriter import numpy as np from PIL import Image

  • 用gpu跑代码时出现的问题2022-05-08 09:32:58

    1、当代码都调试后,使用gpu跑,出现: can't convert cuda:0 device type tensor to numpy.Use Tensor.cpu to copy the tensor to host memory first 此时根据提示,找到代码处的loss.detach().将其该成loss.detach().cpu().numpy()即可,原因:gpu式的tensor不能直接转成numpy 待更新!!!

  • PyTorch的Variable已经不需要用了!!!2022-05-07 18:33:36

    转载自:https://blog.csdn.net/rambo_csdn_123/article/details/119056123   Pytorch的torch.autograd.Variable今天在看《莫凡Python》的PyTorch教程的时候发现他的代码还在使用Variable,并且我记得过去读一些GitHub上面的代码的时候也发现了Variable这个东西,根据教程中所说的,想要

  • to numpy() and to torch()2022-04-27 12:34:40

    def to_numpy(self) -> 'Batch': """Change all torch.Tensor to numpy.ndarray in-place.""" for k, v in self.items(): if isinstance(v, torch.Tensor): self[k] = v.detach().cpu().numpy() retu

  • Deep Learning Week1 Notes2022-04-27 04:31:05

    1. Tensors \(\text{A tensor is a generalized matrix:}\) \(\text{an element of }\mathbb{R^3} \text{ is a 3-dimension vector, but it's a 1-dimension tensor.}\) \(\large \text{The 'dimension' of a tensor is the number of indices.}\

  • tensorflow学习笔记2022-04-25 17:02:01

    Tensorflow是一个基于计算图的深度学习库,可以用它多快好省的完成现代绝大部分深度学习的任务。 实现下面的代码,核心过程如下: import tensorflow as tf a=tf.constant(32) #创建常量 b=tf.constant(10) #创建常量 c=tf.add(a,b) print(a) print(b) print(c)   tensorflow只

  • tensorflow 模型批处理参数tensor快速赋值参考2022-04-25 12:33:35

       批处理调用模型的时候,如果逐像素给tensor对象数据部分赋值的话,效率是很低的,尤其是对于一些图片数据,所以数据块直接拷贝可以大大提高效率,    先取得数据指针: output_tensor->flat<float>().data();再直接对象拷贝好了 std::copy(p, p + arrSize, imgTensorFlat + t * arrSiz

  • tensorflow的读书笔记2022-04-25 00:35:23

    #定义一个2行3列全为0的矩阵 tensor1 = tf.zeros([2,3]) print(tensor1)"""运行结果:tf.Tensor([[0. 0. 0.][0. 0. 0.]], shape=(2, 3), dtype=float32)"""#定义一个2行2列全为1的矩阵 ones_tsr = tf.ones([2, 2])print(ones_tsr)"""运行结果:  tf.Tensor( [[1

  • 深度学习笔记2022-04-25 00:02:36

    tensorflow中的tensor就是张量,是多维数组(多维列表),用阶来表示张量的维数,判断张量是几阶的可以看有几个方括号 import tensorflow as tf a=tf.constant([1,5],dtype=tf.int64) #直接打印a,会输出a的所有信息 print(a) #打印a的数据类型 print(a.dtype) #打印a的形状 print(a.shap

  • Tensflow学习笔记2022-04-24 22:33:00

    import tensorflow as tf sess=tf.compat.v1.Session()a=tf.constant(32) #创建常量b=tf.constant(10) #创建常量#加法a+b+bd=tf.add_n([a,b,b])print(d) 运行结果: Tensor("AddN_3:0", shape=(), dtype=int32) #减法a-be=tf.subtract(a,b)print(b) 运行结果: Tensor("Const_17:0&q

  • Variable----pytorch2022-04-18 16:31:45

    tensor 是 PyTorch 中的完美组件,但是构建神经网络还远远不够,我们需要能够构建计算图的 tensor,这就是 Variable。Variable 是对 tensor 的封装,操作和 tensor 是一样的, 但是每个 Variabel都有三个属性,Variable 中的 tensor本身.data,对应 tensor 的梯度.grad以及这个 Variable 是通过

  • Transforms2022-04-17 20:32:53

    一、 from PIL import Image from torch.utils.tensorboard import SummaryWriter from torchvision import transforms # python的用法-》tensor数据类型 # 通过transforms.ToTensor去解决两个问题 # 2、为什么我们需要Tensor数据类型 img_path = "C:\\Users\\admin\Picture

  • tensorflo实现Droppath2022-04-16 23:02:50

    # def drop_path(inputs, keep_prob, is_training=True, scope=None):def drop_path(inputs, keep_prob, is_training=True): """Drops out a whole example hiddenstate with the specified probability. """ # with tf.name_scope(s

  • the size of tensor a (539) must match the size of tensor b (512) at non-singleton dimension 12022-04-09 11:04:03

       明明已经对超过512长度的序列做了处理,但这个怎么都处理不了,经过检查发现在对子句之间添加[SEP]标记时,错误的将[SEP]写成了[sep],致使电脑在识别的时候无法将[sep]识别出来,而是识别成了[ , s , e , p , ] 这几个分开的,所以长度比正常的长而且代码也无法精简到512(虽然已经精简

  • LSTM (Long Short Term Memory) networks2022-04-07 20:34:43

    # Define LSTM class Lstm(nn.Module): def __init__(self, input_size, hidden_size=2, output_size=1, num_layers=1): super().__init__() self.layer1 = nn.LSTM(input_size, hidden_size, num_layers) self.layer2 = nn.Linear(hid

  • 将tensor转换为图像2022-03-30 10:34:05

    import torch from torchvision import transforms toPIL = transforms.ToPILImage() #这个函数可以将张量转为PIL图片,由小数转为0-255之间的像素值 img = torch.randn(3,128,64) pic = toPIL(img) pic.save('random.jpg') 注意transforms.ToPILImage()的参数格式: 将形状为 C

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有