'NoneType' object has no attribute 'add_summary'
I'm having trouble with visualizing the weights and bias of my model using tensorboardX.
Here is my model (it's pretty simple anyway):

    self.pipe = nn.Sequential(nn.Linear(9, 128),
                             nn.ReLU(),
                             nn.Linear(128, 256),
                             nn.ReLU(),
                             nn.Linear(256,2),
                             nn.Softmax()
                             )

     def forward(self, x):
     return self.pipe(x)


And here is where I get error in pytorch

for name, param in net.named_parameters():
    writer.add_histogram(name, param, epoch_size, bins='auto')


and the error is

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
&lt;ipython-input-70-d060d2df4423&gt; in &lt;module&gt;()
      1 for name, param in net.named_parameters():
----&gt; 2     writer.add_histogram(name, param, epoch_size, bins='auto')

~\Anaconda3\lib\site-packages\tensorboardX\writer.py in add_histogram(self, tag, values, global_step, bins, walltime)
    403         if isinstance(bins, six.string_types) and bins == 'tensorflow':
    404             bins = self.default_bins
--&gt; 405         self.file_writer.add_summary(
    406             histogram(tag, values, bins), global_step, walltime)
    407 

AttributeError: 'NoneType' object has no attribute 'add_summary'


but I really have to see the histogram where the weights stuck in suboptimal.
so I changed code little bit to proceed step by step

param = np.array(list(net.parameters()))   
print(param[0].data)
writer.add_histogram('weight', param[0].data)


BOOM!  still same error, maybe that doesn't change at all.

The posted code snippet is insufficient to root cause the issue.

The member variable file_writer is set to None when the close() method is invoked on writer. Please check if the close() method was invoked on writer. The close() method is also invoked when the writer object is used as a Context manager and the with block is exited.

with SummaryWriter() as writer:
   writer.add_scalar...

writer.add_histogram # this will cause a crash

