当前位置:网站首页>RuntimeError: “max_pool2d“ not implemented for ‘Long‘
RuntimeError: “max_pool2d“ not implemented for ‘Long‘
2022-07-01 04:45:00 【booze-J】
Sample code :
import torch
# The input image (5X5)
from torch import nn
from torch.nn import MaxPool2d
# RuntimeError: "max_pool2d" not implemented for 'Long' This error is a data type error , So we need a input Add a data type restriction
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]])
# from [ Official documents ](https://pytorch.org/docs/stable/generated/torch.nn.MaxPool2d.html#torch.nn.MaxPool2d) Given API You can know the details of use requirement The input of is four-dimensional
# (batch_size,channels,H,W)=(-1,1,5,5) The first one is -1 to -1 Is to let him calculate batch_size
input = torch.reshape(input,(-1,1,5,5))
print(input.shape)
# Building neural networks
class Booze(nn.Module):
# Inherit nn.Module The initialization
def __init__(self):
super(Booze, self).__init__()
self.maxpool1 = MaxPool2d(kernel_size=3,ceil_mode=True)
# rewrite forward function
def forward(self,x):
output = self.maxpool1(x)
return output
obj = Booze()
output = obj(input)
print(output)
An error occurs when running this code :RuntimeError: "max_pool2d" not implemented for 'Long'
.
This error is a data type error , So we have to deal with this input Add a data type restriction .
The problem code is
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]])
This code . Put data type restrictions on it dtype=torch.float32
. I'll change it to
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)
Run the result again and no error will be reported .
边栏推荐
- Common interview questions ①
- Registration of P cylinder filling examination in 2022 and analysis of P cylinder filling
- [pat (basic level) practice] - [simple simulation] 1064 friends
- 分布式锁的实现
- Maixll-Dock 快速上手
- LeetCode_ 58 (length of last word)
- VIM easy to use tutorial
- 神经网络-最大池化的使用
- 2022 hoisting machinery command registration examination and hoisting machinery command examination registration
- 科研狗可能需要的一些工具
猜你喜欢
2022 G2 power station boiler stoker examination question bank and G2 power station boiler stoker simulation examination question bank
slf4j 简单实现
The junior college students were angry for 32 days, four rounds of interviews, five hours of soul torture, and won Ali's offer with tears
RuntimeError: “max_pool2d“ not implemented for ‘Long‘
2022 a special equipment related management (elevator) simulation test and a special equipment related management (elevator) certificate examination
Extension fragment
分布式架构系统拆分原则、需求、微服务拆分步骤
神经网络-使用Sequential搭建神经网络
Simple implementation of slf4j
MySQL winter vacation self-study 2022 12 (5)
随机推荐
解决qiankun中子应用外链文件无法获取
One click shell to automatically deploy any version of redis
How do I sort a list of strings in dart- How can I sort a list of strings in Dart?
2022 gas examination question bank and online simulation examination
OdeInt與GPU
2022年T电梯修理题库及模拟考试
LeetCode_ 35 (search insertion position)
LeetCode_35(搜索插入位置)
软件研发的十大浪费:研发效能的另一面
LeetCode_66(加一)
Matters behind the construction of paint testing laboratory
LeetCode_28(实现 strStr())
LM小型可编程控制器软件(基于CoDeSys)笔记二十:plc通过驱动器控制步进电机
2022 t elevator repair new version test questions and t elevator repair simulation test question bank
STM32扩展板 数码管显示
[FTP] the solution to "227 entering passive mode" during FTP connection
科研狗可能需要的一些工具
神经网络-非线性激活
【硬十宝典目录】——转载自“硬件十万个为什么”(持续更新中~~)
STM32 photoresistor sensor & two channel AD acquisition