当前位置:网站首页>Solution: runtimeerror: expected object of scalar type int but got scalar type double
Solution: runtimeerror: expected object of scalar type int but got scalar type double
2022-07-26 04:15:00 【Huai's blog】
Problem description :
Recently, I am writing code using neural network prediction , After replacing the imported data , The original loss function ( As shown below ) Report errors RuntimeError: Expected object of scalar type Int but got scalar type Double. Later according to CSDN Many blog posts on try to use many methods , for example :loss Function is preceded by X=torch.tensor(np.int(X)) perhaps y=torch.IntTensor(y), But then again “ValueError: only one element tensors can be converted to Python scalar Waiting for a wrong report , So according to other blog posts, it is changed to X= torch.tensor([item.cpu().detach().numpy() for item in np.int(X)]).cuda(), So I went back to the above error report , It's a headache .
for X,y in data_iter(batch_size,train_feature,train_label):# Internal circulation training one batch
l=loss(X,y).sum() # Calculate the gap between the output of the model and the real data
Solution :
In fact, solving this problem is very simple , Because the suffix of the imported table is xlsx( namely : natural Excel file ), Just save the file as csv The format is just ( It should be noted that , The number of reads must be utf-8, Otherwise, when reading, it will be due to csv The encoding format in is ‘ANSI’, and Python 3 The default read format is ‘utf-8’, Lead to decode abnormal . Therefore, an error will be reported ’utf-8’ codec can’t decode bytes in position 16: invalid continuation byte).
After adding the suffix from xlsx Change it to csv after , Read the file smoothly and train , There is no other error report in the middle (ヾ(◍°∇°◍)ノ゙ Kaisensen ~ Kaisensen ~)
Reason for modification :
1、CSV It's a plain text file ,excel It's not plain text ,excel Contains a lot of format information in it . namely :CSV It's a plain text file ,CSV The file in windows The default opening mode of the platform is excel, But its essence is a text file .excel It's not plain text ,Excel It's a binary file , It saves information about all worksheets in the workbook . therefore ,csv The document is more pure .
Other reasons :
1、CSV The file size will be smaller , Creating a distribution is easier to read , Suitable for storing structured information , For example, export of records , Traffic statistics, etc .
2、 Because there is no clear distinction or distinction between numerical value and text ,Excel You can use the automatic formatting function to confuse the values .
CSV It's safer , Value and text can be clearly distinguished .CSV Do not process data and store as is .
3、Excel More memory is consumed when importing data . Import CSV Files can be faster , And consume less memory .
4、Excel Files can only be used Microsoft Excel documents opening .CSV It can be used Windows Open any text editor in , Like Notepad ,MS Excel,Microsoft Works 9 etc. .
reference :
https://www.cnblogs.com/Dongmy/p/16434120.html
https://blog.csdn.net/qq_38703529/article/details/120216078
https://blog.csdn.net/qq_18649781/article/details/90771682
https://blog.csdn.net/qq_38703529/article/details/120216078
https://blog.csdn.net/yzf0011/article/details/93321576
边栏推荐
- 2021 CIKM |GF-VAE: A Flow-based Variational Autoencoder for Molecule Generation
- Sorting and searching
- Makefile knowledge rearrangement (super detailed)
- Implementation of distributed lock
- makefile知识再整理(超详细)
- Recommendation Book Educational Psychology: a book for tomorrow's teachers~
- 支持代理直连Oracle数据库,JumpServer堡垒机v2.24.0发布
- MATLAB绘图
- How to choose the key words of the thesis?
- Apisex's exploration in the field of API and microservices
猜你喜欢

(翻译)按钮位置约定能强化用户使用习惯

Soft simulation rasterization renderer

Helloworld案例分析

综合评价与决策方法

Share | 2022 big data white paper of digital security industry (PDF attached)

2021 CIKM |GF-VAE: A Flow-based Variational Autoencoder for Molecule Generation
![Matrix and Gauss elimination [matrix multiplication, Gauss elimination, solving linear equations, solving determinants] the most detailed in the whole network, with examples and sister chapters of 130](/img/84/e5cb5199fe4602440b50dfc4afe963.gif)
Matrix and Gauss elimination [matrix multiplication, Gauss elimination, solving linear equations, solving determinants] the most detailed in the whole network, with examples and sister chapters of 130

Makefile knowledge rearrangement (super detailed)

零售连锁门店收银系统源码管理商品分类的功能逻辑分享

Acwing第 61 场周赛【完结】
随机推荐
[Reading Notes - > data analysis] 01 introduction to data analysis
Recommendation Book Educational Psychology: a book for tomorrow's teachers~
[Reading Notes - > data analysis] Introduction to BDA textbook data analysis
Advanced content of MySQL -- three MySQL logs that must be understood binlog, redo log and undo log
What are the differences between vite and wenpack?
【第019问 Unity中对SpherecastCommand的理解?】
综合评价与决策方法
[binary tree] the longest interleaved path in a binary tree
HelloWorld case analysis
工程师如何对待开源 --- 一个老工程师的肺腑之言
How to make your language academic when writing a thesis? Just remember four sentences!
Web Test Method Encyclopedia
2021 CIKM |GF-VAE: A Flow-based Variational Autoencoder for Molecule Generation
【SVN】一直出现 Please execute the ‘Cleanup‘ command,cleanup以后没有反应的解决办法
Graph theory: topological sorting
Functions of anonymous functions
Trust sums two numbers
Firewall command simple operation
Pat class a 1039 course list for student
How to choose the key words of the thesis?