今天在使用tensoflow跑cifar10的CNN分類時候,download一個源碼,但是報錯
TypeError: Failed to convert object of type <class 'list'> to Tensor. Contents: [-1, Dimension(4608)]. Consider casting elements to a supported type.
跟蹤發現是tf.reshape()時候報錯!
1 flatten_shape = input.get_shape()[1] * input.get_shape()[2] * input.get_shape()[3] 2 return tf.reshape(input, [-1, flatten_shape], name="flatten")
這里需要改成
flatten_shape = input.get_shape().as_list()[1] * input.get_shape().as_list()[2] * input.get_shape().as_list()[3] return tf.reshape(input, [-1, flatten_shape], name="flatten")
需要使用.as_list()將獲取到的shape轉換成list才行。