pytorch-retinanet icon indicating copy to clipboard operation
pytorch-retinanet copied to clipboard

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

Open designerZhou opened this issue 7 years ago • 7 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 .

designerZhou avatar Sep 07 '18 06:09 designerZhou

I meet the same problem while i use python 3.6

holyhao avatar Sep 14 '18 02:09 holyhao

I meet the same problem while i use python 3.6

so ,did you solve this problem?

designerZhou avatar Sep 21 '18 06:09 designerZhou

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.

holyhao avatar Sep 21 '18 08:09 holyhao

I also have the same issues. Can anyone help me

Dev2022 avatar Nov 26 '18 06:11 Dev2022

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

Jolntu avatar Dec 14 '18 05:12 Jolntu

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

Hliang1994 avatar Apr 30 '19 10:04 Hliang1994

See issue #62 for a solution

wvalcke avatar Jun 16 '19 14:06 wvalcke