- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我读了What is the difference between 'SAME' and 'VALID' padding in tf.nn.max_pool of tensorflow?但这与我的实验不符。
import tensorflow as tf
inputs = tf.random_normal([1, 64, 64, 3])
print(inputs.shape)
conv = tf.keras.layers.Conv2D(6, 4, strides=2, padding='same')
outputs = conv(inputs)
print(outputs.shape)
产生
(1, 64, 64, 3)
(1, 32, 32, 6)
.但是,按照上面的链接会生成 (1, 31, 31, 6)
,因为没有任何填充的过滤器范围之外没有额外的值。
padding='same' 和 strides > 1 的 tf.keras.layers.Conv2D 表现如何?
我想知道确切的答案及其证据。
最佳答案
Keras 使用 TensorFlow 实现填充。文档中提供了所有详细信息 here
First, consider the 'SAME' padding scheme. A detailed explanation ofthe reasoning behind it is given in these notes. Here, we summarizethe mechanics of this padding scheme. When using 'SAME', the outputheight and width are computed as:
out_height = ceil(float(in_height) / float(strides[1]))
out_width = ceil(float(in_width) / float(strides[2]))The total padding applied along the height and width is computed as:
if (in_height % strides[1] == 0):
pad_along_height = max(filter_height - strides[1], 0)
else:
pad_along_height = max(filter_height - (in_height % strides[1]), 0)
if (in_width % strides[2] == 0):
pad_along_width = max(filter_width - strides[2], 0)
else:
pad_along_width = max(filter_width - (in_width % strides[2]), 0)Finally, the padding on the top, bottom, left and right are:
pad_top = pad_along_height // 2
pad_bottom = pad_along_height - pad_top
pad_left = pad_along_width // 2
pad_right = pad_along_width - pad_leftNote that the division by 2 means that there might be cases when thepadding on both sides (top vs bottom, right vs left) are off by one.In this case, the bottom and right sides always get the one additionalpadded pixel. For example, when pad_along_height is 5, we pad 2 pixelsat the top and 3 pixels at the bottom. Note that this is differentfrom existing libraries such as cuDNN and Caffe, which explicitlyspecify the number of padded pixels and always pad the same number ofpixels on both sides.
For the 'VALID' scheme, the output height and width are computed as:
out_height = ceil(float(in_height - filter_height + 1) / float(strides[1]))
out_width = ceil(float(in_width - filter_width + 1) / float(strides[2]))and no padding is used.
关于python - 填充为 ='same' 且步幅 > 1 的 tf.keras.layers.Conv2D 表现如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53819528/
我是 Keras 新手,我正在尝试获取 Keras 中的权重。我知道如何在 Python 中的 Tensorflow 中执行此操作。 代码: data = np.array(attributes, '
我正在尝试为上下文强盗问题 (https://medium.com/emergent-future/simple-reinforcement-learning-with-tensorflow-part
我尝试在单击时向 map 添加新标记,并尝试保存标题和描述以在标记悬停时显示,但出现以下错误: Cannot read property 'add Layer' of undefined Javasc
我想要一个传单图层控件,我可以在其中选择一个基础图层,并使这个基础图层本身成为一个 LayerGroup,我可以从中选择要显示的子图层。我正在考虑一个设置,我单击一个单选按钮来选择基础层(层组),然后
我在 GIMP Script-fu 和过程浏览器中遇到了一个简单的问题。 我正在尝试在具有 40 层的图像中向上/向下移动一个层。让我们调用图像 test.xcf 和所述层 Chromask-snap
我有一个(非常大的)脚本在 InDesign 中运行,该脚本在某一时刻将库资源放置到页面上,然后将其移动到特定图层。此脚本在我们这里的所有计算机上都运行良好,但仅当当时 InDesign 中没有打开其
在一些使用 tf2 的 Tensorflow 教程(例如 Neural Machine Translation with Attention 和 Eager essentials )中,他们定义了自定
现在我无法解决依赖性,怎么了? 公司会更改名称吗?但是,我在他们的网站上看到它,但没有“com.layer.atlas:layer-atlas”,但是我的应用程序包含此依赖项,谁能告诉我原因? 最佳答
我使用 Keras 并尝试将两个不同的层连接成一个向量(向量的第一个值是第一层的值,另一部分是第二层的值)。 其中一层是密集层,另一层是嵌入层。 我知道如何合并两个嵌入层或两个密集层,但我不知道如何合
我正在开发一个类来创建各种对称 AE。我现在把这个类移植到TF 2.0,比我想象的要复杂。但是,我使用层和模型的子类来实现此目的。因此,我想将多个 keras 层分组为一个 keras 层。但如果我想
我正在为 CAGradient 设置动画 let gradientChangeAnimation = CABasicAnimation(keyPath: "colors") gradientC
什么是使用 OOP 在业务逻辑对象和数据库之间分层的良好设计? 最佳答案 这些中的任何一个都可以( from Fowler's POEAA ): 数据源架构模式: 表数据网关:充当数据库表网关的对象。
我正在尝试将一些 UIImages 渲染成一张我可以保存在我的相册中的图像。但是好像 layer.renderInContext 没有考虑图层蒙版? 当前行为:照片保存,我看到了 mosaicLaye
哇,这完全令人困惑,而且 dojo 1.8 文档似乎是围绕构建层的完整 clusterf**k。有人知道那里发生了什么吗? 在构建脚本示例配置文件中,示例 amd.profile.js 有 profi
我的 spacemacs 是 0.200.3@25.1.1 每次启动spacemacs时都会收到警告,如何解决? Warnings: - dotspacemacs-configuration-laye
引用是这样的: There's no problem in Computer Science that can't be solved by adding another layer of abstr
我正在使用 Keras 并且有一个自定义层,但是当我使用它时,会发生以下错误,我不知道问题是什么。你能帮我解决这个问题吗?奇怪的是,当我在另一个系统上使用相同的代码时,没有出现此错误! import
我应该什么时候使用 Input我什么时候应该使用 InputLayer ?在 source code有一个描述,但我不确定它是什么意思。 输入层: Layer to be used as an ent
我正在尝试构建一个可以在音频和视频样本上进行训练的模型,但出现此错误 ValueError:请使用“Layer”实例初始化“TimeDistributed”层。您传递了:Tensor("input_1
我正在实现一个需要支持 mask 的自定义 tf.keras.layers.Layer。 考虑以下场景 embedded = tf.keras.layer.Embedding(input_dim=vo
我是一名优秀的程序员,十分优秀!