繁体   English   中英

形状必须相等

[英]Shapes must be equal rank

我想从预先训练的模型中进行转移学习。 我正在遵循Tensorflow的再培训指南

但是,我陷入了一个错误tensorflow.python.framework.errors_impl.InvalidArgumentError: Shapes must be equal rank, but are 3 and 2 for 'input_1/BottleneckInputPlaceholder' (op: 'PlaceholderWithDefault') with input shapes: [1,?,128].

# Last layer of pre-trained model 
# `[<tf.Tensor 'embeddings:0' shape=(?, 128) dtype=float32>]`

with tf.name_scope('input'):
    bottleneck_input = tf.placeholder_with_default(
        bottleneck_tensor,
        shape=[None, 128],
        name='BottleneckInputPlaceholder')

有任何想法吗?

发生这种情况是因为您的bottleneck_tensor的形状为[1, ?, 128]并且您明确声明该形状应为[?, 128] 您可以使用tf.squeeze减少将张量转换为所需形状

tf.squeeze(bottleneck_tensor)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM