weird compilation behavior
new to pycharm and python in general.
i wrote code with multiple modules, tried to debug it with some print commands and became more confused in the process.
main module called test.py:
import torchvision
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
import torch
from Net import Net
from data_load import classes, trainloader, testloader
from helper_func import matplotlib_imshow
print('writer not')
from board import writer
if __name__ == "__main__":
# default `log_dir` is "runs" - we'll be more specific here
# get some random training images
dataiter = iter(trainloader)
images, labels = dataiter.next()
print(images.shape)
# create grid of images
img_grid = torchvision.utils.make_grid(images)
# show images
matplotlib_imshow(img_grid, one_channel=True)
# write to tensorboard
writer.add_image('four_fashion_mnist_images', img_grid)
print('writer yes')
module 2 board.py:
from torch.utils.tensorboard import SummaryWriter
#from tensorboardX import SummaryWriter
writer = SummaryWriter('runs/fashion_mnist_experiment_1')
print('writer ready')
the rest of the modules are less important.
i don't understand why the command
```
from board import writer
```
executes the entire module (including print commnad)?
more critically, when i run the script (by pressing shift + f10 in test.py module, i get the following print out:
writer not
writer ready
writer not
writer not
writer ready
writer ready
torch.Size([4, 1, 28, 28])
writer yes
why does the writer not, writer ready repeat after the first time. and why does it double repeat the second time?
i was expecting :
writer not
writer ready
torch.Size([4, 1, 28, 28])
writer yes
please help!
Please sign in to leave a comment.