Paddle 如何将tensorflow的tensor数据转化为paddle的输入数据

qgzx9mmu  于 2021-12-07  发布在  Java
关注(0)|答案(4)|浏览(513)

ernie = ErnieModel.from_pretrained('ernie-1.0')

char_id_sequences、mask_sequences都是tensorflow版本模型的输入数据,
1)使用paddle.to_tensor
ernie_output_layer, ernie_pooled_output = ernie(input_ids=paddle.to_tensor(char_id_sequences),
attention_mask=paddle.to_tensor(mask_sequences),
token_type_ids=None)
Error:paddle.to_tensor不支持tf.tensor 转paddle.tensor

2)直接输入
ernie_output_layer, ernie_pooled_output = ernie(input_ids=char_id_sequences,
attention_mask=mask_sequences,
token_type_ids=None)
Error:ErnieEmbeddings中的ones = paddle.ones_like(input_ids, dtype="int64") 处报错,说input_ids不是paddle.tensor

请问有什么方法能将tensorflow版tensor转成paddle版的tensor,以至paddle.ones_like不会报错吗?

ntjbwcob

ntjbwcob1#

您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网API文档常见问题历史IssueAI社区来寻求解答。祝您生活愉快~

Hi! We've received your issue and please be patient to get responded. We will arrange technicians to answer your questions as soon as possible. Please make sure that you have posted enough message to demo your request. You may also check out the APIFAQGithub Issue and AI community to get the answer.Have a nice day!

mo49yndu

mo49yndu2#

可以先将tensorflow的tensor转为numpy,再使用to_tensor转为paddle的tensor。
如何转换tensorflow的tensor为numpy,可参考 https://stackoverflow.com/questions/34097281/convert-a-tensor-to-numpy-array-in-tensorflow

wlp8pajw

wlp8pajw3#

哎,链接里的方式也都试过了,都无法解决'Tensor' object has no attribute 'numpy'的问题(我是tensorflow 2.6版)

holgip5t

holgip5t4#

可以吧,我用的也是tf2.6版本

相关问题