Error on writer.add_graph(model, image)

shaunster: <p>hi,</p>
<p>I’m new to PyTorch. I have a network that trains and runs ok, except that Tensorboard doesnt work fully. With the following lines-</p>
<p>image = torch.zeros((2, 3, args.image_size, args.image_size))<br>
model(image)<br>
writer.add_graph(model, image)</p>
<p>I get the error-<br>
*** TypeError: forward() takes 2 positional arguments but 3 were given</p>
<p>which I dont understand becoz training itself works.<br>
Any thought?<br>
Thanks!</p>

Yannick_Fuchs: <p>I have kind of a similar problem. Training runs fine for me and I also have some add_scalar() methods in my code.<br>
But as soon as I add:</p>
<p><code>tensorboard.add_graph(net, input_to_model=img, verbose=False)</code></p>
<p>in my training loop I get following error:</p>
<pre><code class="lang-auto">
File "c:/SCNN_Pytorch/new_train.py", line 108, in train
    tensorboard.add_graph(net, input_to_model=img, verbose=False)
  File "C:\anaconda3\envs\SCNN\lib\site-packages\torch\utils\tensorboard\writer.py", line 724, in add_graph
    self._get_file_writer().add_graph(graph(model, input_to_model, verbose))
  File "C:\anaconda3\envs\SCNN\lib\site-packages\torch\utils\tensorboard\_pytorch_graph.py", line 286, in graph
    trace = torch.jit.trace(model, args)
  File "C:\anaconda3\envs\SCNN\lib\site-packages\torch\jit\_trace.py", line 733, in trace
    return trace_module(
  File "C:\anaconda3\envs\SCNN\lib\site-packages\torch\jit\_trace.py", line 934, in trace_module
    module._c._create_method_from_trace(
  File "C:\anaconda3\envs\SCNN\lib\site-packages\torch\nn\modules\module.py", line 725, in _call_impl
    result = self._slow_forward(*input, **kwargs)
  File "C:\anaconda3\envs\SCNN\lib\site-packages\torch\nn\modules\module.py", line 709, in _slow_forward
    result = self.forward(*input, **kwargs)
  File "C:\anaconda3\envs\SCNN\lib\site-packages\torch\nn\parallel\data_parallel.py", line 149, in forward
    return self.module(*inputs, **kwargs)
  File "C:\anaconda3\envs\SCNN\lib\site-packages\torch\nn\modules\module.py", line 725, in _call_impl
    result = self._slow_forward(*input, **kwargs)
  File "C:\anaconda3\envs\SCNN\lib\site-packages\torch\nn\modules\module.py", line 709, in _slow_forward
    result = self.forward(*input, **kwargs)
  File "c:\SCNN_Pytorch\model.py", line 52, in forward
    loss_seg = self.ce_loss(seg_pred, seg_gt) #seg_gt.shape = [4, 288, 512]
  File "C:\anaconda3\envs\SCNN\lib\site-packages\torch\nn\modules\module.py", line 725, in _call_impl
    result = self._slow_forward(*input, **kwargs)
  File "C:\anaconda3\envs\SCNN\lib\site-packages\torch\nn\modules\module.py", line 709, in _slow_forward
    result = self.forward(*input, **kwargs)
  File "C:\anaconda3\envs\SCNN\lib\site-packages\torch\nn\modules\loss.py", line 961, in forward
    return F.cross_entropy(input, target, weight=self.weight,
  File "C:\anaconda3\envs\SCNN\lib\site-packages\torch\nn\functional.py", line 2468, in cross_entropy
    return nll_loss(log_softmax(input, 1), target, weight, None, ignore_index, None, reduction)
  File "C:\anaconda3\envs\SCNN\lib\site-packages\torch\nn\functional.py", line 2260, in nll_loss
    if input.size(0) != target.size(0):
AttributeError: 'NoneType' object has no attribute 'size'
</code></pre>
<p>Which doesnt really make any sense. I checked input (which is img) and my target. Both have .size(0)=4 type int. If I print following statement:<br>
<code>print(img.size(0) != target.size(0))</code><br>
the result is False. Can anyone help me with this?<br>
Thank you in advance!</p>