当前位置:网站首页>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)
再次运行结果便没有报错。
边栏推荐
- Leetcode learning - day 36
- Advanced application of ES6 modular and asynchronous programming
- Pytest automated testing - compare robotframework framework
- [ue4] event distribution mechanism of reflective event distributor and active call event mechanism
- 2022-02-15 (399. Division evaluation)
- Shell之分析服务器日志命令集锦
- Use winmtr software to simply analyze, track and detect network routing
- 2022 t elevator repair question bank and simulation test
- Day 52 - tree problem
- Dede collection plug-in does not need to write rules
猜你喜欢
![[pat (basic level) practice] - [simple simulation] 1064 friends](/img/37/0ef0f8aae15ae574be1d76c97497c9.jpg)
[pat (basic level) practice] - [simple simulation] 1064 friends

JVM栈和堆简介

2022年聚合工艺考试题及模拟考试

JS image path conversion Base64 format

Daily question - line 10
![[ue4] event distribution mechanism of reflective event distributor and active call event mechanism](/img/44/6a26ad24d56ddd5156f3a31fa7e0b9.jpg)
[ue4] event distribution mechanism of reflective event distributor and active call event mechanism

Odeint et GPU

Sorting out 49 reports of knowledge map industry conference | AI sees the future with wisdom

I also gave you the MySQL interview questions of Boda factory. If you need to come in and take your own

Kodori tree board
随机推荐
MySQL advanced -- you will have a new understanding of MySQL
Pytorch(四) —— 可视化工具 Visdom
TCP/IP 详解(第 2 版) 笔记 / 3 链路层 / 3.4 桥接器与交换机 / 3.4.2 多属性注册协议(Multiple Registration Protocol (MRP))
Pytorch(二) —— 激活函数、损失函数及其梯度
How to ensure the idempotency of the high concurrency interface?
How to view the changes and opportunities in the construction of smart cities?
The index is invalid
Custom components in applets
The design points of voice dialogue system and the importance of multi round dialogue
[recommended algorithm] C interview question of a small factory
206. reverse linked list
All in all, the low code still needs to solve these four problems
[ue4] event distribution mechanism of reflective event distributor and active call event mechanism
Openresty rewrites the location of 302
Mallbook: how can hotel enterprises break the situation in the post epidemic era?
扩展-Fragment
How do I sort a list of strings in dart- How can I sort a list of strings in Dart?
2022年上海市安全员C证考试题模拟考试题库及答案
I also gave you the MySQL interview questions of Boda factory. If you need to come in and take your own
2022 tea master (intermediate) examination question bank and tea master (intermediate) examination questions and analysis