【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才行。

文章来自:https://www.cnblogs.com/japyc180717/p/9321694.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3