我正在实现一个空间金字塔池(SPP)层,它提供一个固定大小的矢量作为输出。此SPP层的代码是项目的一部分,该项目将列车作为可变大小图像的模型。因此我将模型的输入形状设置为(None,None,3)。 SPP层将其输入张量作为参数。根据SPP的原始论文,汇集层的窗口和步幅大小定义如下:
window_height= ceil(input_tensor.shape[1]/pooling_level)
window_width= ceil(input_tensor.shape[2]/pooling_level)
stride_height=floor(input_tensor.shape[1]/pooling_level)
stride_width=floor(input_tensor.shape[2]/pooling_level)
但是因为我已经将输入形状设为(None,None,3)因此我得到一个错误,告诉" int 返回非int(类型NoneType)"
以下是我的相同代码:
def Pooling2D(input_tensor, pool_levels):
pool_list=[]
shape=input_tensor.shape
for level in pool_levels:
window_height=np.ceil(int(shape[1])/level)
window_width=np.ceil(int(shape[2])/level)
stride_height=np.floor(int(shape[1])/level)
stride_width=np.floor(int(shape[2])/level)
pooling=MaxPool2D(pool_size=(window_height,window_width),strides=(stride_height,stride_width))(input_tensor)
flattened_tensor=K.flatten(pooling)
pool_list.append(flattened_tensor)
output_tensor=K.concatenate(pool_list,axis=-1)
return(output_tensor)
除了将特定形状设置为输入图像之外,是否有任何解决此错误的方法?
答案 0 :(得分:0)
重新思考你在这里想做什么。
window_height= ceil(input_tensor.shape[1]/pooling_level)
您想要计算窗口宽度而不告诉代码实际图像大小是多少。那么你的代码实际上是做什么
window_height= ceil(None/pooling_level)
我认为你对SPP Layer的作用有点困惑。 SPP层将任意大小的图像作为输入并生成一个 具有固定长度的输出向量。这意味着即使您使用SPP层 你需要知道图像的宽度和高度。这不是缺点或其他原因。 SPP图层将接受任何图像大小。