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

username: vin
cooked: <p>Hello,<br>
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 <code>TypeError: 'Tensor' object is not callable</code>. How to make iterable the computation over the entire signal length (one by one).</p>
<p>Shape of each signal : <code>torch.Size([2, 10000, 10005])</code></p>
<p>code :</p>
<pre><code class="lang-auto">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()
</code></pre>
<pre><code class="lang-auto">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)
</code></pre>

username: ptrblck
cooked: <p>Check if you are overriding a method name with a tensor variable name somewhere as it seems that sequential iterations fail.</p>

username: vin
cooked: <p>Solved<br>
Sir, are there any possibilities to run the PyTorch with GPU? I have tried but fail.</p>

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

username: vin
cooked: <p>Got it.<br>
Sir, one more question.<br>
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 <code>(target, label)</code>. 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 <code>ValueError: only one element tensors can be converted to Python scalars</code>. I proceeded like the codes below, but in vain.</p>
<pre><code class="lang-auto">def create_data_loader(train_data, batch_size):
    train_dataloader = DataLoader(train_data, batch_size=batch_size)
    print(train_dataloader)
    return train_dataloader
</code></pre>
<pre><code class="lang-auto">    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')
</code></pre>
<p>So, how to label my data and make the training of my network? Here is an example listed below (the <code>54</code> denotes the listing of the last data). Thanks in advance.</p>
<pre><code class="lang-auto">(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)) 
</code></pre>

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

username: vin
cooked: <p>This part of my code: <code>for target, labels in trainloader:</code><br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/1/7/17e47f194e131a9f8da6272619d0e174976c7a15.png" data-download-href="https://discuss.pytorch.org/uploads/default/17e47f194e131a9f8da6272619d0e174976c7a15" title="2222"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/1/7/17e47f194e131a9f8da6272619d0e174976c7a15_2_690x198.png" alt="2222" data-base62-sha1="3pmx3TkAVBloRzlBiqESnV9flVX" width="690" height="198" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/1/7/17e47f194e131a9f8da6272619d0e174976c7a15_2_690x198.png, https://discuss.pytorch.org/uploads/default/optimized/3X/1/7/17e47f194e131a9f8da6272619d0e174976c7a15_2_1035x297.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/1/7/17e47f194e131a9f8da6272619d0e174976c7a15_2_1380x396.png 2x" data-dominant-color="2F2F33"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">2222</span><span class="informations">1690×486 65.8 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>