![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Pytorch
DeniuHe
加油!
展开
-
Pytorch调用GPU实现简单的卷积神经网络
"""一个简单的调用GPU的卷积神经网络示例!"""import torchimport torchvisionfrom torchvision import datasetsfrom torchvision import transformsfrom torch.utils.data import DataLoaderbatch_size = 64device = torch.device("cuda:0")class CNN(torch.nn.Module): def.原创 2021-07-13 13:18:56 · 1421 阅读 · 1 评论 -
Pytorch:检验本地GPU是否可用
import torchdevice = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")print(device)原创 2021-07-12 15:42:25 · 295 阅读 · 0 评论 -
论文复现:Active Learning with the Furthest NearestNeighbor Criterion for Facial Age Estimation
import osimport torchimport numpy as npfrom copy import deepcopyfrom collections import OrderedDictfrom PIL import Imagefrom sklearn.model_selection import StratifiedKFoldclass FNN_2DLDA(object): def __init__(self, X_train, y_train, labe...原创 2021-07-08 19:55:09 · 257 阅读 · 5 评论 -
Pytorch:三维矩阵在第一维上取平均值
import torchimport numpy as np# ======初始化一个三维矩阵=====A = torch.ones((6,3,3))# ======替换三维矩阵里面的值======A[0] = torch.ones((3,3)) *2A[1] = torch.ones((3,3)) *5A[2] = torch.ones((3,3)) *5A[3] = torch.ones((3,3)) *5A[4] = torch.ones((3,3)) *5A[5] ...原创 2021-07-08 11:53:32 · 3961 阅读 · 0 评论 -
论文复现 Rank consistent ordinal regression for neural networks withapplication to age estimation
import torchimport torch.nn.functional as Ffrom torch import nnfrom torch.autograd import Variableimport pandas as pdimport numpy as npfrom sklearn.model_selection import train_test_splitfrom sklearn.metrics import accuracy_scorefrom sklearn....原创 2021-07-06 11:46:47 · 382 阅读 · 0 评论 -
论文复现:Ordinal Regression with Multiple Output CNN for Age Estimation-2016 CVPR
该论文是对2001年Frank的一篇二分类分解的序分类模型的卷积神经网络的拓展。Frank E, Hall M. A simple approach to ordinal classification[C]//European Conference on Machine Learning. Springer, Berlin, Heidelberg, 2001: 145-156.该二分类分解方法的缺点就是预测类别之间的概率不一致性,有可能出现负概率的问题。但总之不影响模型的预测。对...原创 2021-07-05 20:05:07 · 338 阅读 · 0 评论 -
Pytorch :OneHot encoding 标签转换 代码
import torchimport numpy as npimport pandas as pddef convertLabel(datasetLabel): """ Labels (product ratings) from the dataset are provided to you as floats, taking the values 1.0, 2.0, 3.0, 4.0, or 5.0. You may wish to train with thes.原创 2021-07-04 13:19:45 · 420 阅读 · 0 评论 -
Pytorch 自定义损失函数
自定义HingeLoss class MyHingeLoss(torch.nn.Module): # 不要忘记继承Module def __init__(self): super(MyHingeLoss, self).__init__() def forward(self, output, target): """output和target都是1-D张量,换句话说,每个样例的返回是一个标量. """ hing..原创 2021-07-03 12:05:06 · 608 阅读 · 0 评论 -
Pytorch 实现简单的二分类
import torchimport torch.nn.functional as Ffrom torch.autograd import Variableimport matplotlib.pyplot as pltimport pandas as pdimport numpy as np# data = np.array(pd.read_csv(r"D:\RegressionData\sin.csv"))# x = data[:,0]# y = data[:,-1]# print(.原创 2021-07-02 20:04:13 · 779 阅读 · 0 评论 -
Pytorch 构建一层网络实现简单的回归预测
import torchimport torch.nn.functional as Ffrom torch.autograd import Variableimport matplotlib.pyplot as pltimport pandas as pdimport numpy as np# data = np.array(pd.read_csv(r"D:\RegressionData\sin.csv"))# x = data[:,0]# y = data[:,-1]# print(.原创 2021-07-02 17:15:18 · 208 阅读 · 0 评论