python - keras函数Permute中的参数 'dims'是什么意思?

标签 python keras

我正在尝试在 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. 三维将移动到第一
  2. 二次元将移至二次元
  3. 第一维将移至第三维
  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/

相关文章:

python - celery 任务没有发送给经纪人

python - 使用 Keras + Flask 蓝图时容器本地主机不存在错误

python - 反射填充 Conv2D

python - 如何在keras预测模型CNN中获得概率百分比

python - Keras:TypeError:无法使用 KerasClassifier 腌制 _thread.lock 对象

python - 值错误 : Negative dimension size caused by subtracting 2 from 1 for 'max_pooling2d_6/MaxPool' (op: 'MaxPool' ) with input shapes: [? ,1,1,64]

Python 如何检查时间是否为午夜,如果为真则不显示时间

python - 如何使用 Python 3 venv 使用 postactivate 脚本?

python - plt.show() 在spyder ide 中不起作用

python - 可以使用 zarr 保存对象数组吗?