【问题标题】:Shapes must be equal rank形状必须是相等的等级
【发布时间】:2018-01-25 17:44:10
【问题描述】:

我想从预训练模型进行迁移学习。我正在关注 guide 从 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的形状是什么?定义bottleneck_input的形状是否也可以打印出来?
  • 这是预训练模型的最后一层,被列为“embeddings:0 shape=(?, 128)”
  • 是的,但我认为你的问题是bottleneck_tensor 的形状。似乎前面有一个额外的维度

标签: python tensorflow


【解决方案1】:

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

tf.squeeze(bottleneck_tensor)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-26
    • 1970-01-01
    • 2021-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-22
    • 1970-01-01
    相关资源
    最近更新 更多