当前位置:网站首页>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 .
边栏推荐
- Overview of the construction details of Meizhou veterinary laboratory
- Seven crimes of counting software R & D Efficiency
- 科研狗可能需要的一些工具
- LM小型可编程控制器软件(基于CoDeSys)笔记二十:plc通过驱动器控制步进电机
- Leecode question brushing record 1332 delete palindrome subsequence
- RDF query language SPARQL
- 总结全了,低代码还需要解决这4点问题
- Common interview questions ①
- 2022年G1工业锅炉司炉特种作业证考试题库及在线模拟考试
- Difference between cookie and session
猜你喜欢

Kodori tree board

技术分享| 融合调度中的广播功能设计

Question bank and answers for chemical automation control instrument operation certificate examination in 2022

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

Basic usage, principle and details of session

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

Dataloader的使用

LM小型可编程控制器软件(基于CoDeSys)笔记十九:报错does not match the profile of the target

Measurement of quadrature axis and direct axis inductance of three-phase permanent magnet synchronous motor

Maixll-Dock 快速上手
随机推荐
Annual inventory review of Alibaba cloud's observable practices in 2021
2022年聚合工艺考试题及模拟考试
LeetCode_ 58 (length of last word)
2022 t elevator repair new version test questions and t elevator repair simulation test question bank
软件研发的十大浪费:研发效能的另一面
How to do the performance pressure test of "Health Code"
2022 polymerization process test questions and simulation test
The index is invalid
Section 27 remote access virtual private network workflow and experimental demonstration
LM small programmable controller software (based on CoDeSys) note 20: PLC controls stepping motor through driver
分布式全局唯一ID解决方案详解
The longest increasing subsequence and its optimal solution, total animal weight problem
Leecode record 1351 negative numbers in statistical ordered matrix
Shell之Unix运维常用命令
Dual contractual learning: text classification via label aware data augmentation reading notes
Fitness without equipment
How do I sort a list of strings in dart- How can I sort a list of strings in Dart?
[godot] unity's animator is different from Godot's animplayer
【FTP】FTP常用命令,持续更新中……
VIM简易使用教程