brooklyn1900 / CRAFT_pytorch

A reimplementation of Character Region Awareness for Text Detection (CRAFT) with training code
80 stars 23 forks source link

请问pytorch是那一个版本 #7

Open Waynepoo opened 4 years ago

Waynepoo commented 4 years ago

在训练的时候报这个错误

len train data: 1145 epoch = 0 Traceback (most recent call last): File "train_finetune.py", line 143, in model_save_prefix = model_save_prefix) File "train_finetune.py", line 96, in train device) File "/mnt/data/psenet_demo/ocr/CRAFT_pytorch-master_train/CRAFT_pytorch-master/utils/cal_loss.py", line 70, in cal_fakeData_loss loss1_fg = criterion(score_text[np.where(labels_region > 0.1)], labels_region[np.where(labels_region > 0.1)]) File "<__array_function__ internals>", line 6, in where File "/opt/conda/lib/python3.6/site-packages/torch/tensor.py", line 450, in array return self.numpy() TypeError: can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

2793145003 commented 4 years ago

插眼。遇到了同样的问题。 计算loss时所有参数加上.cpu()可以正常跑,但我觉得这好像不是正常的解决方法……

zcswdt commented 4 years ago

在训练的时候报这个错误

len train data: 1145 epoch = 0 Traceback (most recent call last): File "train_finetune.py", line 143, in model_save_prefix = model_save_prefix) File "train_finetune.py", line 96, in train device) File "/mnt/data/psenet_demo/ocr/CRAFT_pytorch-master_train/CRAFT_pytorch-master/utils/cal_loss.py", line 70, in cal_fakeData_loss loss1_fg = criterion(score_text[np.where(labels_region > 0.1)], labels_region[np.where(labels_region > 0.1)]) File "<array_function internals>", line 6, in where File "/opt/conda/lib/python3.6/site-packages/torch/tensor.py", line 450, in array return self.numpy() TypeError: can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

我也遇到和你一样的问题,请问你这个问题解决了吗?

zcswdt commented 4 years ago

插眼。遇到了同样的问题。 计算loss时所有参数加上.cpu()可以正常跑,但我觉得这好像不是正常的解决方法……

请教一下你是如何操作的呢?我遇到这个问题目前没解决、期待你的回复。

wting861006 commented 3 years ago

np.where改成torch.where试试

wting861006 commented 3 years ago
# loss1_fg = criterion(score_text[np.where(labels_region > 0.1)], labels_region[np.where(labels_region > 0.1)])
loss1_fg = criterion(score_text[torch.where(labels_region > 0.1)], labels_region[torch.where(labels_region > 0.1)])
loss1_fg = torch.sum(loss1_fg) / numPos_region.to(torch.float32)
# loss1_bg = criterion(score_text[np.where(labels_region <= 0.1)], labels_region[np.where(labels_region <= 0.1)])
loss1_bg = criterion(score_text[torch.where(labels_region <= 0.1)], labels_region[torch.where(labels_region <= 0.1)])
#selects the pixel with high loss in the negative pixels
loss1_bg, _ = loss1_bg.sort(descending=True)
loss1_bg = torch.sum(loss1_bg[:numNeg_region]) / numNeg_region.to(torch.float32)
# loss2_fg = criterion(score_link[np.where(labels_affinity > 0.1)], labels_affinity[np.where(labels_affinity > 0.1)])
loss2_fg = criterion(score_link[torch.where(labels_affinity > 0.1)], labels_affinity[torch.where(labels_affinity > 0.1)])
loss2_fg = torch.sum(loss2_fg) / numPos_affinity.to(torch.float32)
# loss2_bg = criterion(score_link[np.where(labels_affinity <= 0.1)], labels_affinity[np.where(labels_affinity <= 0.1)])
loss2_bg = criterion(score_link[torch.where(labels_affinity <= 0.1)], labels_affinity[torch.where(labels_affinity <= 0.1)])