ValueError:张量转换请求dtype float32的张量为dtype int32:'Tensor(“ embedding_1 / random_uniform:0”,shape =(4518,1),dtype = float32)'
File "C:\PythonProjects\combined\venv\lib\site-packages\tensorflow\python\framework\ops.py", line 1050, in convert_to_tensor as_ref=False):
@tf_export("convert_to_tensor")
def convert_to_tensor(value, dtype=None, name=None, preferred_dtype=None):
File "C:\PythonProjects\combined\venv\lib\site-packages\tensorflow\python\framework\ops.py", line 1146, in internal_convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
internal_convert_to_tensor(value=value,dtype=dtype,name=name,preferred_dtype=preferred_dtype,as_ref=False)
我的问题是如何将dtype更改为int32?
答案 0 :(得分:0)
您可以使用tf.cast(given_tensor, tf.int32)
或tf.to_int32(given_tensor)
将张量从float32投射到int32。