ValueError: The two structures don‘t have the same sequence length. Input structure has length 4

文章主要讨论了在使用TensorFlow时遇到的ValueError,原因是输入和浅层结构的序列长度不一致。解决方案是检查模型输出和数据集配置,确保两者在输出维度上匹配。例如,模型原本应有4个输出头,但被错误配置为3个。修正这个问题需要调整模型定义,使输出头的数量与数据集要求一致。
摘要由CSDN通过智能技术生成

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

tensorflow2.0 - ValueError: The two structures don't have the same sequence length. Input structure has length 14, while shallow structure has length 10 - Stack Overflow

解决

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

在我这个代码当中,主要是模型的输出头的个数发生了变化,在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)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值