![](/img/trans.png)
[英]tf.gradients: ValueError: Shapes must be equal rank, but are 2 and 1
[英]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.