ValueError: The two structures don't have the same sequence length. Input structure has length 4, while shallow structure has length 3.

ValueError: The two structures don't have the same sequence length. Input structure has length 4, while shallow structure has length 3.

整体报错:

/opt/conda/lib/python3.6/site-packages/tensorflow/python/util/nest.py:1460 map_structure_with_tuple_paths_up_to
expand_composites=expand_composites)
/opt/conda/lib/python3.6/site-packages/tensorflow/python/util/nest.py:1091 assert_shallow_structure
input_length=len(input_tree), shallow_length=len(shallow_tree)))
ValueError: The two structures don't have the same sequence length. Input structure has length 4, while shallow structure has length 3.

参考资料

ValueError: The two structures don‘t have the same sequence length._input structure has length 2, while shallow struct_qq_34292087的博客-CSDN博客

ValueError: The two structures don't have the same sequence length. Input structure has length 0, while shallow structure has length 9. · Issue #17 · FurkanOM/tf-faster-rcnn · GitHub

https://stackoverflow.com/questions/71350360/valueerror-the-two-structures-dont-have-the-same-sequence-length-input-struct

解决

问题主要是两组结构的序列长度不同,这里需要检查一下所使用的特征以及模型结构的输入输出维度是否发生变化。

在我这个代码当中,主要是模型的输出头的个数发生了变化,在dataset当中配置了4个label输出,实际模型错误地写成了3个输出头。

比如

task_output = [task_ouput_1, task_output_2, task_output_3]
train_model = tf.keras.models.Model(inputs=get_keras_model_input(inputs, task_outputs)

修改成

task_output = [task_ouput_1, task_output_2, task_output_3, task_output_4]
train_model = tf.keras.models.Model(inputs=get_keras_model_input(inputs, task_outputs)
posted @ 2023-03-14 10:45  NoMornings  阅读(118)  评论(0编辑  收藏  举报