当前位置:网站首页>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 :
边栏推荐
- Automatic assembly & set injection
- After 4 years of developing two-sided meituan, we finally lost: the interview question of volatile keyword function and principle
- Flutter development: running the flutter upgrade command reports an error exception:flutter failed to create a directory at... Solution
- Ncnn thread
- Yolov5 ncnn reasoning
- This is a mathematical problem
- C语言基础Day4-数组
- [MCU simulation] (II) keil installation tutorial
- Code demonstration of fcos face detection model in openvino
- SysTick定时器的基础学习以及手撕代码
猜你喜欢
![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“ )

2002 - Can‘t connect to server on ‘127.0.0.1‘ (36)

04_服务注册Eureka

JDBC连接Mysql数据库

Polynomial interpolation fitting (III)
![[PHP] tp6 multi table connection query](/img/f8/a3803f01820082792901bff98bb96c.png)
[PHP] tp6 multi table connection query

JDBC connection to MySQL database

Graphql first acquaintance

【人脸识别】基于直方图Histogram实现人脸识别附matlab代码

Mysql多表查询
随机推荐
[MCU simulation] (XVI) control transfer instructions - unconditional transfer instructions, conditional transfer instructions
D. Permutation Restoration(贪心/双指针/set)
[MCU simulation] (XVIII) control transfer instructions - empty operation instructions
Thinking for half a year
04_服务注册Eureka
Replacement operation not supported by ncnn partial operators
RESNET learning notes
while 循环
Introduction to wangeditor (entry level)
[regression prediction] lithium ion battery life prediction based on particle filter with matlab code
【单片机仿真】(七)寻址方式 — 位寻址
无线用的鉴权代码
Obvious things
[MCU simulation] (XX) org - set start address
Net SNMP development I
It's good to take more exercise
2002 - Can‘t connect to server on ‘127.0.0.1‘ (36)
zsh: command not found: mysql
多表查询——案例练习
Rhce8 Study Guide Chapter 2 use of basic commands