赞
踩
https://github.com/PaddlePaddle/PaddleNLP/pull/330/files
[Window]InvalidArgumentError: Tensor holds the wrong type, it holds int, but desires to be int64_t. #500
我在windows10 上面修复了这个问题。错误的原因是int和int64不匹配。
只需要更改 paddlehub\reader\cv_reader.py 第166行
labels.append([int(label)])
改为
labels.append([np.int64(label)])
希望及时修复,谢谢。
ValueError: (InvalidArgument) 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 < softmax_with_cross_entropy > error]
@davidhefan 是由于windows下,numpy对于int型数据默认的是int32类型,而 softmax_with_cross_entropy op要求是int64类型,导致不匹配报错。
fix label dtype to be compatiable with win #330
Stack API加一下dtype=‘int64’,如下所示
@@ -163,7 +163,7 @@ def do_train():
batchify_fn = lambda samples, fn=Tuple(
Pad(axis=0, pad_val=tokenizer.vocab[tokenizer.pad_token]), # input ids
Pad(axis=0, pad_val=tokenizer.vocab[tokenizer.pad_token]), # token type ids
Stack(), # sequence lens
**Stack(dtype='int64'), # sequence lens**
Pad(axis=0, pad_val=ignore_label) # labels
): fn(list(map(trans_func, samples)))
还报错的话在pad函数里面也加上dtype=‘int64’
Stack(dtype='int64'), # seq_len
Pad(dtype='int64', axis=0, pad_val=label_vocab.get('O', 0)) # label_ids
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。