分类模型测试代码中有以下代码段:

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)相关推荐

  1. 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 ...

  2. YDOOK:Pytorch : AI : torch.tensor.size() 与 torch.tensor.shape 的区别

    YDOOK:Pytorch : AI : torch.tensor.size() 与 torch.tensor.shape 的区别 区别: 1. torch.tensor.size() 可用通过 :t ...

  3. pytorch(2)Tensor创建和获取tensor的size信息、torch.dtype、torch.device、torch.layout

    获取tensor的size信息 >>> import torch >>> from torch.autograd import Variable >>& ...

  4. Pytorch中torch.numel(),torch.shape,torch.size()和torch.reshape()函数解析

    一. torch.numel()函数解析 1. 官网链接 torch.numel(),如下图所示: 2. torch.numel()函数解析 torch.numel(input) → int 返回输入 ...

  5. 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 ...

  6. SpringBoot中: Incorrect result size: expected 1, actual 0以及column xxxx not found解决

    利用springboot + 数据库来获取学生集合的时候,却发生了报错:column academy not found的错误,对应的代码是这样的: StudentMapper类: public cl ...

  7. 解决Incorrect result size: expected 1, actual 0!

    今日做练习,发现错误Incorrect result size: expected 1, actual 0 这句话的意思是它要一个为1的结果,但是我给它的是0 在论坛找答案,有说不能使用queryFo ...

  8. pytorch学习——torch.cat和torch.stack的区别

    合并tensors torch.cat 沿着特定维数连接一系列张量. torch.stack 沿新维度连接一系列张量. torch.cat 在给定维度中连接给定的 seq 个张量序列. 所有张量必须具 ...

  9. pytorch拼接函数:torch.stack()和torch.cat()--详解及例子

    原文链接: https://blog.csdn.net/xinjieyuan/article/details/105205326 https://blog.csdn.net/xinjieyuan/ar ...

  10. 2021.08.22学习内容torch.cat()和torch.stack()函数

    torch.cat()函数 将两个张量(tensor)拼接在一起,cat是concatnate的意思,即拼接,联系在一起. def cat(tensors: List[torch.Tensor], d ...

最新文章

  1. 华为mate20 android,华为Mate20 Pro上手:安卓最强机会带来哪些体验惊喜?
  2. markdown如何设置图片大小_Gitee(码云)实现免费 Markdown 图床
  3. WINCE 加入驱动DLL步骤
  4. Git—代码管理、提交及冲突解决流程的思考
  5. glut编译问题 (程序无法运行)
  6. 问题 D: Search Problem
  7. 【Hive】Hive内部表/外部表
  8. Java开发笔记(一百四十五)FXML布局的伸展适配
  9. mysql系列之InnoDB存储引擎结构详解
  10. VS2019提示“未能完成操作,不支持此接口”
  11. 7个国外社交网络用户数据情况
  12. 阿里云短信一条价格包含验证码短信/短信通知/推广短信
  13. 计算机二级c语言程序设计改错,2017年计算机二级C语言上机改错题考点总结
  14. 5种阿里常用代码检测推荐 | 阿里巴巴DevOps实践指南
  15. 【PHPWord】PHPWord生成图表-柱形图 | 设置数值类别展示、展示多组数据
  16. mysql 英文月份_mysql – STR_TO_DATE替换非英文月份名称
  17. QImage 图片分割、保存
  18. 深搜和广搜的原理及优缺点
  19. PS快速蒙版 ——制作动感效果——飞猫
  20. jQuery vs JavaScript

热门文章

  1. int i =1 是原子操作吗?i++是原子操作吗?
  2. RDMA-Using the QP states
  3. 小米8检查更新显示服务器连接失败,小米助手常见问题及解决方案
  4. ADSL开机自动拨号
  5. 电脑卡的打字都卡。怎么回事。有什么办法解决吗?
  6. VMware ESXi 8.0虚拟机开心版下载!有福利有惊喜!
  7. 网络通信——客户端服务器端交互
  8. 怎么批量免费XPS转PDF
  9. ins风景Mac动态壁纸合集
  10. 何恺明 MIT 最新演讲:未来工作将聚焦 AI for science