Error: "trainloader" and "writer" are not defined, when it has been defined, in tutorial on viz model via tensorboard

I’m following the PyTorch official tutorial on how to viz model via TensorBoard in my notebook here.

(Note that I copied the exact code from the tutorial webpage)

  1. However, I continued to get the following error on the section to write image to tensorboard, although obviously “trainloader” has been defined in the first cell.
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-6d95240dcdaa> in <module>
      1 # get some random training images
----> 2 dataiter = iter(trainloader)
      3 images, labels = dataiter.next()
      4 
      5 # create grid of images

NameError: name 'trainloader' is not defined
  1. After I re-ran the first cell to create the trainloader twice, the error points to the writer object, which obviously has been created in previous cell.
NameError: name 'writer' is not defined
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-5-6d95240dcdaa> in <module>
     10 
     11 # write to tensorboard
---> 12 writer.add_image('four_fashion_mnist_images', img_grid)
NameError: name 'writer' is not defined

Appreciate if you can advise what could have caused this problem.

Based on the errors I guess your Jupyter notebook might have trouble executing the cells somehow?
Are you seeing the same issues when you run the script from a terminal (outside of a notebook)?