Skip to main content
 首页 » 编程设计

python之如何在 Tensorflow 中构建 spp-net

2025年02月15日39luoye11

由于 tf.max_pool 不支持可变大小,所以 spp 层不起作用。 我将长度输入图表,但出现错误。

length = tf.placeholder(tf.int32) 
shape=[-1, length,length,32] 
pool = tf.nn.max_pool(output, 
                     ksize=[1, np.ceil(shape[1] * 1. / l).astype(np.int32), np.ceil(shape[2] * 1. / l).astype(np.int32), 1], 
                     strides=[1, np.floor(shape[1] * 1. / l + 1).astype(np.int32), np.floor(shape[2] * 1. / l + 1), 1], 
                          padding='SAME') 

TypeError:应为 int32,得到的是“float”类型的 1.0。

你有什么想法,如何处理它吗?

请您参考如下方法:

在您的步幅参数中,将第三个值更改为整数。 即

np.floor(shape[2] * 1./l + 1) 到 np.floor(shape[2] * 1./l + 1).astype(np .int32)

完整的stride选项:

strides=[1, np.floor(shape[1] * 1. / l + 1).astype(np.int32),  
           np.floor(shape[2] * 1. / l + 1).astype(np.int32), 1], 

希望对你有帮助。