深度学习各种错误汇总
1、RuntimeError: Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the same
如上错误是在 torch.onnx.export 时出现的
解决:x造成的,后边加上.cuda()就可以了
import torch model = torch.load('best_055_0.707265_model.pt') device = torch.device("cuda" if torch.cuda.is_available() else "cpu") model.to(device) batch_size = 1 input_shape = (3,384,640) #输入的图像格式 export_onnx_file = "testResNet50.onnx" # 目的ONNX文件名 model.eval() #测试模式 x = torch.randn(batch_size,*input_shape,requires_grad=True).cuda() #生成张量 torch.onnx.export(model, (x,), #元组,因此使用括号 export_onnx_file, export_params=True, # store the trained parameter weights inside the model file opset_version=17, # the ONNX version to export the model to do_constant_folding=True, # 是否执行常量折叠优化 input_names=["input"], # 输入名 output_names=["output"], # 输出名 dynamic_axes={"input": {0: "batch_size"}, # 批处理变量 "output": {0: "batch_size"}})
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2018-10-24 四舍五入
2018-10-24 函数的递归调用