TypeError: new() received an invalid combination of arguments

Traceback (most recent call last):
  File "train.py", line 130, in <module>
    old_val_psnr, old_val_ssim = validation(Encoder, DecGen, val_data_loader, device, category)
  File "/home/chen009/Desktop/ganmethod/utils.py", line 48, in validation
    latent, mu, var = Encoder(haze)
  File "/home/chen009/Desktop/ganmethod/network.py", line 76, in __init__
    self.mu = nn.Linear(1024, nz, bias=False)
  File "/home/chen009/anaconda3/lib/python3.7/site-packages/torch/nn/modules/linear.py", line 72, in __init__
    self.weight = Parameter(torch.Tensor(out_features, in_features))
TypeError: new() received an invalid combination of arguments - got (Tensor, int), but expected one of:
 * (torch.device device)
 * (torch.Storage storage)
 * (Tensor other)
 * (tuple of ints size, torch.device device)
      didn't match because some of the arguments have invalid types: (Tensor, int)
 * (object data, torch.device device)
      didn't match because some of the arguments have invalid types: (Tensor, int)

For this situation, what could I do?

maybe nz is a tensor, I think it should be an integer, like,

nz = 10
self.mu = nn.Linear(1024, nz, bias=False)
actions_v = torch.Tensor(actions, dtype=torch.int64).to(device)

I am getting error on this line of code
here is the error displayed

new() received an invalid combination of arguments - got (numpy.ndarray, dtype=torch.dtype), but expected one of:
 * (torch.device device)
 * (torch.Storage storage)
 * (Tensor other)
 * (tuple of ints size, torch.device device)
      didn't match because some of the keywords were incorrect: dtype
 * (object data, torch.device device)
      didn't match because some of the keywords were incorrect: dtype

To create a tensor from a numpy array use torch.from_numpy.

I am also getting the same error,

File “C:\Users\XYZ\Anaconda3\envs\PyTorch\lib\site-packages\torch\nn\modules\linear.py”, line 72, in init
self.weight = Parameter(torch.Tensor(out_features, in_features))

TypeError: new() received an invalid combination of arguments - got (Tensor, GCN), but expected one of:

  • (torch.device device)
  • (torch.Storage storage)
  • (Tensor other)
  • (tuple of ints size, torch.device device)
    didn’t match because some of the arguments have invalid types: (!Tensor!, !GCN!)
  • (object data, torch.device device)
    didn’t match because some of the arguments have invalid types: (!Tensor!, !GCN!)

Could you check, if you’ve redefined in_features as GCN? I don’t know what kind of type it is, but it might be a custom function?

@ptrblck thanks for your reply.

I was using the class without making the instance. I solved this Error just by creating the instance.

If you use tensor instead of Tensor, it’ll do the trick