博客
关于我
pytorch loss = loss_func(output, label) 报错
阅读量:303 次
发布时间:2019-03-03

本文共 424 字,大约阅读时间需要 1 分钟。

在运行损失函数时 loss = loss_func(output, label) 时报了两个错 : 

 

1.

RuntimeError: Expected object of scalar type Long but got scalar type Float for argument #2 'target'

这是因为label必须是 LongTensor 类型, 之前是 :

label = t.tensor(float(image[1]))  # image[1]为str类型

改为 :

label = t.tensor(float(image[1])).long()

 

2. 

Assertion `cur_target >= 0 && cur_target < n_classes’ failed

这是因为我的数据集类别是从1开始,需要依次减一,所以要改为 :

label = t.tensor(float(image[1])-1).long()

 

 

转载地址:http://wncq.baihongyu.com/

你可能感兴趣的文章
C# WinForm 监视文件变化程序
查看>>
将本地已有的maven工程导入工作空间
查看>>
这个坑
查看>>
spring boot和sping的一些注解
查看>>
Mybatis整合ehcache
查看>>
Java基础之反射
查看>>
线程池之SingleThreadPool学习
查看>>
对象的创建、内存布局和访问定位
查看>>
Redis支持的5种数据类型
查看>>
FreeRTOS学习笔记(9)——内存管理
查看>>
FreeRTOS学习笔记(10)——中断管理
查看>>
CC2640R2F学习笔记(1)——搭建环境、编译烧写
查看>>
ESP8266学习笔记(10)——官方WebServer
查看>>
CC2640R2F学习笔记(6)——UART串口使用
查看>>
SHELL命令
查看>>
redis命令学习
查看>>
自然划分的3-4-5规则
查看>>
剑指offer Leetcode 37.序列化二叉树
查看>>
剑指offer Leetcode 39.数组中出现次数超过一半的数字
查看>>
Latex中cases环境引入报错
查看>>