亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

tf.custom_gradient具有多個輸入

tf.custom_gradient具有多個輸入

HUWWW 2021-05-15 19:16:14
tf.custom_gradient僅接受一個Tensor x,如果此操作需要多個輸入呢?例如,定義需要輸入x和label?的Softmax的梯度。更新感謝@AllenLavoie的建議,我使用Python列表作為輸入。def self_define_op_multiple_inputs():    @tf.custom_gradient    def loss_func(input_):        x = input_[0]        label = input_[2]        def grad(dy):            return [dy, dy]        return x - label, grad    x = tf.range(10, dtype=tf.float32)    y = tf.range(10, dtype=tf.int32)    loss = loss_func([x, y])if __name__ == '__main__':    self_define_op_multiple_inputs()看來它將把Python轉換list為Tensor。上面的代碼段將引發TypeError: TypeError: Cannot convert a list containing a tensor of dtype <dtype: 'int32'> to <dtype: 'float32'> (Tensor is: <tf.Tensor 'range_1:0' shape=(10,) dtype=int32>)如何解決?
查看完整描述

2 回答

  • 2 回答
  • 0 關注
  • 145 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號