How to use tensorboard in Pytorch
In this issue, the editor will bring you about how to use tensorboard in Pytorch. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
Installation: pip install tensorboard
Or install tensorflow. The default CPU version is pip install tensorflow.
Run: tensorboard-- logdir=runs
Lab code:
Import torchimport torchvisionfrom torch.utils.tensorboard import SummaryWriterfrom torchvision import datasets, transforms# Writer will output to. / runs/ directory by defaultwriter = SummaryWriter () transform= transforms.Compose ([transforms.ToTensor (), transforms.Normalize ((0.5,), (0.5,)]) trainset = datasets.MNIST ('mnist_train', train=True, download=True, transform=transform) trainloader = torch.utils.data.DataLoader (trainset, batch_size=64, shuffle=True) model = torchvision.models.resnet50 (False) # Have ResNet model take in grayscale rather than RGBmodel.conv1 = torch.nn.Conv2d (1 64, kernel_size=7, stride=2, padding=3, bias=False) images, labels = next (iter (trainloader)) grid = torchvision.utils.make_grid (images) writer.add_image ('images', grid, 0) writer.add_graph (model, images) writer.close ()' tensorboard-- logdir=runs'''
After running, type: tensorboard-- logdir=runs at the command line
When prompted, open the link: http://localhost:6006/
The output under the command line is:
(base) PS C:\ Users\ chenxuqi\ Desktop\ News4cxq\ tensorboard4cxq > conda activate pytorch_1.7.1_cu102 (pytorch_1.7.1_cu102) PS C:\ Users\ chenxuqi\ Desktop\ News4cxq\ tensorboard4cxq > tensorboard-logdir=runsTensorFlow installation not found-running with reduced feature set.Serving TensorBoard on localhost; to expose to the network, use a proxy or pass-bind_allTensorBoard 2.4.0 at http://localhost:6006/ (Press CTRL+C to quit)
Display effect under the browser:
This is how to use tensorboard in the Pytorch shared by the editor. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.