jeong-tae / RACNN-pytorch

This is a third party implementation of RA-CNN in pytorch.
201 stars 63 forks source link

hi,i don't know what happened .RuntimeError: "exp" not implemented for 'torch.LongTensor' #10

Closed songwaimai closed 5 years ago

songwaimai commented 5 years ago

[] RACNN forward test... Traceback (most recent call last): File "/home/dl2/Songly/RACNN-pytorch-master/models/RACNN.py", line 158, in logits, conv5s, attens = net(x) File "/usr/local/lib/python2.7/dist-packages/torch/nn/modules/module.py", line 477, in call result = self.forward(input, kwargs) File "/home/dl2/Songly/RACNN-pytorch-master/models/RACNN.py", line 49, in forward scaledA_x = self.crop_resize(x, atten1 448) File "/usr/local/lib/python2.7/dist-packages/torch/nn/modules/module.py", line 477, in call result = self.forward(input, kwargs) File "/home/dl2/Songly/RACNN-pytorch-master/models/RACNN.py", line 152, in forward return AttentionCropFunction.apply(images, locs) File "/home/dl2/Songly/RACNN-pytorch-master/models/RACNN.py", line 99, in forward mk = (h(x-w_off) - h(x-w_end)) (h(y-h_off) - h(y-h_end)) File "/home/dl2/Songly/RACNN-pytorch-master/models/RACNN.py", line 76, in h = lambda x: 1 / (1 + torch.exp(-10 x)) RuntimeError: "exp" not implemented for 'torch.LongTensor'

hubutui commented 5 years ago

You need to cast tensor to float type,

RACNN.py
@@ -77,6 +76,8 @@ class AttentionCropFunction(torch.autograd.Function):
         unit = torch.stack([torch.arange(0, in_size)] * in_size)
         x = torch.stack([unit.t()] * 3)
         y = torch.stack([unit] * 3)
+        x = x.float()
+        y = y.float()
songwaimai commented 5 years ago

哇,谢谢,我已经这么做了,程序也通了,但是运行trainer后出现了这个 /usr/bin/python2.7 /home/dl2/Songly/RACNN-pytorch-master/trainer.py [] Set cuda: True [] Loading dataset...

Process finished with exit code 134 (interrupted by signal 6: SIGABRT) 不知道是为什么呢,期待您的回答 @hubutui

jeong-tae commented 5 years ago

@songwaimai yep. he is right. You may need to cast tensor. and... i don't know your characters. can you translate in English?

I am really sorry about progress. I am focusing on the other project now. Here i already aware about some issues. I will fix and improve when i convenient.

please keep follow repo and me to know when it's update. Thank you!

songwaimai commented 5 years ago

Thank you very much for answering my question~ the question has been resolved. i am a newbie of pytorch :-) now the new error happened. when i run trainer.py line235 # response_map = F.upsample(response_map, size=[resize, resize])

[] Set cuda: True [] Loading dataset... /usr/local/lib/python2.7/dist-packages/torch/nn/functional.py:1890: UserWarning: nn.functional.upsample is deprecated. Use nn.functional.interpolate instead. warnings.warn("nn.functional.upsample is deprecated. Use nn.functional.interpolate instead.") Traceback (most recent call last): File "/home/dl2/Songly/RACNN-pytorch-master/trainer.py", line 318, in train() File "/home/dl2/Songly/RACNN-pytorch-master/trainer.py", line 68, in train apn_iter, apn_epoch, apn_steps = pretrainAPN(trainset, trainloader) File "/home/dl2/Songly/RACNN-pytorch-master/trainer.py", line 235, in pretrainAPN response_map = F.upsample(response_map, size=[resize, resize]) File "/usr/local/lib/python2.7/dist-packages/torch/nn/functional.py", line 1891, in upsample return interpolate(input, size, scale_factor, mode, align_corners) File "/usr/local/lib/python2.7/dist-packages/torch/nn/functional.py", line 1965, in interpolate return torch._C._nn.upsample_nearest1d(input, _output_size(1)) RuntimeError: Expected a list of 1 ints but got 2 for argument #2 'output_size'

Process finished with exit code 1 i don't know why~ i am looking forward your answer~

hubutui commented 5 years ago
nn.functional.upsample is deprecated. Use nn.functional.interpolate instead

this log is clear enough. And the arg/param changed a little, see torch.nn.functional.interpolate for detail.

PS: discussion in English helps others understand you and reply to your issue.

songwaimai commented 5 years ago

ok,thank U very much. Now the program can run! I appreciate it~

jeong-tae commented 5 years ago

Seems solved issue. I will close it. If you have new question or find bug, please make new issue

doublemanyu commented 5 years ago

ok,thank U very much. Now the program can run! I appreciate it~

hi, I run the code recently. Now I have the question like this even I used nn.functional.interpolate instead. I change the line230 "response_map = F.upsample(response_map, size = [resize, resize])" into response_map = F.interpolate(response_map, size=(resize, resize)), but it doesn't work. How can I solve it? Thanks in advance. Traceback (most recent call last): File "C:\Anaconda3\lib\site-packages\torch\utils\data\dataloader.py", line 399, in del self._shutdown_workers() File "C:\Anaconda3\lib\site-packages\torch\utils\data\dataloader.py", line 378, in _shutdown_workers self.worker_result_queue.get() File "C:\Anaconda3\lib\multiprocessing\queues.py", line 345, in get return ForkingPickler.loads(res) File "C:\Anaconda3\lib\site-packages\torch\multiprocessing\reductions.py", line 167, in rebuild_storage_filename storage = cls._new_shared_filename(manager, handle, size) RuntimeError: Couldn't open shared event: , error code: <2>

Process finished with exit code 1

doublemanyu commented 5 years ago

You need to cast tensor to float type,

RACNN.py
@@ -77,6 +76,8 @@ class AttentionCropFunction(torch.autograd.Function):
         unit = torch.stack([torch.arange(0, in_size)] * in_size)
         x = torch.stack([unit.t()] * 3)
         y = torch.stack([unit] * 3)
+        x = x.float()
+        y = y.float()

Hi, I changed it like you. But it doesn't work. The error like this Traceback (most recent call last): File "L:/project/RACNN-pytorch-master/models/RACNN.py", line 176, in loss = loss_cls + loss_rank TypeError: add() received an invalid combination of arguments - got (list), but expected one of:

How can I solve it? Thank you in advance

songwaimai commented 5 years ago

I solve the problem:

  1. unit = torch.stack([torch.arange(0, in_size)] in_size) x = torch.stack([unit.t()] 3) y = torch.stack([unit] * 3)
    • x = x.float()
    • y = y.float()
  2. nn.functional.upsample is deprecated. Use nn.functional.interpolate instead. then it can work, I hope this can help u~
YananGu commented 5 years ago

@songwaimai Hi , did you obtain the performance mentioned in the origin paper using this code?

xqq-hub commented 4 years ago

@songwaimai hi,How to solve your second problem? I change the code to 'response_map = f.interpolate (response_map, size = [resize, resize])' , but the same error will be reported

jeong-tae commented 4 years ago

Thank you for you guys attention to this repo. I've updated to solve many issues. probably, many errors come from changing of pytorch version and I update few lines. I hope this helps you guys!

I will update more soon if possible. Unfortunately and fortunately Coronavirus19 makes me stay home more and it leads me to fix this repo.

Keep letting me know if there is a problem!