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


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM