【发布时间】:2021-08-19 07:52:38
【问题描述】:
我是一个带有 TensorFlow 概率层的构建模型。当我这样做时,model.output.shape,我得到一个错误:
AttributeError: 'UserRegisteredSpec' object has no attribute '_shape'
如果我这样做,output_shape = tf.shape(model.output) 它会给出一个 Keras 张量:
<KerasTensor: shape=(5,) dtype=int32 inferred_value=[None, 3, 128, 128, 128] (created by layer 'tf.compat.v1.shape_15')
我怎样才能得到实际值[None, 3, 128, 128, 128]?
我试过output_shape.get_shape(),但这给出了张量形状[5]。
重现错误的代码:
import tensorflow as tf
import tensorflow_probability as tfp
from tensorflow_probability import distributions as tfd
tfd = tfp.distributions
model = tf.keras.Sequential()
model.add(tf.keras.layers.Input(10))
model.add(tf.keras.layers.Dense(2, activation="linear"))
model.add(
tfp.layers.DistributionLambda(
lambda t: tfd.Normal(
loc=t[..., :1], scale=1e-3 + tf.math.softplus(0.1 * t[..., 1:])
)
)
)
model.output.shape
【问题讨论】:
-
试试
model.layers[-1].output_shape -
没用。
标签: tensorflow shapes tf.keras tensorflow-probability