当前位置:网站首页>RuntimeError_ Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor)
RuntimeError_ Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor)
2022-07-19 03:20:00 【lucky-wz】
Two solutions
Scheme 1 : Check whether the network and data are GPU On
RuntimeError: Input type (torch.FloatTensor) And weight type (torch.cuda.FloatTensor) It should be the same , Or the input should be a MKLDNN tensor , And weight is a dense tensor .
Our weight is cuda type (GPU Train to get ), And input ( Data to be tested ) No cuda type . use GPU Training model , Not directly in CPU Upper use , Put it in GPU Medium forecast .
If the model parameters used are cuda On (gpu) Trained , When using it for testing , You need to put the data to be tested into GPU On , namely :data.cuda().
Carefully check whether the neural network and related data are placed GPU On !
Option two : Model definitions are all placed in class initialization
Besides , According to the analysis of the boss , May also be , Because your model is defined , Not well defined , As a result, part of the model cannot be transferred to cuda On . The specific test is skipped .
in general , If the above method doesn't work , Then try putting all the network layers ( As long as there are parameters to be trained in the network layer ) in __init__() Function to define , Only in forward() Write the logic of the runtime , namely :
class A(nn.Module):
def __init__(self):
super(A,self).__init__()
self.conv = nn.Conv2d(in_channels=3, out_channels=8, kernel_size=3)
self.relu = nn.ReLU(inplace=True)
self.b_module = B()
def forward(self,x):
out = self.conv(x)
out = self.relu(out)
out = self.b_module(out)
return out
class B(nn.Module):
def __init__(self):
super(B,self).__init__()
self.conv = nn.Conv2d(in_channels=8, out_channels=16, kernel_size=3)
self.relu = nn.ReLU(inplace=True)
def forward(self, x):
out = self.conv(x)
out = self.relu(out)
return out
Reference resources :
边栏推荐
- LETV has more than 400 employees? Living a fairy life without a boss, the official responded
- Yolov5 ncnn reasoning
- Rewrite equals why rewrite hashcode
- Transaction and storage engine in MySQL database
- 数据源对象管理(第三方对象资源) & 加载properties文件
- 【单片机仿真】(十五)指令系统位操作类指令 — 位运算指令、位条件转移指令
- A Youku VIP member account can be used by several people to log in at the same time. How to share multiple people using Youku member accounts?
- Net SNMP related commands
- Ncnn mat matrix class
- [MCU simulation] (XIII) instruction system logic operation instruction shift instruction
猜你喜欢

Es6 notes d'étude - station B Xiao Ma Ge

JPA初识(ORM思想、JPA的基本操作)

05_服务调用Ribbon

自动装配 & 集合注入

Using gatekeeper to restrict kubernetes to create specific types of resources
![2022-07-16:以下go语言代码输出什么?A:[];B:[5];C:[5 0 0 0 0];D:[0 0 0 0 0]。 package main import ( “fmt“ )](/img/e4/ff7f1e19583f42377307de7291f870.png)
2022-07-16:以下go语言代码输出什么?A:[];B:[5];C:[5 0 0 0 0];D:[0 0 0 0 0]。 package main import ( “fmt“ )
![[MCU simulation] (XX) org - set start address](/img/9e/4e44dd779b0de28a190d86fbb1c2c0.png)
[MCU simulation] (XX) org - set start address

05_ Service call ribbon

CorelDRAW cannot be installed. Solution

Code demonstration of fcos face detection model in openvino
随机推荐
Net SNMP development I
Specifications、多表查询基础
重写equals为什么要重写hashcode
【模板记录】字符串哈希判断回文串
[PHP] tp6 multi table connection query
[MCU simulation] (VIII) instruction system - data transmission instruction
Configure high availability using virtual ip+kept
Common MySQL commands you can use
无线用的鉴权代码
Zabbix6.0 monitoring vcenter7.0
ubuntu清除cuda缓存
乐视还有400多位员工?过着没有老板的神仙日子 官方出来回应了...
Rhce8 Study Guide Chapter 2 use of basic commands
Pure virtual function
05-中央处理器
Ncnn mat matrix class
Multi table query - case exercise
MySQL multi table query
[template record] string hash to judge palindrome string
LETV has more than 400 employees? Living a fairy life without a boss, the official responded