(predicted == labels).sum().item()作用
⚠️(predicted == labels).sum().item()作用,举个小例子介绍:
# -*- coding: utf-8 -*-
import torch
import numpy as np data1 = np.array([
[1,2,3],
[2,3,4]
])
data1_torch = torch.from_numpy(data1) data2 = np.array([
[1,2,3],
[2,3,4]
])
data2_torch = torch.from_numpy(data2) p = (data1_torch == data2_torch) #对比后相同的值会为1,不同则会为0
print p
print type(p) d1 = p.sum() #将所有的值相加,得到的仍是tensor类别的int值
print d1
print type(d1) d2 = d1.item() #转成python数字
print d2
print type(d2)
返回:
(deeplearning2) userdeMBP:pytorch user$ python test.py
tensor([[1, 1, 1],
[1, 1, 1]], dtype=torch.uint8)
<class 'torch.Tensor'>
tensor(6)
<class 'torch.Tensor'>
6
<type 'int'>
即如果有不同的话,会变成:
# -*- coding: utf-8 -*-
import torch
import numpy as np data1 = np.array([
[,,],
[,,]
])
data1_torch = torch.from_numpy(data1) data2 = np.array([
[,,],
[,,]
])
data2_torch = torch.from_numpy(data2) p = (data1_torch == data2_torch)
print p
print type(p) d1 = p.sum()
print d1
print type(d1) d2 = d1.item()
print d2
print type(d2)
返回:
(deeplearning2) userdeMBP:pytorch user$ python test.py
tensor([[, , ],
[, , ]], dtype=torch.uint8)
<class 'torch.Tensor'>
tensor()
<class 'torch.Tensor'> <type 'int'>
(predicted == labels).sum().item()作用的更多相关文章
- 测试准确率计算方法说明 pre.eq(target).float().sum().item()
测试准确率计算方法说明 pre.eq(target).float().sum().item() 待办 pred = logits.argmax(dim=1) correct += pred.eq(ta ...
- document.all.item作用
1.document.all.myCheckBox和 document.all.item通过控件的名字定位控件,item()中是控件的名字例如:<input type="checkbo ...
- pytorch例子学习——TRAINING A CLASSIFIER
参考:https://pytorch.org/tutorials/beginner/blitz/cifar10_tutorial.html#sphx-glr-beginner-blitz-cifar1 ...
- Note | PyTorch官方教程学习笔记
目录 1. 快速入门PYTORCH 1.1. 什么是PyTorch 1.1.1. 基础概念 1.1.2. 与NumPy之间的桥梁 1.2. Autograd: Automatic Differenti ...
- 【PyTorch v1.1.0文档研习】60分钟快速上手
阅读文档:使用 PyTorch 进行深度学习:60分钟快速入门. 本教程的目标是: 总体上理解 PyTorch 的张量库和神经网络 训练一个小的神经网络来进行图像分类 PyTorch 是个啥? 这是基 ...
- 60 分钟极速入门 PyTorch
2017 年初,Facebook 在机器学习和科学计算工具 Torch 的基础上,针对 Python 语言发布了一个全新的机器学习工具包 PyTorch. 因其在灵活性.易用性.速度方面的优秀表现,经 ...
- 003-simonyanVeryDeepConvolutional2015(VGG)
Very Deep Convolutional Networks for Large-Scale Image Recognition #paper 1. paper-info 1.1 Metadata ...
- 【项目实战】kaggle产品分类挑战
多分类特征的学习 这里还是b站刘二大人的视频课代码,视频链接:https://www.bilibili.com/video/BV1Y7411d7Ys?p=9 相关注释已经标明了(就当是笔记),因此在这 ...
- 学习笔记-ResNet网络
ResNet网络 ResNet原理和实现 总结 一.ResNet原理和实现 神经网络第一次出现在1998年,当时用5层的全连接网络LetNet实现了手写数字识别,现在这个模型已经是神经网络界的“hel ...
随机推荐
- angular $watch 一个变量的变化
$scope.$watch('custArea', function(newValue, oldValue) { angular.forEach(newValue, function(item, ke ...
- 利用js里的Dom和Date,自定义cookie的前端设置方法
通过浏览器访问url时候浏览器会携带cookie,可利用cookie进行信息验证如用户验证,cookie前后端都可获取设置,后端用self.get_cookie和self.set_cookie,前端可 ...
- HDU 1848 Fibonacci again and again(SG函数)
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...
- CentOS-7.2安装Ambari-2.6.1
CentOS-7.2安装Ambari-2.6.1 一.Ambari 是什么? Ambari 跟 Hadoop 等开源软件一样,也是 Apache Software Foundation 中的一个项目, ...
- 人工智能改进传统云ERP的10种方法
http://blog.itpub.net/31542119/viewspace-2168809/ 随着数字化转型的进程加快,企业开始重新评估ERP的作用.传统ERP经过多年僵硬化定制过于追求生产的一 ...
- java对程序的简单加密
File file = new File("oppo.in"); File file1 = new File("main.in"); GregorianCale ...
- 开源项目商业模式分析(2) - 持续维护的重要性 - Selenium和WatiN
该系列第一篇发布后收到不少反馈,包括: 第一篇里说的MonicaHQ不一定盈利 没错,但是问题在于绝大多数开源项目商业数据并没有公开,从而无法判断其具体是否盈利.难得MonicaHQ是公开的,所以才用 ...
- iOS -----------Downloading core failed:
[!] /bin/bash -c set -e sh build.sh cocoapods-setup core is not a symlink. Deleting... Downloading d ...
- iOS中时间与时间戳的相互转化
//获取当前系统时间的时间戳 #pragma mark - 获取当前时间的 时间戳 +(NSInteger)getNowTimestamp{ NSDateFormatter *formatter = ...
- Python random模块方法
random内置模块中的方法注解 random.seed(a=None, version=2) # 初始化伪随机数生成器,若种子a相同,则可以使生成的随机数相同.如果未提供a或者a=None,则使用系 ...