0

为什么我会收到此错误slim.fully_connected()

ValueError: Input 0 of layer fc1 is incompatible with the layer: : expected min_ndim=2, found ndim=1. Full shape received: [32]

我的输入Tensor("batch:0", shape=(32,), dtype=float32)来自tf.train.batch()

  inputs, labels = tf.train.batch(
        [input, label],
        batch_size=batch_size,
        num_threads=1,
        capacity=2 * batch_size)

如果我重塑输入(32,1)它的工作正常。

inputs, targets = load_batch(train_dataset)
print("inputs:", inputs, "targets:", targets)
# inputs: Tensor("batch:0", shape=(32,), dtype=float32) targets: Tensor("batch:1", shape=(32,), dtype=float32)

inputs = tf.reshape(inputs, [-1,1])
targets = tf.reshape(targets, [-1,1])

苗条演练中的示例似乎在没有明确重塑之后就可以工作load_batch()

4

1 回答 1

0

tf.train.batch期望像输入一样的数组,因为标量非常罕见(实际上来说)。所以,你必须重塑你的输入。我认为下一个代码片段会清除问题。

>>> import numpy as np
>>> a = np.array([1,2,3,4])
>>> a.shape
(4,)
>>> a = np.reshape(a,[4,1])
>>> a
array([[1],
       [2],
       [3],
       [4]])
>>>  
于 2018-03-02T03:24:15.360 回答