当前位置:网站首页>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)
再次运行结果便没有报错。
边栏推荐
- 软件研发的十大浪费:研发效能的另一面
- Shell之一键自动部署Redis任意版本
- Collect the annual summary of laws, regulations, policies and plans related to trusted computing of large market points (national, ministerial, provincial and municipal)
- [recommended algorithm] C interview question of a small factory
- 2022 polymerization process test questions and simulation test
- Offline installation of Wireshark 2.6.10
- Sorting out 49 reports of knowledge map industry conference | AI sees the future with wisdom
- Introduction of Spock unit test framework and its practice in meituan optimization___ Chapter I
- 2022 gas examination question bank and online simulation examination
- [send email with error] 535 error:authentication failed
猜你喜欢

扩展-Fragment

Concurrent mode of different performance testing tools

离线安装wireshark2.6.10

How to do the performance pressure test of "Health Code"

2022年T电梯修理题库及模拟考试

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

Dual Contrastive Learning: Text Classification via Label-Aware Data Augmentation 阅读笔记

Strategic suggestions and future development trend of global and Chinese vibration isolator market investment report 2022 Edition

Task04 | statistiques mathématiques

TASK04|数理统计
随机推荐
扩展-Fragment
TCP/IP 详解(第 2 版) 笔记 / 3 链路层 / 3.4 桥接器与交换机 / 3.4.2 多属性注册协议(Multiple Registration Protocol (MRP))
How do I sort a list of strings in dart- How can I sort a list of strings in Dart?
Research on medical knowledge atlas question answering system (I)
网站服务器:好用的网站服务器怎么选这五方面要关注
[difficult] sqlserver2008r2, can you recover only some files when recovering the database?
How to choose the right server for website data collection?
The design points of voice dialogue system and the importance of multi round dialogue
Pytorch(二) —— 激活函数、损失函数及其梯度
After many job hopping, the monthly salary is equal to the annual salary of old colleagues
2022年G1工业锅炉司炉特种作业证考试题库及在线模拟考试
TCP server communication flow
Advanced application of ES6 modular and asynchronous programming
尺取法:有效三角形的个数
Programs and processes, process management, foreground and background processes
Account sharing technology enables the farmers' market and reshapes the efficiency of transaction management services
VR线上展览所具备应用及特色
MySQL winter vacation self-study 2022 12 (5)
2022年聚合工艺考试题及模拟考试
RDF query language SPARQL