本文主要是介绍python InvalidArgumentError: Tensor holds the wrong type, it holds int, but desires to be int64_t.,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
完整报错如下:
Traceback (most recent call last):
File “E:\untitled\机器学习\机器学习期末项目\news_classify.py”, line 291, in
result=exe.run(infer_progroam,#预测progr
File “C:\Python39\lib\site-packages\paddle\fluid\executor.py”, line 1110, in run
six.reraise(*sys.exc_info())
File “C:\Python39\lib\site-packages\six.py”, line 719, in reraise
raise value
File “C:\Python39\lib\site-packages\paddle\fluid\executor.py”, line 1098, in run
return self._run_impl(
File “C:\Python39\lib\site-packages\paddle\fluid\executor.py”, line 1231, in _run_impl
return self._run_program(
File “C:\Python39\lib\site-packages\paddle\fluid\executor.py”, line 1328, in _run_program
self._default_executor.run(program.desc, scope, 0, True, True,
ValueError: In user code:
File "E:\untitled\机器学习\机器学习期末项目\news_classify.py", line 188, in <module>model=CNN_net(words,dict_dim)
File "E:\untitled\机器学习\机器学习期末项目\news_classify.py", line 157, in CNN_netemb=fluid.layers.embedding(input=data,size=[dict_dim,emb_dim])
File "C:\Python39\lib\site-packages\paddle\fluid\layers\nn.py", line 511, in embeddinghelper.append_op(
File "C:\Python39\lib\site-packages\paddle\fluid\layer_helper.py", line 43, in append_opreturn self.main_program.current_block().append_op(*args, **kwargs)
File "C:\Python39\lib\site-packages\paddle\fluid\framework.py", line 3226, in append_opop = Operator(
File "C:\Python39\lib\site-packages\paddle\fluid\framework.py", line 2312, in __init__for frame in traceback.extract_stack():InvalidArgumentError: Tensor holds the wrong type, it holds int, but desires to be int64_t.[Hint: Expected valid == true, but received valid:0 != true:1.] (at C:\home\workspace\Paddle_release\paddle/fluid/framework/tensor_impl.h:33)[operator < lookup_table > error]
写机器学习项目时遇到 InvalidArgumentError: Tensor holds the wrong type, it holds int, but desires to be int64_t.说希望我给一个int64的整形,问题的关键在于把哪里的代码改成int64位,下面是我找出错误的流程:
1,看保存信息,哪些行报错了,必须是你写的代码里面的,api里面的不算类似File “C:\Python39\lib\site-packages\paddle\fluid\framework.py”, line 2312, in init
for frame in traceback.extract_stack():这样的就不算。
2.设断点调试,可以更精确的定位出错的位置,一般报错的第一行就是你出错的位置,我是这里
3.找到相应代码
里面有3个参数,一个参数一个参数的找过去,先看text,ctrl+鼠标左键点击texts变量,就会自动跳到使用texts的位置,
原来是加了几个数据倒texts里面,这些数据都经过get_data函数处理,去看看get_data函数,同样ctrl+鼠标左键点击get_data,跳过去看看,
原来我使用了一个int(dict_txt[s]),把它改成np.int64(dict_txt[s])试试,再次运行就成功运行不报错了!yes
这篇关于python InvalidArgumentError: Tensor holds the wrong type, it holds int, but desires to be int64_t.的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!