官方總結 tensorboardX 使用教程

2021-09-17 18:24:49 字數 2575 閱讀 8205

tensorboardx api手冊& 簡單教程(看著像官方發布的):

這個東西非常簡單,很多網友的部落格對初學者不利,加了自己的東西,致使簡單上手的tensorboardx變得困難。

下面搬運github readme 部分(請務必多看幾遍,官方說明,沒有比它更合適的學習途徑)

用簡單的函式呼叫寫tensorboard事件。

在anaconda2 / anaconda3上測試,

pytorch 1.0.0 / torchvision 0.2.1 / tensorboard 1.12.0

pip install tensorboardx

或者從源**構建:

git clone && cd tensorboardx && python setup.py install

# demo.py

import torch

import torchvision.utils as vutils

import numpy as np

import torchvision.models as models

from torchvision import datasets

from tensorboardx import summarywriter

resnet18 = models.resnet18(false)

# 注意,在這儲存路徑

writer = summarywriter("./data")

sample_rate = 44100

freqs = [262, 294, 330, 349, 392, 440, 440, 440, 440, 440, 440]

for n_iter in range(100):

dummy_s1 = torch.rand(1)

dummy_s2 = torch.rand(1)

# data grouping by `slash`

writer.add_scalar('data/scalar1', dummy_s1[0], n_iter)

writer.add_scalar('data/scalar2', dummy_s2[0], n_iter)

writer.add_scalars('data/scalar_group', , n_iter)

dummy_img = torch.rand(32, 3, 64, 64) # output from network

if n_iter % 10 == 0:

x = vutils.make_grid(dummy_img, normalize=true, scale_each=true)

writer.add_image('image', x, n_iter)

dummy_audio = torch.zeros(sample_rate * 2)

for i in range(x.size(0)):

# amplitude of sound should in [-1, 1]

dummy_audio[i] = np.cos(freqs[n_iter // 10] * np.pi * float(i) / float(sample_rate))

writer.add_audio('myaudio', dummy_audio, n_iter, sample_rate=sample_rate)

writer.add_text('text', 'text logged at step:' + str(n_iter), n_iter)

for name, param in resnet18.named_parameters():

writer.add_histogram(name, param.clone().cpu().data.numpy(), n_iter)

# needs tensorboard 0.4rc or later

writer.add_pr_curve('xoxo', np.random.randint(2, size=100), np.random.rand(100), n_iter)

dataset = datasets.mnist('mnist', train=false, download=true)

images = dataset.test_data[:100].float()

label = dataset.test_labels[:100]

features = images.view(100, 784)

writer.add_embedding(features, metadata=label, label_img=images.unsqueeze(1))

# export scalar data to json for external processing

writer.export_scalars_to_json("./all_scalars.json")

writer.close()

to add more ticks for the slider (show more image history), check /issues/44 or

使用tensorboard問題總結

1.問題 attributeerror module object has no attribute summarywriter tensorflow版本問題 tf.train.summarywriter函式替換為tf.summary.filewriter2.問題 importerror no mo...

Apple官方demo總結

儲存自定義的類 可以用nsarchiver這個類 首先是類要遵循的協議 nsobject 和 nscoding class meal nsobject,nscoding 先儲存鍵 mark types struct propertykey 顯示儲存的操作 func encodewithcoder a...

lodash官方文件總結

lodash官方中文文件 array chunk 乙個陣列在內部分割出兩個陣列,可以指定第乙個陣列的引數個數 chunk a b c d 2 a b c d chunk a b c d 3 a b c d compact 去除乙個陣列中的 0 false 和空值 compact 0,1,false,...