python - Keras 中的反展平层

标签 python keras neural-network reshape flatten

我想创建一个简单的 Keras 神经网络,它接受维度 (rows, columns) = (n, m) 的输入矩阵,将矩阵展平为维度 (n *m, 1),将展平的矩阵发送到多个任意层,并在最后一层,在释放之前再次将矩阵展平到 (n, m) 维度这个最终矩阵作为输出。

我遇到的问题是,我在 keras.io 上没有找到任何有关 Unflatten 图层的文档。页面,我想知道是否存在这样一个看似标准的通用层不存在的原因。有没有一种更自然、更简单的方法来实现我的建议?

最佳答案

您可以使用Reshape层用于此目的。它接受所需的输出形状作为其参数,并将输入张量 reshape 为该形状。例如:

from keras.layers import Reshape

rsh_inp = Reshape((n*m, 1))(inp)  # if you don't want the last axis with dimension 1, you can also use Flatten layer

# rsh_inp goes through a number of arbitrary layers ...

# reshape back the output
out = Reshape((n,m))(out_rsh_inp)

关于python - Keras 中的反展平层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53329659/

相关文章:

python - 在 Python 中通过没有 Content-Disposition 的 POST 发送文件

python - python中属性名称的最大长度是多少?

python-3.x - Keras 中 X 的多项功能

tensorflow - tf.keras 创建 float 类型的随机整数

machine-learning - 神经网络如何提取特征

python - 使用百分号向 panda 数据框添加百分比列

python - 自动将文件分发给用户

machine-learning - 如何在 Keras 中提取训练集和验证集?

machine-learning - 深度学习模型中以前从未见过的类(class)

python - 如何在 scikit-learn 管道中向 Keras 网络添加纪元