1. 程式人生 > >【tensorFlow】tf.reshape()報錯信息 - TypeError: Expected binary or unicode string

【tensorFlow】tf.reshape()報錯信息 - TypeError: Expected binary or unicode string

bject port cas inpu dimen div nts sof expec

今天在使用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才行。

【tensorFlow】tf.reshape()報錯信息 - TypeError: Expected binary or unicode string