longcw / yolo2-pytorch

YOLOv2 in PyTorch
1.54k stars 421 forks source link

TypeError with Python 3.5 / PyTorch 0.1.10_2 #6

Closed wilrich-msft closed 7 years ago

wilrich-msft commented 7 years ago

Hi,

I've converted a bunch of .py files to Python 3 and am getting now:

(py35) ~/yolo2-pytorch$ python demo.py                                                                                   
load model succ...                                                                                                                          
Traceback (most recent call last):                                                                                                          
  File "demo.py", line 49, in <module>                                                                                                      
    bbox_pred, iou_pred, prob_pred = net(im_data)                                                                                           
  File "/home/wilrich/anaconda3/lib/python3.5/site-packages/torch/nn/modules/module.py", line 202, in __call__                              
    result = self.forward(*input, **kwargs)                                                                                                 
  File "/home/wilrich/yolo2-pytorch/darknet.py", line 177, in forward                                                                       
    conv1s_reorg = self.reorg(conv1s)                                                                                                       
  File "/home/wilrich/anaconda3/lib/python3.5/site-packages/torch/nn/modules/module.py", line 202, in __call__                              
    result = self.forward(*input, **kwargs)                                                                                                 
  File "/home/wilrich/yolo2-pytorch/layers/reorg/reorg_layer.py", line 49, in forward                                                       
    x = ReorgFunction(self.stride)(x)                                                                                                       
  File "/home/wilrich/yolo2-pytorch/layers/reorg/reorg_layer.py", line 15, in forward                                                       
    out = torch.FloatTensor(bsize, out_c, out_h, out_w)                                                                                     
TypeError: torch.FloatTensor constructor received an invalid combination of arguments - got (int, int, float, float), but expected one of:  
 * no arguments                                                                                                                             
 * (int ...)                                                                                                                                
      didn't match because some of the arguments have invalid types: (int, int, float, float)                                               
 * (torch.FloatTensor viewed_tensor)                                                                                                        
 * (torch.Size size)                                                                                                                        
 * (torch.FloatStorage data)                                                                                                                
 * (Sequence data)                                                                                                                          

Thanks for having a look, wr

longcw commented 7 years ago

Division operation in python3 will produce a float number. You can change out_w = w / stride in line 14 to out_w = int(w / stride). So as out_h.