![](/img/trans.png)
[英]During training the TensorFlow model(!!Not the Keras model), How to get the input and output of the intermediate layer(op) of the model?
[英]Tensorflow/Keras: how to get the output of an Input layer by channels?
我有一个如下所示的输入层:
>>>inp = tf.keras.Input(shape=(107, 3))
>>>print(inp)
Tensor("input_25:0", shape=(None, 107, 3), dtype=float32)
由于形状是(None, 107, 3)
,我想将每个(None, 107, 1)
用于单独的图层。 我怎么做?
根据一个相关的 GitHub 问题,您可以使用tf.keras.layers.Lambda
按通道拆分输入张量。
import tensorflow as tf
tfkl = tf.keras.layers
inp = tf.keras.Input(shape=(107, 3))
x0 = tfkl.Lambda(lambda x : x[..., 0])(x)
x1 = tfkl.Lambda(lambda x : x[..., 1])(x)
x2 = tfkl.Lambda(lambda x : x[..., 2])(x)
...
是一个Ellipsis
并填充切片以仅获取最后一个切片。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.