【Pytorch问题】RuntimeError: “max_pool2d“ not implemented for ‘Long‘

简介: 【Pytorch问题】RuntimeError: “max_pool2d“ not implemented for ‘Long‘

问题描述

将如下input作为torch.MaxPool2d的输入

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]])
input = torch.reshape(input, (-1, 1, 5, 5))

报错:
RuntimeError: "max_pool2d" not implemented for 'Long'

解决办法

pytorch中的很多操作不支持Long类型的张量, 只需要把输入的张量改成浮点类型即可

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.reshape(input, (-1, 1, 5, 5))

目录
相关文章
|
2月前
Maximum call stack size exceeded报错的原因及解决办法
Maximum call stack size exceeded报错的原因及解决办法
463 0
|
2月前
|
编译器 C语言
成功解决“Run-Time Check Failure #2 - Stack around the variable ‘arr‘ was corrupted.“问题
成功解决“Run-Time Check Failure #2 - Stack around the variable ‘arr‘ was corrupted.“问题
48 1
|
数据库
解决numpy.core._exceptions.UFuncTypeError: ufunc ‘add‘ did not contain a loop with signature matching
解决numpy.core._exceptions.UFuncTypeError: ufunc ‘add‘ did not contain a loop with signature matching
609 0
解决numpy.core._exceptions.UFuncTypeError: ufunc ‘add‘ did not contain a loop with signature matching
|
12月前
|
存储 异构计算 Python
解决numpy.core._exceptions.MemoryError: Unable to allocate 1.04 MiB for an array
但实际上它保存的不是模型文件,而是参数文件文件。在模型文件中,存储完整的模型,而在状态文件中,仅存储参数。因此,collections.OrderedDict只是模型的值。
1395 0
|
12月前
|
人工智能 编解码 自动驾驶
YOLOv7: Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors
YOLOv7在5 FPS到160 FPS的范围内,在速度和精度方面都超过了所有已知的物体检测器,在GPU V100上以30 FPS或更高的速度在所有已知的实时物体检测器中具有最高的精度56.8% AP。
343 0
|
12月前
Expected more than 1 value per channel when training, got input size torch.Size
因为模型中用了batchnomolization,训练中用batch训练的时候当前batch恰好只含一个sample,而由于BatchNorm操作需要多于一个数据计算平均值,因此造成该错误。
695 0
|
TensorFlow 算法框架/工具
ValueError: Negative dimension size caused by subtracting 5 from 1 for ‘{{node le_net5/conv2d/Conv2D
ValueError: Negative dimension size caused by subtracting 5 from 1 for ‘{{node le_net5/conv2d/Conv2D
133 0
解决办法:RuntimeError: dictionary changed size during iteration
解决办法:RuntimeError: dictionary changed size during iteration
87 0
成功解决lightgbm.basic.LightGBMError: Parameter max_depth should be of type int, got “0.02“
成功解决lightgbm.basic.LightGBMError: Parameter max_depth should be of type int, got “0.02“
|
前端开发
Google Earth Engine——Layer error: Description length exceeds maximum.解决办法
Google Earth Engine——Layer error: Description length exceeds maximum.解决办法
582 0
Google Earth Engine——Layer error: Description length exceeds maximum.解决办法