当前位置:网站首页>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)
再次运行结果便没有报错。
边栏推荐
- Summary of testing experience - Testing Theory
- [ue4] event distribution mechanism of reflective event distributor and active call event mechanism
- Rule method: number of effective triangles
- After many job hopping, the monthly salary is equal to the annual salary of old colleagues
- C language games (I) -- guessing games
- Question bank and online simulation examination for special operation certificate of G1 industrial boiler stoker in 2022
- [recommended algorithm] C interview question of a small factory
- Concurrent mode of different performance testing tools
- 什么是权限?什么是角色?什么是用户?
- 扩展-Fragment
猜你喜欢

数据加载及预处理

Internet winter, how to spend three months to make a comeback

This sideline workload is small, 10-15k, free unlimited massage

Odeint et GPU

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

2022 tea master (intermediate) examination question bank and tea master (intermediate) examination questions and analysis

Odeint and GPU

2022 Shanghai safety officer C certificate examination question simulation examination question bank and answers

2022年G1工业锅炉司炉特种作业证考试题库及在线模拟考试

Dual contractual learning: text classification via label aware data augmentation reading notes
随机推荐
Kodori tree board
OdeInt與GPU
CF1638E colorful operations
2022 t elevator repair new version test questions and t elevator repair simulation test question bank
[2020 overview] overview of link prediction based on knowledge map embedding
Obtain detailed ideas for ABCDEF questions of 2022 American Games
Strategic suggestions and future development trend of global and Chinese vibration isolator market investment report 2022 Edition
Threejs opening
Maixll-Dock 使用方法
2022 hoisting machinery command registration examination and hoisting machinery command examination registration
Daily question - line 10
Dual Contrastive Learning: Text Classification via Label-Aware Data Augmentation 阅读笔记
2022 polymerization process test questions and simulation test
软件研发的十大浪费:研发效能的另一面
Selenium opens the Chrome browser and the settings page pops up: Microsoft defender antivirus to reset your settings
About the transmission pipeline of stage in spark
Shell之Unix运维常用命令
VIM easy to use tutorial
Tcp/ip explanation (version 2) notes / 3 link layer / 3.4 bridge and switch / 3.4.2 multiple registration protocol (MRP)
Openresty rewrites the location of 302