Faster-rcnn.pytorch: AttributeError: 'int' object has no attribute 'astype'

Created on 14 Jun 2019  Â·  5Comments  Â·  Source: jwyang/faster-rcnn.pytorch

In file "./faster-rcnn.pytorch-master/lib/roi_data_layer/roibatchLoader.py" line:54,self.ratio_list_batch[left_idx:(right_idx+1)] = torch.tensor(target_ratio.astype(np.float64)) # trainset ratio list ,each batch is same number I met the error AttributeError: 'int' object has no attribute 'astype'. My sovle method is remove 'astype(np.float64)'. Although there is no error, is it right ? Has it effect on experients result?

Most helpful comment

/lib/roi_data_layer/roibatchLoader.py
line 52, target_ratio = 1 change to:
target_ratio = np.array(1)

All 5 comments

/lib/roi_data_layer/roibatchLoader.py
line 52, target_ratio = 1 change to:
target_ratio = np.array(1)

/lib/roi_data_layer/roibatchLoader.py
line 52, target_ratio = 1 change to:
target_ratio = np.array(1)

That will be ok. It seems to be right as my modify.

Hi, @Feiyu-Zhang
I also met errors in line 54 of "./faster-rcnn.pytorch-master/lib/roi_data_layer/roibatchLoader.py".
The code is:
self.ratio_list_batch[left_idx:(right_idx + 1)] = torch.tensor(target_ratio.astype(np.float64)) # trainset ratio list ,each batch is same number
The error is:

Traceback (most recent call last):
  File "./faster-rcnn.pytorch-master3/trainval_net.py", line 209, in <module>
    imdb.num_classes, training=True)
  File "./faster-rcnn.pytorch-master3/lib/roi_data_layer/roibatchLoader.py", line 54, in __init__
    self.ratio_list_batch[left_idx:(right_idx + 1)] = torch.tensor(target_ratio.astype(np.float64)) # trainset ratio list ,each batch is same number
TypeError: 'module' object is not callable

If I change the code to self.ratio_list_batch[left_idx:(right_idx + 1)] = torch.Tensor(target_ratio.astype(np.float64)) # trainset ratio list ,each batch is same number, the errors become:

TypeError: torch.FloatTensor constructor received an invalid combination of arguments - got (numpy.float64), but expected one of:
 * no arguments
 * (int ...)
      didn't match because some of the arguments have invalid types: (!numpy.float64!)
 * (torch.FloatTensor viewed_tensor)
      didn't match because some of the arguments have invalid types: (!numpy.float64!)
 * (torch.Size size)
      didn't match because some of the arguments have invalid types: (!numpy.float64!)
 * (torch.FloatStorage data)
      didn't match because some of the arguments have invalid types: (!numpy.float64!)
 * (Sequence data)
      didn't match because some of the arguments have invalid types: (!numpy.float64!)

Could you give me some help? Thanks!

Hi, @Feiyu-Zhang
I also met errors in line 54 of "./faster-rcnn.pytorch-master/lib/roi_data_layer/roibatchLoader.py".
The code is:
self.ratio_list_batch[left_idx:(right_idx + 1)] = torch.tensor(target_ratio.astype(np.float64)) # trainset ratio list ,each batch is same number
The error is:

Traceback (most recent call last):
  File "./faster-rcnn.pytorch-master3/trainval_net.py", line 209, in <module>
    imdb.num_classes, training=True)
  File "./faster-rcnn.pytorch-master3/lib/roi_data_layer/roibatchLoader.py", line 54, in __init__
    self.ratio_list_batch[left_idx:(right_idx + 1)] = torch.tensor(target_ratio.astype(np.float64)) # trainset ratio list ,each batch is same number
TypeError: 'module' object is not callable

If I change the code to self.ratio_list_batch[left_idx:(right_idx + 1)] = torch.Tensor(target_ratio.astype(np.float64)) # trainset ratio list ,each batch is same number, the errors become:

TypeError: torch.FloatTensor constructor received an invalid combination of arguments - got (numpy.float64), but expected one of:
 * no arguments
 * (int ...)
      didn't match because some of the arguments have invalid types: (!numpy.float64!)
 * (torch.FloatTensor viewed_tensor)
      didn't match because some of the arguments have invalid types: (!numpy.float64!)
 * (torch.Size size)
      didn't match because some of the arguments have invalid types: (!numpy.float64!)
 * (torch.FloatStorage data)
      didn't match because some of the arguments have invalid types: (!numpy.float64!)
 * (Sequence data)
      didn't match because some of the arguments have invalid types: (!numpy.float64!)

Could you give me some help? Thanks!

Maybe you can try other version's PyTorch. That's my guess because I don't meet the problem same as yours.

@wangken1994 Exactly the same problem as yours.

I downgrade Pytorch from version 0.4.0 to 0.3.0 and got the error. If I do not downgrade it, I will encounter a FileNotFoundError. Related comments: https://github.com/pytorch/pytorch/issues/6932#issuecomment-557059493, https://github.com/jwyang/faster-rcnn.pytorch/issues/199#issuecomment-557062508, https://github.com/jwyang/faster-rcnn.pytorch/issues/421#issuecomment-557061870.

How did you solve it in the end?

Was this page helpful?
0 / 5 - 0 ratings