title: Pytorch nn.BCELoss() getting TypeError: 'Tensor' object is not callable
body: <p>I am using <code>adv_loss = torch.nn.BCELoss()</code> to calculate loss for my network:</p>
  <p>When I call the function the first time(first batch), I do not get an error. But, if I call the function 2nd time(2nd batch), I get the error <code>'Tensor' object is not callable. </code></p>
  <p>I am training GAN, where <code>output_of_nn_layers = D(img1)</code>(output of discriminator network) and</p>
  <p><code>label = torch.ones(batch, 1, device=device, dtype = torch.float32)</code></p>
  <p>I am using adv_loss(BCELoss) in generator training as well, but error occurs in 2nd batch. So total times it is used in training 1st batch is 3 times(2 times for discriminator and 1 time for generator).</p>
  <pre class="lang-py prettyprint-override"><code>for i, (img1, img2) in enumerate(dataloader):
    #do some processing
    loss = adv_loss(output_of_nn_layers, label)
    #do some processing
  </code></pre>
  <p>I am getting error : <code>TypeError: 'Tensor' object is not callable</code></p>
  <p>Full error log:</p>
  <pre><code>
  TypeError                                 Traceback (most recent call last)
  
  &lt;ipython-input-52-bafb0a65d4d9&gt; in &lt;module&gt;()
       73       val_real = D(dis_train_real)
       74       print(&quot;check4.2&quot;)
  ---&gt; 75       d_real_loss = adv_loss(val_real, real_label)   #BCELoss
       76       print(&quot;check4.3&quot;)
       77       val_fake = D(dis_train_fake)
  
  TypeError: 'Tensor' object is not callable
  </code></pre>
  <p>I found similar question on stackoerflow : <a href="https://stackoverflow.com/questions/48819022/recalling-function-tensor-object-is-not-callable">Recalling function: Tensor &#39;object&#39; is not callable</a></p>
  <p>It gave solution that called function should not have variable name same as function name. Am i missing something here?</p>
  <p>i also tried using <code>nn.L1Loss()</code> and got same error.
  what does this error means? what can i do to remove it?</p>