![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Pytorch
2021乐乐
交流学习
展开
-
win10 pytorch用GPU 运行代码
1: 首先安装显卡对应的CUDA , 2:打开pytorch 官网 3:验证: import torch DEVICE = ("cuda" if torch.cuda.is_available() else "cpu") print(torch.cuda.is_available()) 输出为true 则证明 已经可以启动显卡运行程序 ...原创 2020-03-18 23:14:55 · 1919 阅读 · 1 评论 -
python 混淆矩阵模板
from sklearn.metrics import confusion_matrix y_true = ["cat", "ant", "cat", "cat", "ant", "bird"] y_pred = ["ant", "ant", "cat", "cat", "ant", "cat"] print(confusion_matrix(y_true, y_pred, labels=[ "...原创 2020-03-15 22:51:14 · 260 阅读 · 0 评论 -
RuntimeError: 1D target tensor expected, multi-target not supported
输出的标签是:[1., 0., 0., 0., 0.], 提取最大值所在的 index labels_=torch.max(labels,1)[1] ### 返回最大值的索引原创 2020-03-13 11:07:02 · 11597 阅读 · 0 评论 -
pytorch data 和 label shape 的变化
1:out: torch.Size([128, 5]) torch.Size([128, 1, 5]) 2: 利用label.view() 进行转化 print("out:",out.shape,label.shape) label = label.view(out.shape[0], out.shape[1]) print(label.shape) ...原创 2020-01-12 00:09:13 · 964 阅读 · 0 评论 -
pytorch 利用BP神经网路对坐标区域进行分类
代码test 部分是meng yu hong 写的 import numpy as np import scipy.io as scio import torch import torch.nn.functional as Fun import torch.nn as nn import torchvision import torchvision.transforms as transfo...原创 2020-01-11 22:24:20 · 548 阅读 · 0 评论 -
pytorch tensor 元素是否相等
import torch import numpy as np x=torch.rand(5,2) print(x) print(x[0],x[3]) a=np.array([[2,3],[3,4],[4,5],[6,0]]) a=torch.from_numpy(a) print(a,a.shape) b=np.array([[2,3],[3,8],[4,5],[3,0]]) b=torch....原创 2020-01-11 22:20:22 · 2814 阅读 · 0 评论 -
one-hot 编码 (字符串和数字类型的标签)
在用Pytorch 验证标签的时候,建议使用ont-hot 编码,这样比较容易实现既定的功能。 直接上代码: 字符串类型 本代码将hello world 换做了矩阵 from numpy import argmax # define input string data = 'hello world' print(data) # define universe of possible in...原创 2020-01-09 10:27:37 · 1821 阅读 · 0 评论 -
简单的LSTM神经网络
import numpy as np import scipy.io as scio import torch import torch.nn as nn import torchvision import torchvision.transforms as transforms from torch.autograd import Variable class simpleLSTM(nn.M...原创 2020-01-06 20:52:57 · 413 阅读 · 1 评论 -
简单RNN网络
import numpy as np import scipy.io as scio import torch import torch.nn as nn import torchvision import torchvision.transforms as transforms class SimpleRnn(nn.Module): def __init__(self,inp...原创 2020-01-06 19:42:26 · 236 阅读 · 0 评论 -
pytorch Variable变量
1:tensor不能反向传播,variable可以反向传播。 2:Variable计算时,它会逐渐地生成计算图。这个图就是将所有的计算节点都连接起来,最后进行误差反向传递的时候,一次性将所有Variable里面的梯度都计算出来,而tensor就没有这个能力。 3:variable 如何转化为numpy 4:Variable有一个名叫data的字段,可以通过它获得被包装起来的那个原始的Ten...转载 2020-01-05 12:02:07 · 345 阅读 · 0 评论 -
pytorch tensor 数据类型的转换
tensor 一共包含的数据类型,数据 class DoubleTensor(Tensor): ... class FloatTensor(Tensor): ... class LongTensor(Tensor): ... class IntTensor(Tensor): ... class ShortTensor(Tensor): ... class CharTensor(Tensor...原创 2020-01-05 11:40:31 · 608 阅读 · 0 评论 -
pytorch Dropout
减低过拟合,一般可以通过:加大训练集、loss function 加入正则化项、Dropout 等途径。本文的主要作用是展示dropout 的作用 设置Dropout时,torch.nn.Dropout(0.5), 这里的 0.5 是指该层(layer)的神经元在每次迭代训练时会随机有 50% 的可能性被丢弃(失活),不参与训练,一般多神经元的 layer 设置随机失活的可能性比神经元少的高。 ...转载 2020-01-05 10:57:29 · 321 阅读 · 0 评论 -
pytorch 之 manual_seed
pytorch 之 manual_seed 的源程序如下,作用:产生固定的随机数 def manual_seed(seed): r"""Sets the seed for generating random numbers. Returns a `torch.Generator` object. Args: seed (int): The de...原创 2020-01-05 10:43:31 · 530 阅读 · 0 评论