admin管理员组文章数量:1566978
问题
运行报错:
TypeError: 'Specificity' does not have the same nested structure after one iteration.
The two structures don't have the same nested structure.
First structure: type=list str=[]
Second structure: type=list str=[<tf.Tensor 'regular_loss/while/Cast_1:0' shape=() dtype=float32>]
More specifically: The two structures don't have the same number of elements. First structure: type=list str=[]. Second structure: type=list str=[<tf.Tensor 'regular_loss/while/Cast_1:0' shape=() dtype=float32>]
Entire first structure:[]
Entire second structure:[.]
解决方法
用tf.TensorArray()的方法声明“Specificity”变量,如:
Specificity = tf.TensorArray(tf.float32, size=nb_classes)
用对象的write()方法(形如:Specificity = Specificity.write())写入值;用stack()的方法提取值。
原因
函数中定义的“Specificity”在for循环中,属于变化的中间值。当用列表或者字典方法定义时,tf.2x默认为长度固定,所以出现迭代后长度(结构)不同的报错信息。当改用tf.TensorArray()方法时就可以顺利存储和调用循环中动态变化的值。
参考
https://www.tensorflow/guide/function
tensorflow2.0系列(4): Eager Execution和Auto Graph_lxy_Alex的博客-CSDN博'
本文标签: 报错dontstructuresStructureNested
版权声明:本文标题:The two structures dont have the same nested structure... ...报错解决 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/xitong/1725840047a1044920.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论