簡體   English   中英

無法計算 Add 作為輸入 #1(從零開始)應該是一個 int32 張量,但它是一個雙張量 [Op:Add]

[英]cannot compute Add as input #1(zero-based) was expected to be a int32 tensor but is a double tensor [Op:Add]

import tensorflow as tf
a = tf.constant(6, name = 'constant_a')
b = tf.constant(3, name = 'constant_b')
c = tf.constant(10, name = 'constant_c')
d = tf.constant(5, name = 'constant_d')
mul = tf.multiply(a, b, name = 'mul')
div = tf.divide(c, d, name = 'div')

這一行給了我錯誤

addn = tf.add(mul, div)

InvalidArgumentError                      Traceback (most recent call last)
<ipython-input-8-387060d1ddd5> in <module>()
----> 1 addn = tf.add(mul, div)

~/.local/lib/python3.5/site-packages/tensorflow_core/python/ops/gen_math_ops.py in add(x, y, name)
    341         raise
    342     except _core._NotOkStatusException as e:
--> 343       _ops.raise_from_not_ok_status(e, name)
    344   # Add nodes to the TensorFlow graph.
    345   try:

~/.local/lib/python3.5/site-packages/tensorflow_core/python/framework/ops.py in raise_from_not_ok_status(e, name)
   6604   message = e.message + (" name: " + name if name is not None else "")
   6605   # pylint: disable=protected-access
-> 6606   six.raise_from(core._status_to_exception(e.code, message), None)
   6607   # pylint: enable=protected-access
   6608 

~/.local/lib/python3.5/site-packages/six.py in raise_from(value, from_value)

InvalidArgumentError: cannot compute Add as input #1(zero-based) was expected to be a int32 tensor but is a double tensor [Op:Add]
addn = tf.add(mul, tf.cast(div, tf.int32))

這有助於

 tf.cast(
        x,
        dtype,
        name=None
    )

很抱歉問一個問題,如果那是愚蠢的!!!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM