关于torch.size()和torch.size(0)
在分类模型测试代码中有以下代码段:
correct = 0
total = 0
# since we're not training, we don't need to calculate the gradients for our outputs
with torch.no_grad():for data in testloader:images, labels = data# calculate outputs by running images through the networkoutputs = net(images)# the class with the highest energy is what we choose as prediction_, predicted = torch.max(outputs.data, 1)total += labels.size(0)correct += (predicted == labels).sum().item()print('Accuracy of the network on the 10000 test images: %d %%' % (100 * correct / total))
其中:
dataiter = iter(test_dataloader)
images, labels = dataiter.next()
print(labels)
print(f"label.size()返回: {labels.size()} \n type: {type(labels.size())}")
print(f"label.size(0)返回: {labels.size(0)} \n type: {type(labels.size(0))}")
tensor([3, 8, 8, 0])>>>label.size()返回: torch.Size([4])
>>> type: <class 'torch.Size'>
>>>label.size(0)返回: 4
>>> type: <class 'int'>
关于torch.size()和torch.size(0)相关推荐
- pytorch torch.Tensor.new_ones()(返回一个与size大小相同的用1填充的张量。 默认返回的Tensor具有与此张量相同的torch.dtype和torch.device)
from https://pytorch.org/docs/1.1.0/tensors.html?highlight=new_ones#torch.Tensor.new_ones new_ones(s ...
- YDOOK:Pytorch : AI : torch.tensor.size() 与 torch.tensor.shape 的区别
YDOOK:Pytorch : AI : torch.tensor.size() 与 torch.tensor.shape 的区别 区别: 1. torch.tensor.size() 可用通过 :t ...
- pytorch(2)Tensor创建和获取tensor的size信息、torch.dtype、torch.device、torch.layout
获取tensor的size信息 >>> import torch >>> from torch.autograd import Variable >>& ...
- Pytorch中torch.numel(),torch.shape,torch.size()和torch.reshape()函数解析
一. torch.numel()函数解析 1. 官网链接 torch.numel(),如下图所示: 2. torch.numel()函数解析 torch.numel(input) → int 返回输入 ...
- git错误:exceeds file size limit of 100.0 MB remote: error: hook declined to update refs/heads/master
今天在git上提交了一个大于100M的文件,结果发现报错如下: remote: warning: Large files detected. remote: error: File a/b/c is ...
- SpringBoot中: Incorrect result size: expected 1, actual 0以及column xxxx not found解决
利用springboot + 数据库来获取学生集合的时候,却发生了报错:column academy not found的错误,对应的代码是这样的: StudentMapper类: public cl ...
- 解决Incorrect result size: expected 1, actual 0!
今日做练习,发现错误Incorrect result size: expected 1, actual 0 这句话的意思是它要一个为1的结果,但是我给它的是0 在论坛找答案,有说不能使用queryFo ...
- pytorch学习——torch.cat和torch.stack的区别
合并tensors torch.cat 沿着特定维数连接一系列张量. torch.stack 沿新维度连接一系列张量. torch.cat 在给定维度中连接给定的 seq 个张量序列. 所有张量必须具 ...
- pytorch拼接函数:torch.stack()和torch.cat()--详解及例子
原文链接: https://blog.csdn.net/xinjieyuan/article/details/105205326 https://blog.csdn.net/xinjieyuan/ar ...
- 2021.08.22学习内容torch.cat()和torch.stack()函数
torch.cat()函数 将两个张量(tensor)拼接在一起,cat是concatnate的意思,即拼接,联系在一起. def cat(tensors: List[torch.Tensor], d ...
最新文章
- 华为mate20 android,华为Mate20 Pro上手:安卓最强机会带来哪些体验惊喜?
- markdown如何设置图片大小_Gitee(码云)实现免费 Markdown 图床
- WINCE 加入驱动DLL步骤
- Git—代码管理、提交及冲突解决流程的思考
- glut编译问题 (程序无法运行)
- 问题 D: Search Problem
- 【Hive】Hive内部表/外部表
- Java开发笔记(一百四十五)FXML布局的伸展适配
- mysql系列之InnoDB存储引擎结构详解
- VS2019提示“未能完成操作,不支持此接口”
- 7个国外社交网络用户数据情况
- 阿里云短信一条价格包含验证码短信/短信通知/推广短信
- 计算机二级c语言程序设计改错,2017年计算机二级C语言上机改错题考点总结
- 5种阿里常用代码检测推荐 | 阿里巴巴DevOps实践指南
- 【PHPWord】PHPWord生成图表-柱形图 | 设置数值类别展示、展示多组数据
- mysql 英文月份_mysql – STR_TO_DATE替换非英文月份名称
- QImage 图片分割、保存
- 深搜和广搜的原理及优缺点
- PS快速蒙版 ——制作动感效果——飞猫
- jQuery vs JavaScript