In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
PyTorch how to use TensorBoard, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
Steps
Set up the TensorBoard.
To put it simply, set up the things needed to run the basic tensorboard. The imshow (img) and matplotlib_imshow (img, one_channel=False) in my code are functions that display pictures and can be replaced uniformly. I haven't changed my own test!
# helper function to show an image# (used in the `plot_classes_ preds` function below) def matplotlib_imshow (img, one_channel=False): if one_channel: img = img.mean (dim=0) img = img / 2 + 0.5 # unnormalize npimg = img.cpu (). Numpy () if one_channel: plt.imshow (npimg, cmap= "Greys") else: plt.imshow (np.transpose (npimg, (1,2) 0)) # set tensorBoard# default `log_ dir` is "runs"-we'll be more specific herewriter = SummaryWriter ('runs/image_classify_tensorboard') # get some random training imagesdataiter = iter (trainloader) images, labels = dataiter.next () # create grid of imagesimg_grid = torchvision.utils.make_grid (images) # show images# matplotlib_imshow (img_grid, one_channel=True) imshow (img_grid) # write to tensorboardwriter.add_image (' imag_classify') Img_grid) # Tracking model training with TensorBoard# helper functionsdef images_to_probs (net, images):''Generates predictions and corresponding probabilities from a trained network and a list of images' output = net (images) # convert output probabilities to predicted class _, preds_tensor = torch.max (output, 1) # preds = np.squeeze (preds_tensor.numpy ()) preds = np.squeeze (preds_tensor.cpu (). Numpy () return preds [F.softmax (el, dim=0) [I] .item () for I, el in zip (preds, output)] def plot_classes_preds (net, images, labels):''Generates matplotlib Figure using a trained network, along with images and labels from a batch, that shows the network's top prediction along with its probability, alongside the actual label, coloring this information based on whether the prediction was correct or not. Uses the "images_to_probs" function. '' Preds, probs = images_to_probs (net, images) # plot the images in the batch, along with predicted and true labels fig = plt.figure (figsize= (12,48) for idx in np.arange (4): ax = fig.add_subplot (1,4, idx+1, xticks= [], yticks= []) matplotlib_imshow (images [idx], one_channel=True) ax.set_title ("{0}) {1color= .1f}%\ n (label: {2}) ".format (green [predes [IDX]], probs [idx] * 100.0, classes [labels]]), color= (" green "if predes [IDX] = = labels [IDX] .item () else" red ")) format
Write to TensorBoard.
This is written into tensorboard at every stage of training.
If I% 2000 = = 1999: # print every 2000 mini-batches print ('[% d,% 5d] loss:% .3f'% (epoch + 1, I + 1, running_loss / 2000)) # write data to tensorflow #... log the running loss writer.add_scalar ('image training loss', running_loss / 2000) Epoch * len (trainloader) + I) #... log a Matplotlib Figure showing the model's predictions on a # random mini-batch writer.add_figure ('predictions vs. Actuals', plot_classes_preds (net, inputs, labels), global_step=epoch * len (trainloader) + I)
Running
Tensorboard-logdir=runs
Open http://localhost:6006/ to view
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.