PaddlePaddle / PaddleHub

Awesome pre-trained models toolkit based on PaddlePaddle. (400+ models including Image, Text, Audio, Video and Cross-Modal with Easy Inference & Serving)【安全加固,暂停交互,请耐心等待】
https://www.paddlepaddle.org.cn/hub
Apache License 2.0
12.72k stars 2.08k forks source link

(InvalidArgument) Tensor holds the wrong type, it holds int, but desires to be int64_t. #1430

Open doraemonlei opened 3 years ago

doraemonlei commented 3 years ago

win10 paddle最新版,cuda10.2

运行 https://www.paddlepaddle.org.cn/tutorials/projectdetail/1925567 桃脸识别例子训练部分报错

from paddlehub.finetune.trainer import Trainer

import paddle

optimizer = paddle.optimizer.Adam(learning_rate=0.001, parameters=model.parameters())
trainer = Trainer(model, optimizer, checkpoint_dir='img_classification_ckpt', use_gpu=True) 
trainer.train(peach_train, epochs=10, batch_size=16, eval_dataset=peach_validate, save_interval=1)
ValueError                                Traceback (most recent call last)
<ipython-input-5-944f9deffa54> in <module>()
      5 optimizer = paddle.optimizer.Adam(learning_rate=0.001, parameters=model.parameters())
      6 trainer = Trainer(model, optimizer, checkpoint_dir='img_classification_ckpt', use_gpu=True)
----> 7 trainer.train(peach_train, epochs=10, batch_size=16, eval_dataset=peach_validate, save_interval=1)

D:\ProgramData\Anaconda3\envs\env_paddle\lib\site-packages\paddlehub\finetune\trainer.py in train(self, train_dataset, epochs, batch_size, num_workers, eval_dataset, log_interval, save_interval, collate_fn)
    204 
    205             for batch_idx, batch in enumerate(loader):
--> 206                 loss, metrics = self.training_step(batch, batch_idx)
    207                 self.optimizer_step(self.current_epoch, batch_idx, self.optimizer, loss)
    208                 self.optimizer_zero_grad(self.current_epoch, batch_idx, self.optimizer)

D:\ProgramData\Anaconda3\envs\env_paddle\lib\site-packages\paddlehub\finetune\trainer.py in training_step(self, batch, batch_idx)
    342             result = self.model._layers.training_step(batch, batch_idx)
    343         else:
--> 344             result = self.model.training_step(batch, batch_idx)
    345 
    346         # process result

D:\ProgramData\Anaconda3\envs\env_paddle\lib\site-packages\paddlehub\module\cv_module.py in training_step(self, batch, batch_idx)
     56             results(dict) : The model outputs, such as loss and metrics.
     57         '''
---> 58         return self.validation_step(batch, batch_idx)
     59 
     60     def validation_step(self, batch: int, batch_idx: int) -> dict:

D:\ProgramData\Anaconda3\envs\env_paddle\lib\site-packages\paddlehub\module\cv_module.py in validation_step(self, batch, batch_idx)
     74         preds, feature = self(images)
     75 
---> 76         loss, _ = F.softmax_with_cross_entropy(preds, labels, return_softmax=True, axis=1)
     77         loss = paddle.mean(loss)
     78         acc = paddle.metric.accuracy(preds, labels)

D:\ProgramData\Anaconda3\envs\env_paddle\lib\site-packages\paddle\utils\deprecated.py in wrapper(*args, **kwargs)
    108                     warningmsg, category=DeprecationWarning, stacklevel=2)
    109 
--> 110             return func(*args, **kwargs)
    111 
    112         return wrapper

D:\ProgramData\Anaconda3\envs\env_paddle\lib\site-packages\paddle\nn\functional\loss.py in softmax_with_cross_entropy(logits, label, soft_label, ignore_index, numeric_stable_mode, return_softmax, axis)
   1113     return fluid_softmax_with_cross_entropy(logits, label, soft_label,
   1114                                             ignore_index, numeric_stable_mode,
-> 1115                                             return_softmax, axis)
   1116 
   1117 

D:\ProgramData\Anaconda3\envs\env_paddle\lib\site-packages\paddle\fluid\layers\loss.py in softmax_with_cross_entropy(logits, label, soft_label, ignore_index, numeric_stable_mode, return_softmax, axis)
   1262             logits, label, 'soft_label', soft_label, 'ignore_index',
   1263             ignore_index, 'numeric_stable_mode', numeric_stable_mode, 'axis',
-> 1264             axis)
   1265         if not return_softmax:
   1266             return loss

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]
haoyuying commented 3 years ago

看报错是由于soft_max_cross_entropy传输的数据类型不正确报错,你可以尝试把img_classification_ckpt文件夹删除,使用paddle2.0 paddlehub2.0,看是否仍然报错。paddle和paddlehub都要先卸载再安装,目前定位问题原因可能是由于卸载和安装paddle不彻底导致的。

wkxu commented 3 years ago

win10,paddle2.1.0,cuda10.1,在本机jupyter下运行,也是碰到同样问题。 后把paddlepaddle和paddlehub均降到2.0.0,也还是报同样错误。不知有没有其他解决方法?