kuangliu / pytorch-retinanet

RetinaNet in PyTorch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Expected object of type torch.LongTensor but found type torch.FloatTensor

designerZhou opened this issue · comments

the torch version:torch 0.4.1
When i use python 2.7 to train the project ,found a problem as follow:
`` python train.py
==> Preparing data..

Epoch: 0
Traceback (most recent call last):
File "train.py", line 114, in
train(epoch)
File "train.py", line 68, in train
for batch_idx, (inputs, loc_targets, cls_targets) in enumerate(trainloader):
File "/usr/local/lib/python2.7/dist-packages/torch/utils/data/dataloader.py", line 336, in next
return self._process_next_batch(batch)
File "/usr/local/lib/python2.7/dist-packages/torch/utils/data/dataloader.py", line 357, in _process_next_batch
raise batch.exc_type(batch.exc_msg)
RuntimeError: Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/torch/utils/data/dataloader.py", line 106, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File "/home/wq/retinaNet_pytorch/pytorch-retinanet-master_old/datagen.py", line 120, in collate_fn
loc_target, cls_target = self.encoder.encode(boxes[i].long(), labels[i].long(), input_size=(w,h))
File "/home/wq/retinaNet_pytorch/pytorch-retinanet-master_old/encoder.py", line 78, in encode
anchor_boxes = self._get_anchor_boxes(input_size)
File "/home/wq/retinaNet_pytorch/pytorch-retinanet-master_old/encoder.py", line 52, in _get_anchor_boxes
xy = (xy*grid_size).view(fm_h,fm_w,1,2).expand(fm_h,fm_w,9,2)
RuntimeError: Expected object of type torch.LongTensor but found type torch.FloatTensor for argument #2 'other

I trained this project with voc2012 ,downloaded by myself , i tried to correct this problem, but caused some others problem similarly .

I meet the same problem while i use python 3.6

I meet the same problem while i use python 3.6

so ,did you solve this problem?

I meet the same problem while i use python 3.6

so ,did you solve this problem?

xy = meshgrid(fm_w,fm_h) + 0.5 # [fm_h*fm_w, 2]
xy = xy.float()
I think this repo has some bugs, so choose another work to follow.

I also have the same issues. Can anyone help me

you can solver it by add any code like that:
targets = targets.type(torch.LongTensor)

@Jolntu Hi, where did you change the type of targets? I met the same problem,thx!

See issue #62 for a solution