RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the

简介: RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the

行时出现这个错误:RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same。


主要是mode没有把mode没有调用cuda,而input却调用了,造成了不统一。这两个地方要保持一致。下面举个同时调用cuda的例子


autoencoderModel = autoencoderModel.cuda() 1,声明mode时,调用cuda

criterion = nn.MSELoss()

optimizer = torch.optim.Adam(autoencoderModel.parameters(), lr=LEARNING_RATE)

#=======================================================================================================================

#=======================================================================================================================

# Model Training and Saving

bestLoss = 1

for epoch in range(EPOCHS):

   autoencoderModel.train()

   if epoch % 50 == 0 and epoch > 0:

       optimizer.param_groups[0]['lr'] = optimizer.param_groups[0]['lr'] * 0.1

   for i, autoencoderInput in enumerate(train_loader):

       autoencoderInput = autoencoderInput.cuda()2,input时,调用cuda

       autoencoderOutput = autoencoderModel(autoencoderInput)

       loss = criterion(autoencoderOutput, autoencoderInput)

       optimizer.zero_grad()

       loss.backward()

       optimizer.step()

       if i % PRINT_RREQ == 0:

           print('Epoch: [{0}][{1}/{2}]\t' 'Loss {loss:.4f}\t'.format(epoch, i, len(train_loader), loss=loss.item()))


目录
相关文章
RuntimeError: Given groups=1, weight of size 64 128 1 7, expected input[16,
RuntimeError: Given groups=1, weight of size 64 128 1 7, expected input[16,
3265 0
|
运维 Serverless 数据处理
函数计算产品使用问题之ComfyUI界面没有显示Manager按钮是什么原因
函数计算产品作为一种事件驱动的全托管计算服务,让用户能够专注于业务逻辑的编写,而无需关心底层服务器的管理与运维。你可以有效地利用函数计算产品来支撑各类应用场景,从简单的数据处理到复杂的业务逻辑,实现快速、高效、低成本的云上部署与运维。以下是一些关于使用函数计算产品的合集和要点,帮助你更好地理解和应用这一服务。
|
PyTorch 算法框架/工具
Pytorch中Trying to backward through the graph和one of the variables needed for gradient错误解决方案
Pytorch中Trying to backward through the graph和one of the variables needed for gradient错误解决方案
2574 0
Pytorch中Trying to backward through the graph和one of the variables needed for gradient错误解决方案
|
机器学习/深度学习 计算机视觉 Python
目标检测笔记(三):Mosaic数据增强完整代码和结果展示
本文介绍了Mosaic数据增强技术,通过将四张图片拼接成一张新图,极大丰富了目标检测的背景信息。文章提供了完整的Python代码,涵盖了如何处理检测框并调整其位置,以适应拼接后的图像。Mosaic技术不仅提高了学习效率,还在标准化BN计算时同时考虑了四张图片的数据,从而提升了模型的泛化能力。
1138 1
|
机器学习/深度学习 并行计算 PyTorch
ONNX 优化技巧:加速模型推理
【8月更文第27天】ONNX (Open Neural Network Exchange) 是一个开放格式,用于表示机器学习模型,使模型能够在多种框架之间进行转换。ONNX Runtime (ORT) 是一个高效的推理引擎,旨在加速模型的部署。本文将介绍如何使用 ONNX Runtime 和相关工具来优化模型的推理速度和资源消耗。
6105 4
|
监控 数据挖掘 Linux
Linux服务器PBS任务队列作业提交脚本的使用方法
【8月更文挑战第21天】在Linux服务器环境中,PBS任务队列能高效管理及调度计算任务。首先需理解基本概念:作业是在服务器上执行的任务;队列则是等待执行任务的列表,具有不同的资源限制与优先级;节点指分配给作业的计算资源。
1972 4
|
机器学习/深度学习 编解码 自然语言处理
Transformers 4.37 中文文档(十二)(2)
Transformers 4.37 中文文档(十二)
171 1
get_frontal_face_detector
【6月更文挑战第20天】
316 5
|
机器学习/深度学习 并行计算 PyTorch
【已解决】RuntimeError: CUDA error: device-side assert triggeredCUDA kernel errors might be asynchronous
【已解决】RuntimeError: CUDA error: device-side assert triggeredCUDA kernel errors might be asynchronous