#Multiple signal computation TypeError: 'Tensor' object is not callable

Hello,
I have difficulties calculating the covariance matrix of a loop of signals of size 54 (the 54 denotes the total set of stored signals). However, when the calculation starts, only the first signal is executed. It seems that the current covariance script does only an operation on the first signal after no signal is considered while raising the indicated error TypeError: 'Tensor' object is not callable. How to make iterable the computation over the entire signal length (one by one).

Shape of each signal : torch.Size([2, 10000, 10005])

code :

def covariance_matrix(tensor, rowvar=True, bias=False):
    
    tensor = tensor if rowvar else tensor.transpose(-1, -2)
    tensor = tensor - tensor.mean(dim=-1, keepdim=True)
    factor = 1 / (tensor.shape[-1] - int(not bool(bias)))
    return factor * tensor @ tensor.transpose(-1, -2).conj()
if __name__ == '__main__':
            if torch.is_tensor(reshape_signal):
                if True:
                    print(True)
                    covariance_matrice = covariance_matrix(reshape_signal)
                    print("My covariance : ", covariance_matrice)
                print(False)

Check if you are overriding a method name with a tensor variable name somewhere as it seems that sequential iterations fail.

1 Like

Solved
Sir, are there any possibilities to run the PyTorch with GPU? I have tried but fail.

Yes, you can push the model’s internal state as well as the input data to the GPU e.g. via .cuda() or .to(device). Take a look at the tutorials which also give you some examples.

Got it.
Sir, one more question.
As my data are tensor type, I have defined 54 signals in total. Now I want to insert them into a CNN network, which requires (target, label). In my case the target is in definition my data, however, its data has no labels as identifiers, this is my major problem. In fact, I want to assign to each data a label, to compile the designed network. I first enumerate each data as a label of each data, unfortunately, an error is raised ValueError: only one element tensors can be converted to Python scalars. I proceeded like the codes below, but in vain.

def create_data_loader(train_data, batch_size):
    train_dataloader = DataLoader(train_data, batch_size=batch_size)
    print(train_dataloader)
    return train_dataloader
    for jj, y in enumerate(storage_data, index):
        # print(jj, ". ", y)
        train_data = (jj, y)
        index += 1
        print("My signals are : ", '\n', train_data, '\n')

So, how to label my data and make the training of my network? Here is an example listed below (the 54 denotes the listing of the last data). Thanks in advance.

(54, tensor([[[ 6.7071e-49+9.6242e-67j, -5.7732e-53-1.1452e-50j,
           1.0942e-50+1.2945e-51j,  ...,
           7.2834e-52-4.2107e-51j,  5.7082e-51-3.9200e-51j,
          -4.9956e-51+6.2307e-51j],
         [-5.7732e-53+1.1452e-50j,  6.6808e-49+8.0598e-67j,
          -5.2926e-53-1.1456e-50j,  ...,
           3.8010e-51+2.0603e-51j,  7.3626e-52-4.2001e-51j,
           5.6491e-51-3.8731e-51j],
         [ 1.0942e-50-1.2945e-51j, -5.2926e-53+1.1456e-50j,
           6.6689e-49+6.7971e-68j,  ...,
           5.4084e-51-6.5998e-51j,  3.7788e-51+1.9931e-51j,
           7.7121e-52-4.1535e-51j],
         ...,
         [ 7.2834e-52+4.2107e-51j,  3.8010e-51-2.0603e-51j,
           5.4084e-51+6.5998e-51j,  ...,
           5.7495e-49+1.8567e-67j, -1.5623e-51-2.1687e-52j,
           6.8474e-51-3.8617e-52j],
         [ 5.7082e-51+3.9200e-51j,  7.3626e-52+4.2001e-51j,
           3.7788e-51-1.9931e-51j,  ...,
          -1.5623e-51+2.1687e-52j,  5.7503e-49+2.4958e-67j,
          -1.6490e-51-6.3735e-53j],
         [-4.9956e-51-6.2307e-51j,  5.6491e-51+3.8731e-51j,
           7.7121e-52+4.1535e-51j,  ...,
           6.8474e-51+3.8617e-52j, -1.6490e-51+6.3735e-53j,
           5.7527e-49-5.1433e-67j]],

        [[ 5.7611e-49-3.0056e-67j, -1.6267e-51+1.7540e-52j,
           6.8346e-51-5.1263e-52j,  ...,
          -2.2249e-52-4.9047e-51j,  5.2019e-51-2.8803e-51j,
          -6.4842e-51+6.2802e-51j],
         [-1.6267e-51-1.7540e-52j,  5.7591e-49-1.2227e-67j,
          -1.7296e-51+3.3187e-52j,  ...,
           4.2446e-51+3.1161e-51j, -2.9077e-52-4.8340e-51j,
           5.2237e-51-2.8507e-51j],
         [ 6.8346e-51+5.1263e-52j, -1.7296e-51-3.3187e-52j,
           5.7666e-49-4.0239e-67j,  ...,
           4.7945e-51-7.9020e-51j,  4.3089e-51+3.1792e-51j,
          -2.3726e-52-4.8676e-51j],
         ...,
         [-2.2249e-52+4.9047e-51j,  4.2446e-51-3.1161e-51j,
           4.7945e-51+7.9020e-51j,  ...,
           7.2150e-49+5.8171e-67j, -3.9169e-51+1.2124e-50j,
           5.8248e-51-3.1926e-51j],
         [ 5.2019e-51+2.8803e-51j, -2.9077e-52+4.8340e-51j,
           4.3089e-51-3.1792e-51j,  ...,
          -3.9169e-51-1.2124e-50j,  7.2353e-49-4.0999e-67j,
          -3.9812e-51+1.2184e-50j],
         [-6.4842e-51-6.2802e-51j,  5.2237e-51+2.8507e-51j,
          -2.3726e-52+4.8676e-51j,  ...,
           5.8248e-51+3.1926e-51j, -3.9812e-51-1.2184e-50j,
           7.2597e-49+2.2527e-67j]]], dtype=torch.complex128)) 

I’m unsure which line of code is raising the issue, but it seems you might be trying to call tensor.item() on a tensor containing multiple elements somewhere? Could you check the code and describe where the error is raised, please?

This part of my code: for target, labels in trainloader: