简体   繁体   English

如何在 tensorflow 2.0 中提供 padding=6?

[英]how to give padding=6 in tensorflow 2.0?

self.conv6 = tf.keras.layers.Conv2D(1024, kernel_size=3, padding=6,dilation_rate=6) # atrous convolution

this gives error in tensorflow 2.0这会在 tensorflow 2.0 中出现错误
I see the padding='same' option我看到了 padding='same' 选项
but what if I want to give padding=6但是如果我想给 padding=6 怎么办

File "/home/jake/venv/lib/python3.7/site-packages/tensorflow_core/python/keras/utils/conv_utils.py", line 202, in normalize_padding padding = value.lower() AttributeError: 'int' object has no attribute 'lower'文件“/home/jake/venv/lib/python3.7/site-packages/tensorflow_core/python/keras/utils/conv_utils.py”,第 202 行,在 normalize_padding padding = value.lower() AttributeError: 'int' object没有“下”属性

According to the tf.keras.layers.Conv2D documentation, padding can only be either 'same' or 'valid' .根据tf.keras.layers.Conv2D文档, padding只能是'same''valid'

'same' ensures that the spatial dimensions are preserved and 'valid' adds the minimum amount of padding required to ensure that the filter "fits" your spatial dimensions (which can be an issue if stride is anything other than one). 'same'可确保保留空间维度,而'valid'添加所需的最小填充量,以确保过滤器“适合”您的空间维度(如果stride不是一个,这可能是一个问题)。

You shouldn't need to specify an custom padding size as in most cases it would be unnecessary upsampling.您不需要指定自定义填充大小,因为在大多数情况下,这将是不必要的上采样。 But if you must, you can have a padding layer before the conv layer.但是如果你必须,你可以在 conv 层之前有一个 padding 层。

tf.keras.layers.ZeroPadding2D(padding=(6, 6)) # put this before your conv layer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM