我正在尝试在 Keras 核心层中使用 keras.layers.Permute(dims)
。
根据文档:
dims: Tuple of integers. Permutation pattern, does not include the samples dimension. Indexing starts at 1. For instance, (2, 1) permutes the first and second dimension of the input."
它给出了如下示例代码,
问题是:这个 (2,1) 是做什么的?如果我的输入特征有 10 个维度,我需要将第 1、3、5 个特征的顺序更改为 (5,1,3),那么我是否应该只使用 (5,1,3) 作为参数值这个功能的“暗淡”?
model = Sequential()
model.add(Permute((2, 1), input_shape=(10, 64)))
# now: model.output_shape == (None, 64, 10)
# note: `None` is the batch dimension
最佳答案
permute 函数只是切换轴的位置,dims
参数告诉 Keras 您希望最终位置如何。例如,如果 x
是 4 维的并且形状为 (None, 2, 4, 5, 8)
-(这里的 Batch size 是 None)并且如果你指定 dims = (3, 2, 1, 4)
,则将发生以下四个步骤:
- 三维将移动到第一
- 二次元将移至二次元
- 第一维将移至第三维
- 第四维度将迈向第四维度
请记住,索引从 1
而不是 0
开始。零维是批量大小。所以最终置换层的输出将具有 (5, 4, 2, 8)
的形状。函数np.moveaxis
在 NumPy 中做类似的事情。
对于您的示例,dims 应等于 (5, 2, 1, 4, 3, 6, 7, 8, 9, 10)
。
关于python - keras函数Permute中的参数 'dims'是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53878219/