Fluid版本在不固定shape的输入时,pool层报错
Created by: yeyupiaoling
环境
- PaddlePaddle 1.4.1
问题
就如下面的代码,如果去掉pool层就可以正常运行,
# 加载库
import paddle.fluid as fluid
import cv2
import numpy as np
# 定义网络
def cnn(img):
S_conv_1 = fluid.layers.conv2d(input=img, num_filters=24, filter_size=5, act="relu")
S_conv_pool_1 = fluid.layers.pool2d(input=S_conv_1, pool_size=2, pool_stride=2)
return S_conv_pool_1
# 定义输入数据的占位符
image = fluid.layers.data(name='image', shape=[-1, 1, None, None], dtype='float32')
prediction = cnn(image)
# 对图片进行预处理
def load_image(path):
img = cv2.imread(path)
# 转灰度
img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
# 转换成numpy值
img = np.array(img).astype(np.float32)
img = img / 255.0
return img
# 创建一个使用CPU的执行器
place = fluid.CPUPlace()
exe = fluid.executor.Executor(place)
# 进行参数初始化
exe.run(fluid.default_startup_program())
# 定义两个要计算的变量
img = load_image('0a0eb71384f56d77ced5f6dbcfdfac1e.jpg')[np.newaxis, np.newaxis, ]
# 进行运算,并把y的结果输出
result = exe.run(program=fluid.default_main_program(),
feed={image.name: img},
fetch_list=[prediction])
print(result)
如果不去掉就报错:
paddle.fluid.core.EnforceNotMet: Due to the settings of padding(0), filter_size(2) and stride(2), the output size is less than 0, please check again. Input_size:-1 at [D:\1.4.1\paddle\paddle\fluid\operators\pool_op.cc:40]
PaddlePaddle Call Stacks: