博客
关于我
pytorch loss = loss_func(output, label) 报错
阅读量:313 次
发布时间: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/

你可能感兴趣的文章
MySQL8.0.29启动报错Different lower_case_table_names settings for server (‘0‘) and data dictionary (‘1‘)
查看>>
MySQL8修改密码报错ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
查看>>
mysqlbinlog报错unknown variable ‘default-character-set=utf8mb4‘
查看>>
mysqldump 导出中文乱码
查看>>
mysqldump备份时忽略某些表
查看>>
mysqlreport分析工具详解
查看>>
MySQL一个表A中多个字段关联了表B的ID,如何关联查询?
查看>>
MYSQL一直显示正在启动
查看>>
MySQL一站到底!华为首发MySQL进阶宝典,基础+优化+源码+架构+实战五飞
查看>>
MySQL万字总结!超详细!
查看>>
Mysql下载以及安装(新手入门,超详细)
查看>>
mysql中cast() 和convert()的用法讲解
查看>>
mysql中floor函数的作用是什么?
查看>>
MySQL中group by 与 order by 一起使用排序问题
查看>>
mysql中having的用法
查看>>
mysql中int、bigint、smallint 和 tinyint的区别、char和varchar的区别详细介绍
查看>>
mysql中json_extract的使用方法
查看>>
mysql中null和空字符串的区别与问题!
查看>>
Mysql中varchar类型数字排序不对踩坑记录
查看>>
Mysql中存储引擎简介、修改、查询、选择
查看>>