【问题标题】:TypeError: TypeErro...pected',)类型错误:类型错误...预期的',)
【发布时间】:2019-11-11 02:35:55
【问题描述】:

TypeError: TypeErro...pected',) 将字符串类型张量转换为 float32 并初始化为常量张量。 从文件中读取的值作为字符串类型接收,因此需要转换为 float32。

我怎样才能让它工作?

filename, label, box1, box2, box3, box4, box5, box6, box7, box8 = tf.decode_csv(value, [[''], [''], [''],[''],[''],[''],[''],[''],[''],['']], ' ')
boxes = tf.constant([tf.dtypes.cast(box1, tf.float32),tf.dtypes.cast(box2, tf.float32),tf.dtypes.cast(box3, tf.float32),tf.dtypes.cast(box4, tf.float32),tf.dtypes.cast(box5, tf.float32),tf.dtypes.cast(box6, tf.float32),tf.dtypes.cast(box7, tf.float32),tf.dtypes.cast(box8, tf.float32)]) 

错误是

TypeError: TypeErro...pected',)

【问题讨论】:

  • 以后请不要对错误信息的重要部分进行缩写。

标签: python tensorflow


【解决方案1】:

使用 tf.stack 并解决了。

boxes = tf.transpose(tf.stack([tf.strings.to_number(box1,tf.dtypes.float32),tf.strings.to_number(box2,tf.dtypes.float32),tf.strings.to_number(box3,tf.dtypes.float32),tf.strings.to_number(box4,tf.dtypes.float32),tf.strings.to_number(box5,tf.dtypes.float32),tf.strings.to_number(box6,tf.dtypes.float32),tf.strings.to_number(box7,tf.dtypes.float32),tf.strings.to_number(box8,tf.dtypes.float32)]))

【讨论】:

    猜你喜欢
    • 2023-04-06
    • 2014-09-10
    • 1970-01-01
    • 2019-08-28
    • 2014-06-04
    • 2021-04-23
    • 2013-07-11
    • 1970-01-01
    • 2013-07-12
    相关资源
    最近更新 更多