当前位置:网站首页>RuntimeError: “max_pool2d“ not implemented for ‘Long‘
RuntimeError: “max_pool2d“ not implemented for ‘Long‘
2022-07-01 04:35:00 【booze-J】
示例代码:
import torch
# 输入图像(5X5)
from torch import nn
from torch.nn import MaxPool2d
# RuntimeError: "max_pool2d" not implemented for 'Long' 报这个错是数据类型的错误,所以我们要个input加个数据类型的限制
input = torch.tensor([[1,2,0,3,1],
[0,1,2,3,1],
[1,2,1,0,0],
[5,2,3,1,1],
[2,1,0,1,1]])
# 由[官方文档](https://pytorch.org/docs/stable/generated/torch.nn.MaxPool2d.html#torch.nn.MaxPool2d)给出的API使用详情可以知道 要求 的输入是四维的
# (batch_size,channels,H,W)=(-1,1,5,5)第一个给的是-1 给-1就是让他自己计算batch_size
input = torch.reshape(input,(-1,1,5,5))
print(input.shape)
# 搭建神经网络
class Booze(nn.Module):
# 继承nn.Module的初始化
def __init__(self):
super(Booze, self).__init__()
self.maxpool1 = MaxPool2d(kernel_size=3,ceil_mode=True)
# 重写forward函数
def forward(self,x):
output = self.maxpool1(x)
return output
obj = Booze()
output = obj(input)
print(output)
运行该段代码时报错:RuntimeError: "max_pool2d" not implemented for 'Long'。
报这个错是数据类型的错误,所以我们要对这个input加个数据类型的限制.
出问题的代码是
input = torch.tensor([[1,2,0,3,1],
[0,1,2,3,1],
[1,2,1,0,0],
[5,2,3,1,1],
[2,1,0,1,1]])
这一段代码。给它加上数据类型限制dtype=torch.float32。即改成
input = torch.tensor([[1,2,0,3,1],
[0,1,2,3,1],
[1,2,1,0,0],
[5,2,3,1,1],
[2,1,0,1,1]],dtype=torch.float32)
再次运行结果便没有报错。
边栏推荐
- Odeint and GPU
- Day 52 - tree problem
- 2022年上海市安全员C证考试题模拟考试题库及答案
- OdeInt与GPU
- [ue4] event distribution mechanism of reflective event distributor and active call event mechanism
- VIM easy to use tutorial
- Introduction of Spock unit test framework and its practice in meituan optimization___ Chapter I
- Announcement on the list of Guangdong famous high-tech products to be selected in 2021
- Section 27 remote access virtual private network workflow and experimental demonstration
- TCP/IP 详解(第 2 版) 笔记 / 3 链路层 / 3.4 桥接器与交换机 / 3.4.2 多属性注册协议(Multiple Registration Protocol (MRP))
猜你喜欢

2022 G2 power station boiler stoker examination question bank and G2 power station boiler stoker simulation examination question bank

Cmake selecting compilers and setting compiler options

(12) Somersault cloud case (navigation bar highlights follow)

Software testing needs more and more talents. Why do you still not want to take this path?

About the transmission pipeline of stage in spark

【硬十宝典】——2.【基础知识】开关电源各种拓扑结构的特点

VIM easy to use tutorial

How to use maixll dock

Question bank and online simulation examination for special operation certificate of G1 industrial boiler stoker in 2022

Extension fragment
随机推荐
How to view the changes and opportunities in the construction of smart cities?
OdeInt与GPU
This sideline workload is small, 10-15k, free unlimited massage
Task04 mathematical statistics
[ue4] event distribution mechanism of reflective event distributor and active call event mechanism
OdeInt與GPU
Question bank and answers for chemical automation control instrument operation certificate examination in 2022
What is uid? What is auth? What is a verifier?
Caijing 365 stock internal reference | the first IPO of Beijing stock exchange; the subsidiary of the recommended securities firm for gambling and gambling, with a 40% discount
TASK04|數理統計
VIM easy to use tutorial
2022 G2 power station boiler stoker examination question bank and G2 power station boiler stoker simulation examination question bank
Shell analysis server log command collection
Selenium opens the Chrome browser and the settings page pops up: Microsoft defender antivirus to reset your settings
【深度学习】(4) Transformer 中的 Decoder 机制,附Pytorch完整代码
How to do the performance pressure test of "Health Code"
How to choose the right server for website data collection?
Registration for R2 mobile pressure vessel filling test in 2022 and R2 mobile pressure vessel filling free test questions
什么是权限?什么是角色?什么是用户?
TCP/IP 详解(第 2 版) 笔记 / 3 链路层 / 3.4 桥接器与交换机 / 3.4.2 多属性注册协议(Multiple Registration Protocol (MRP))